void loop() is not looping
hello,
i trying program automatic water level controller. have used 2 arduino modules. 1 sensor side , control side. program control side:
the void loop not looping. 1 distance ultrasonic sensor. when distance changes, not reflected on code. can guide me have gone wrong. in advance
moderator edit: [code] [/code] tags added.
i trying program automatic water level controller. have used 2 arduino modules. 1 sensor side , control side. program control side:
code: [select]
#include <liquidcrystal.h>
#define echo 0
#define motor 8
#define buzzer 12
liquidcrystal lcd(2,3,4,5,6,7);
float distance=0;
int temp=0;
void setup()
{
lcd.begin(16,2);
pinmode(echo,input);
pinmode(motor, output);
pinmode(buzzer, output);
lcd.print(" water level ");
lcd.setcursor(0,1);
lcd.print(" indicator ");
serial.begin(9600);
delay(2000);
}
void loop()
{
while(serial.available()>0){
distance=serial.parsefloat()-'0';}
lcd.clear();
lcd.print("water space in ");
lcd.setcursor(0,1);
lcd.print("tank is: ");
lcd.print(distance);
lcd.print("cm");
delay(1000);
if(distance<12 && temp==0)
{
digitalwrite(motor, low);
digitalwrite(buzzer, high);
lcd.clear();
lcd.print("water tank full ");
lcd.setcursor(0,1);
lcd.print("motor turned off");
delay(2000);
digitalwrite(buzzer, low);
delay(3000);
temp=1;
}
else if(distance<12 && temp==1)
{
digitalwrite(motor, low);
lcd.clear();
lcd.print("water tank full ");
lcd.setcursor(0,1);
lcd.print("motor turned off");
delay(5000);
}
else if(distance>30)
{
digitalwrite(motor, high);
lcd.clear();
lcd.print("low water level");
lcd.setcursor(0,1);
lcd.print("motor turned on");
delay(5000);
temp=0;
}
}
the void loop not looping. 1 distance ultrasonic sensor. when distance changes, not reflected on code. can guide me have gone wrong. in advance
moderator edit: [code] [/code] tags added.
[/s]
[code]code tags[/code]
[s]
, (which you're always supposed when posting code).
even better if hit ctrl-t or ">tools auto format" in ide correctly format code before posting it.
it done you.
in diagram, arduinos aren't connected gnd.
why subtract '0' here?:-
distance=serial.parsefloat()-'0';
edit: , perhaps should show other half of code - sender.
also, 'distance' 'float'?
Arduino Forum > Using Arduino > Programming Questions > void loop() is not looping
arduino
Comments
Post a Comment