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 ![]()