hi blynkers,
I am using water level sensor to detect the water level and when the water level goes down the motor should turn on and when that level goes up the motor should turn off but he motor keeps running continuouslyt at all time its states not changing I am using Arduino uno
#define motor 9
#define BLYNK_PRINT SwSerial
int Grove_Water_Sensor=analogRead(A0);
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleStream.h>
char auth[] = "dfe8ce156c5a4a1990fb55bb91326ded";
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
Blynk.virtualWrite(A0, Grove_Water_Sensor);
}
void fancontrol()
{
if( Grove_Water_Sensor <=256 )
{
digitalWrite(motor,HIGH);
}
else
{
digitalWrite(motor,LOW);
}
}
void setup()
{
pinMode(motor,OUTPUT);
digitalWrite(motor,LOW);
analogWrite(motor, 0);
Serial.begin(9600);
pinMode(Grove_Water_Sensor, INPUT); // The Water Sensor is an Input
// Debug console
SwSerial.begin(9600);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
timer.setInterval(1500L, fancontrol);
}
void loop()
{
Blynk.run();
timer.run();
}