Example Code for Arduino-Liquid Level Detection
This article guides users through setting up an Arduino-based liquid level detection system using a non-contact capacitive sensor, complete with a wiring diagram, sample code, and expected outcomes.
Hardware Preparation
Software Preparation
Click to download Arduino IDE
Wiring Diagram

Sample Code
int ledPin = 13; // LED connected to digital pin 13
int inPin = 7; // pushbutton connected to digital pin 7
int val = 0; // variable to store the read value
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
pinMode(inPin, INPUT_PULLUP); // sets the digital pin 7 as input
digitalWrite(inPin, HIGH); //Setting software pull-up
}
void loop()
{
val = digitalRead(inPin); // read the input pin
digitalWrite(ledPin, val); // sets the LED to the button's value
}
Result
If the sensor detects liquid, the onboard LED of UNO will turn off. If no liquid is detected, the onboard LED of UNO will turn on.
Was this article helpful?
