hi.. i am doing a fire extinguisher robot project. and the robot senses fire, stops motor, turns off fan and put off candle fire..its ok.but i cant control the rpm of motors.. sometimes, the robot just smashes the candle without stopping..
i am using 12V DC Motors (4) 300 rpm, h-bridge to control them, arduino atmega 8, cooling fan, dfrobot flame sensor..
i tried using arduino tutorial but still cant crack it...please i need your help.
}
void loop()
{
val=analogRead(fm); //connected flame sensor to analogpin 5. vcc to +5 volt, gnd.
Serial.println(val ,DEC);
delay(100);
if(val>400) // val>400 represents the presence of fire.
{digitalWrite(13, LOW); // motor gets stopped but not the robot. as i use low torque motor, the robot still moves a bit after stopping.
digitalWrite(7, HIGH); // fan gets on. extinguishes fire.
}
if(val<100) // no significant fire..just the surrounding temperature..
{digitalWrite(13,HIGH);
digitalWrite(7, LOW); // robot keeps running..in search of fire..
}
}
i need to code for rpm control..like from 200-400 (flame sensor readings), it has to be 150 rpm..then from 500 -800, 100 rpm, then from 800, motor has to stop.. like that i want some codes..i tried pwm pin but cant get the output..
if ( val > 800 )
{
analogWrite(m1, 0); // stop
digitalWrite(m2,HIGH); // fan on
}
if (val < 780)
{
digitalWrite(m2, LOW); // fan off
if ( val > 400 )
{
analogWrite(m1, 100); // slow
}
else if (val > 200 )
{
analogWrite(m1, 200); // medium
}
else
{
analogWrite(m1, 300); // full speed
}
}
I also added a sample hysteresis : if value is between 780 and 800 there's no change: if fan wan running, it keep running; if its off it stays off until val rises even more.
On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 through 13. Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11.
My sample writes to the (digital) pin you defined in m2.
as mine is arduino atmega8, i should connect to 11 or 9 th digital pin and then use the analogwrite code.. is that correct?? i thought we should use analogwrite only in the analog pin...
Post your code! Inside code tags. The code you "tried". It's no good saying you tried what PaulS said and it isn't right. Show what you tried and describe what wasn't right about it.
ok man..i almost got the solution without making rpm control code.. just by using two relays (+5 volt).. i just posted here if i can come across a solution.. but the solution just sparked into me.