Go Down

Topic: Progrmming Help Required - DC Motor as Annemometer (Read 1 time) previous topic - next topic

Khalid

Jun 26, 2011, 01:13 pm Last Edit: Jun 26, 2011, 01:14 pm by Khalid Reason: 1
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.


http://www.youtube.com/watch?v=2CGyUeY6k08

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

PaulS

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.

floresta

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

Khalid

#3
Jun 26, 2011, 05:23 pm Last Edit: Jun 26, 2011, 05:25 pm by Khalid Reason: 1
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 :
Code: [Select]
/*


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):
 sensorValue = analogRead(sensorPin);
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:
http://www.youtube.com/watch?v=megInro0qII

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.

PaulS

Quote
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.

Re-read the second part of reply #1.

Aeturnalus

Try something like this (untested):

Code: [Select]

#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() {
 bool reading = analogRead(SENSORPIN) >= SPEED_THRESHOLD; // read the voltage

 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
 }
}

Khalid

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

PaulS


Khalid

Aeturnalus,
That is what i really want it. I shall explore this sketch and i am very grateful to all the members who took time and helped me.. Its amazing that you people gave me respect by answering a short period of time. I am very very thankful to all of you especially  Pauls, Don and Aeturnalus.
If you have a better suggestions you are welcome. This is not a perfect Anemometer but just a sensor that gives me a value when to stop/start the fountain pump. Some day i will seek your help to convert these values into wind speed. (I shall take my CAR out with this anemometer and record different DC voltages at specific speeed, then make a formula through Microsoft excel and will come back to you)

Go Up