happyheart32
Published © GPL3+

Water level sensor DIY

Using wires and resistors to make water level sensor. Water level sensor can detect low water level, high water level, and normal level.

IntermediateProtip992
Water level sensor DIY

Things used in this project

Hardware components

Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Resistor 4.75k ohm
Resistor 4.75k ohm
×1
Arduino Mega 2560
Arduino Mega 2560
×1

Software apps and online services

MIT App Inventor
MIT App Inventor

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

The schematic of water sensor level

Code

waterSensorLED.ino

Arduino
int H_pin=26;
int L_pin=25;
int B=27;
int G=14;
int R=12;
int H_State=0;
int L_State=0;
long lasttimeLoop2=0;
long lasttimeLEDFalsh=0;
void setup() {
  // put your setup code Here, to run once:
  Serial.begin(115200);
  pinMode(H_pin,INPUT);
  pinMode(L_pin,INPUT);
  pinMode(B,OUTPUT);
  pinMode(G,OUTPUT);
  pinMode(R,OUTPUT);
}

void loop() {
  // put your main code Here, to run repeatedly:
  waterSensorLED();
  waterDisplay();
}

void waterDisplay(){
  if(millis()-lasttimeLoop2>1000){
    Serial.print("H_State=");
    Serial.print(H_State);
    Serial.print(",L_State=");
    Serial.print(L_State);
    Serial.println();  
    lasttimeLoop2=millis();
  }
}
void waterSensorLED(){
  H_State=digitalRead(H_pin);
  L_State=digitalRead(L_pin);
  
  if(H_State==1 and L_State==1){
    digitalWrite(G,1);
    digitalWrite(B,0);
    digitalWrite(R,0);
  }
  if(H_State==0 and L_State==1){
    if(millis()-lasttimeLEDFalsh>0 and millis()-lasttimeLEDFalsh<500){
      digitalWrite(G,1);
      digitalWrite(B,0);
      digitalWrite(R,1);  
    }
    if(millis()-lasttimeLEDFalsh>500 and millis()-lasttimeLEDFalsh<1000){
      digitalWrite(G,0);
      digitalWrite(B,0);
      digitalWrite(R,0);
    }
    if(millis()-lasttimeLEDFalsh>1000){
      lasttimeLEDFalsh=millis();
    }
  }
  if(H_State==0 and L_State==0){
    digitalWrite(G,0);
    digitalWrite(B,0);
    digitalWrite(R,1);
  }  
}

Credits

happyheart32

happyheart32

0 projects • 0 followers

Comments