# Progrmming Help Required - DC Motor as Annemometer

Dear All,
BackGround:
I am working on a Laminar Flow nozzle project. In this project Arduino shall control RGB LED, one Solenoid, and Anemometer made from CD ROM Motor. Actually i should not called it a perfect Anemometer for the time being because it just provide me voltage at high wind and i am not able to convert those voltages into wind MPH. The maximum voltage i get from this Anemometer is 0.4 V DC.
The idea is when the voltages reaches to 0.24 DC the laminar flow disturb and i want to stop the pump. This seems very simple as i can monitor the voltages through Analogue pin easily. But, i do not want the Arduino to stop/start the pump frequently.

WHAT I want:
1- I want Arduino to get the voltage of Anemometer. If the voltage reading is 0.24 DC then take further readings if the voltage is greater 0.24 or equal to 0.24 for 1 minutes then STOP the pump.
2- The Arduino takes the reading of anemometer after stoppage of pump if the readings are persistent for a minute then the Pump should not be started. This cycle should be calculated again and again till the arduino knows that the wind is low and DC voltages are less than 0.24VDC. then start the pump.

I need all of your help please. How can i do it. Any psuedcode will be useful or any other method / technique shall be good for me.

Regards
Khalid Khattak

There are two issues you are having. One is making use of the very small voltage that you are generating. The other, of course, is the very small voltage that you are generating. If you were to run that voltage through an op-amp with a 12 to 1 gain, you'd get 0 to 4.8 volts, which would translate to many more values output by the analogRead function, which would greatly improve your ability to make use of the data.

That's where I'd start.

Once you have a wider range of readings, you can read the value, on each pass through loop().
If the value is greater than a threshold (in terms of analogRead output not voltage), and was not before, record the time. This means, of course, that you also need to keep track of the previous value. If the value is less than the threshold, set the time to 0.

Separately, you need to see if "now" (as defined by millis()) is greater than "then" (when the value exceeded the threshold), and "then" is not 0. If so, stop the pump. If not, leave the pump running.

Have you considered using a stepper motor (from an old floppy disk drive) instead of the DC motor. The output is AC, but even after the voltage drop of the rectifier you will probably get more DC than you are getting now.

Don

Thank you Paul and Don for the valuable replies.I want to share with you following video where i was able to light up an LED when required threshold is received off-course :

``````/*

int sensorPin = A0;    // select the input pin
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor(DC Motor)

void setup() {
// declare the ledPin as an OUTPUT:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop() {
// read the value(DC Voltage) from the sensor(DC Motor):
Serial.println(sensorValue);
// turn the ledPin on
if (sensorValue>25)    // (This 25 was the rough value. How i got it? I rotated the anemometer by hand and got the values with the Serial.Println.  i selected by seeing the rotation of Annemometer and assuming that if the annemometer is that fast( sensorvalue=25) the Laminar flow of the fountain shall be disturbed.and this  will decide to make LED on(later i will use this to OFF the pump)
{digitalWrite(ledPin, HIGH);
}
else
// turn the ledPin off:
{ digitalWrite(ledPin, LOW);
}

// stop the program for for <sensorValue> milliseconds:

}
``````

Here is the video:

I know the value (25 or any value) that is generated in Arduino make some sense . For example if i rotate the Anemometer at a fix RPM (assume) i get value 25. If the RPM is little increase i will get the value greater than 25. Now i want the same how i program that for a certain period of time(monitoring) if the value 25 stays the same or increased the Arduino make the pump stop.

Now i want the same how i program that for a certain period of time(monitoring) if the value 25 stays the same or increased the Arduino make the pump stop.

Try something like this (untested):

``````#define SENSORPIN 0
#define LEDPIN 13
#define SPEED_THRESHOLD 25 // the threshold speed value
#define TIME_THRESHOLD 1000 // the number of milliseconds before changing the state

unsigned long pTime;
bool pValue;

void setup() {
pinMode(LEDPIN, OUTPUT); // set the led pin to output
}

void loop() {

if ((reading && !pValue) || (!reading && pValue)) { // if the threshold is crossed
pTime = millis(); // move the marker to the current time
}

pValue = reading; // record the current value for later use

if (millis() - pTime >= TIME_THRESHOLD) { // if there has been no change for more than TIME_THRESHOLD
digitalWrite(LEDPIN, reading); // set the LED appropriately
}
}
``````

Hi paul,
Thanks for the reply and i have read it twice and that exactly what i want. So i should use millis to calculate the time...can you help me some example or a little piece of sketch to where and how i implement the same in my above sketch... I know asking more may offend you, but this i am requesting you very meekly..

Regards