Pages: [1]   Go Down
Author Topic: Progrmming Help Required - DC Motor as Annemometer  (Read 1521 times)
0 Members and 1 Guest are viewing this topic.
Pakistan
Offline Offline
Sr. Member
****
Karma: 6
Posts: 357
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: June 26, 2011, 06:14:57 am by Khalid » Logged


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 632
Posts: 50182
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 4389
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pakistan
Offline Offline
Sr. Member
****
Karma: 6
Posts: 357
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*


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:


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.
« Last Edit: June 26, 2011, 10:25:34 am by Khalid » Logged


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 632
Posts: 50182
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try something like this (untested):

Code:
#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
  }
}
Logged

Pakistan
Offline Offline
Sr. Member
****
Karma: 6
Posts: 357
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 632
Posts: 50182
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Aeturnalus already posted some code.
Logged

Pakistan
Offline Offline
Sr. Member
****
Karma: 6
Posts: 357
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged


Pages: [1]   Go Up
Jump to: