# Pinwheel

Intended to use rotational speed on pinwheel to measure wind speed by converting angular velocity of the pinwheel to linear velocity. Looking back, I’m not sure how accurate this way of measuring wind speed is, considering properties of the pinwheel (such as friction).

Angular velocity is calculated by using a photocell to detect when a blade of the pinwheel passes over.

What it looks like:

A simple demo video that shows it working:

Code:

`#include `
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_7segment matrix = Adafruit_7segment();
int historyLength = 100;
float sensorHistory[100];
float runningL;
float runningMaxL;
float runningMinL;
float threshhold;
boolean covered;
int speedHistLen = 400;
float speedHistory[400];
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
matrix.begin(0x70);
for (int i=0; i0; i-- ){
sensorHistory[i] = sensorHistory[i-1];
}
sensorHistory[0] = sensorValue;
float currMax = -9999;
float currMin = 9999;
for (int i=0; i currMax) { currMax = ith; }
if (ith15.0) {
if (!covered && currL< (runningL-threshhold*halfRange)) {
//If sensor is NOT covered and current sensor value falls below threshhold,
//then a blade is currently passing over
updateLinearSpeed(0);
covered = true;
}
else if (covered && currL>(runningL+threshhold*halfRange)) {
//If sensor IS covered and current sensor value falls above threshhold,
//then a blade just passed over, so update speed
updateLinearSpeed(1);
covered = false;
}
else {
updateLinearSpeed(0);
}
}
delay(1);
}
int nBlades = 8;
float radius = 0.085; //in meters
void updateLinearSpeed(int n) {
int totalPasses = 0;
for (int i=speedHistLen-1; i>0; i-- ){
speedHistory[i] = speedHistory[i-1];
totalPasses+=speedHistory[i];
}
speedHistory[0] = n;
totalPasses+=n;
float spinSpeed = 2.0*PI/nBlades*radius*((float)totalPasses)/((float)speedHistLen);
Serial.println(spinSpeed);
int displayed = (int)spinSpeed*100;
int tens = displayed/1000;
int ones = (displayed/100)%10;
int tenths = (displayed/10)%10;
int hundredths = displayed%10;
matrix.writeDigitNum(0,tens,false);
matrix.writeDigitNum(1,ones,true);
matrix.drawColon(false);
matrix.writeDigitNum(3,tenths,false);
matrix.writeDigitNum(4,hundredths,false);
matrix.writeDisplay();
}