Water level detection system failure

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 )

void setup()
  analogWrite(motor, 0);
  pinMode(Grove_Water_Sensor, INPUT); // The Water Sensor is an Input
  // Debug console

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Blynk.begin(Serial, auth);

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
  timer.setInterval(1500L, fancontrol);

void loop()

You’re not actually taking a reading from your water sensor!

This line makes me think that you’re expecting an analogue reading from your sensor, rather than just a HIGH/LOW value, in which case you’ll need to do an analogue read from the sensor and assign the result to the Grove_Water_Sensor variable.

Why are you doing both digital and analog writes to the motor pin?


thanks pete now it works

this one was by mistakes due to several experiments with both digital and analog pins

1 Like