How to use water level sensor with Arduino

Posted by moudud 14/05/2019 0 Comment(s)

 

 

How to use water level sensor with Arduino

 


Circuit Diagram :


 

 

Connections
Water level sensor ModulePinArduino pin
VCC5V
GNDGND
SA0
OLED Display ModuleVCC5V
GNDGND
SDAA4
SCLA5


 

 

 

 


Code

 

 

#include <Wire.h>
#include <Adafruit_SSD1306.h>

 

#define OLED_RESET 4

 

Adafruit_SSD1306 display(OLED_RESET);

 


const int analogInPin = A0;
int sensorValue = 0;

 

void setup() {
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  delay(2000);
  display.clearDisplay();
}

 


void loop() {
  sensorValue = analogRead(analogInPin);
  Serial.print("Sensor = " );

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(35,0);
  display.println("Water Level");

 

  Serial.print(sensorValue*100/315);
  //Serial.print(sensorValue);

 

  display.setTextSize(2);
  display.setTextColor(WHITE,BLACK);
  display.setCursor(40,15);
  display.print(sensorValue*100/315);
  display.setCursor(90,15);
  display.print("%");
  display.display();
  display.clearDisplay();

 

  Serial.println("%");
}

 


 

 


 

 

Write a Comment