Arduino(18): Water Sensor to detect the high and low water level

I bought this sensor a long time ago, but it has not been implemented for water level detection. I used the recent review of the Arduino to find out and practice it, and record the implementation process by the way. During the test, instead of actually adding water to raise the water level to test the sensor, the sensor board was slowly put into the water to simulate the rise of the water level. In the process of testing the water level, I feel that the sensor error value obtained is very large, and the values ​​obtained at the same position are not the same. After a long time adjustment, it can only roughly match. If you also want to implement this circuit, remember to find a suitable range.



[Material]

  • Arduino Uno Development Board
  • Water Sensor
  • LED x3
  • 220 ohm resistor x3
  • Buzzer x1
  • Breadboard x1
  • Water bottle x1
  • Wires x N

[Wiring diagram]

ArduinoWater level sensorother
+5VPostive(+)-
GNDNegative(-)-
A0S-
D4-The positive pole of the green LED and the negative pole are connected to a 220 ohm resistor, and the other end of the resistor is grounded.
D3-The positive pole of the yellow LED and the negative pole are connected to a 220 ohm resistor, and the other end of the resistor is grounded.
D2-The anode of the red LED is connected to a 220 ohm resistor, and the other end of the resistor is grounded.
D5-The buzzer is positive and the other end is grounded.




[Code]

int red=2;
int yellow=3;
int green=4;
int buzz=5;

void setup () {
  pinMode (red,OUTPUT);
  pinMode (yellow,OUTPUT);
  pinMode (green,OUTPUT);
  pinMode (buzz,OUTPUT);  
  Serial.begin (9600);
  digitalWrite(buzz,LOW);   
}
 
void loop() {
  //Read input from A0
  int value = analogRead(A0);
  Serial.print(value);    
  Serial.print("   ");      
  if (value > 480) {
    Serial.println("High Level");
    digitalWrite (red,HIGH);
    digitalWrite(yellow,LOW);
    digitalWrite(green,LOW);    
    digitalWrite(buzz,HIGH);
  }          
  else if ((value > 340) && (value <= 480)) {
    Serial.println("Middle Level");
    digitalWrite (red,LOW);   
    digitalWrite (yellow,HIGH);     
    digitalWrite (green,LOW);
    digitalWrite(buzz,LOW); 
  }
  else if ((value > 100) && (value <=340)){
    Serial.println("Low Level");
    digitalWrite (red,LOW);
    digitalWrite (yellow,LOW);
    digitalWrite (green,HIGH);
    digitalWrite(buzz,LOW);
  }     
  else if (value <=100){
    Serial.println("NO Water");
    digitalWrite (red,LOW);
    digitalWrite (yellow,LOW);
    digitalWrite (green,LOW);
    digitalWrite(buzz,LOW);        
  }
  delay(500);
}

[Result]




[Reference]

Post a Comment

Previous Post Next Post