Water sensor problem

my Arduino is a nano v.3. connected to a water sensor connected to 3.3v, a LCD display, and a buzzer . but for some reason, whenever the water sensor gets contacted by water my laptop starts to freak and disconects the arduino board for no reason

#include <LiquidCrystal.h>
int waterP = A4;
int waterV;       // water sensor pin and value
int readT = 250;

int rs=9;
int en=7;
int d4=11;
int d5=10;   //LCD vars
int d6=8;
int d7=12;

int buzP = 3;
int buzzsL = 255; //buzz vars
int buzzsS = 230;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);

void setup() {
  // put your setup code here, to run once:
pinMode(waterP,INPUT); 

Serial.begin(9600);

lcd.begin(16,2);

pinMode(buzP,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
waterV = analogRead(waterP);
Serial.print(waterV);
delay(100);             // water sensor value reading + print value
Serial.print("\n");

while(waterV < 200){
    analogWrite(buzP,255);
    delay(buzzsL);
    analogWrite(buzP,150);
    delay(buzzsS);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("water level:");
    lcd.setCursor(0,2);
    lcd.print("CRITICAL!");
    waterV = analogRead(waterP);
    delay(readT);
}

while(waterV > 100){
    analogWrite(buzP,0);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("water level:");
    lcd.setCursor(0,2);
    lcd.print("excellent!");
    waterV = analogRead(waterP);
    delay(readT);
}

while(waterV > 100){
    analogWrite(buzP,0);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("water level:");
    lcd.setCursor(0,2);
    lcd.print("excellent!");
    waterV = analogRead(waterP);
    delay(readT);
}
lcd.clear();
}

this is the code used. please be easy with me as I am a new arduino user :slight_smile:

I can see it's been 5 months since you posted to the forum, but you should still remember we can't see what your water sensor is nor how you have all the stuff wired together.

Please make a block diagram showing each device and the connecting wires. Take p picture or scan the drawing and include it on your next post, Thanks!

thanks for your kind reply but the problem had been solved!

Good! Care to enlighten us?

1 Like

well the problem was with the 3.3v pin, i just switched to a 5V pin and it workes perfectly,

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.