Skip to content

Project 3.6.1: Smart Gauge System

Description This project demonstrates how to build a water level monitoring system using an ultrasonic sensor, LEDs, and a buzzer. The ultrasonic sensor measures the water level, the LEDs indicate different water levels, and the buzzer provides an alert when the water reaches a certain point.
Use case This project can be used in water storage tanks to monitor water levels automatically. For example, the LEDs can indicate whether the tank is low, medium, or full, while the buzzer alerts users when the tank is completely full to prevent water overflow.

Components (Things You will need)

LED Arduino Uno Arduino USB Cable Breadboard Jumper wire Ultrasonics Sensor

Building the circuit

Things Needed:

  • Arduino Uno Board: 1
  • Arduino USB cable: 1
  • Breadboard: 1
  • Red LED = 1
  • Green LED = 1
  • Ultrasonic sensor = 1
  • Jumper Wires.

Mounting the component on the breadboard

Things needed:

  • Ultrasonic Sensor = 1
  • Breadboard =1
  • Red LED = 1
  • Green LED = 1

Step 1: Insert the ultrasonic sensor into the breadboard. Then place the red, green, and yellow LEDs beside the sensor, ensuring the positive and negative pins are correctly identified. Connect a resistor to the positive pin of each LED, and insert the buzzer into the breadboard with the positive and negative pins properly positioned.

LED fixed on breadboard.

WIRING THE CIRCUIT

Step 2: Connect the positive pins of the LEDs to their respective digital pins on the Arduino Uno through resistors using jumper wires, and connect all the negative pins of the LEDs to the GND pin on the Arduino Uno. NB: The resistor is added to limit the amount of current flowing through the LED, helping to protect the LED from damage and ensuring it operates safely.

LED fixed on breadboard.

Step 3: Connect the VCC pin of the ultrasonic sensor to the 5V pin on the Arduino Uno and connect the GND pin to GND. Then connect the TRIG pin to Digital Pin 7 and the ECHO pin to Digital Pin 6 on the Arduino Uno using jumper wires.

LED fixed on breadboard.

Step 4: Connect the positive pin (+) of the buzzer to a digital pin on the Arduino Uno (for example Digital Pin 8), and connect the negative pin (–) to the GND pin on the Arduino Uno.

LED fixed on breadboard

PROGRAMMING

Step 1: Open your Arduino IDE. See how to set up here: Getting Started.

Step 2: Before the void setup() function, type:

const int trigPin = 6;    // HC-SR04 TRIG pin connected to D6
const int echoPin = 7;    // HC-SR04 ECHO pin connected to D7
const int redLedPin = 4;  // Red LED connected to D4
const int yellowLedPin = 3; // Yellow LED connected to D3
const int greenLedPin = 2;  // Green LED connected to D2
const int buzzerPin = 8;  // Buzzer connected to D8

LED fixed on breadboard

Step 3: Inside the void setup() function, type:

pinMode(trigPin, OUTPUT);  // Set TRIG pin as output
  pinMode(echoPin, INPUT);   // Set ECHO pin as input
  pinMode(redLedPin, OUTPUT);  // Set Red LED pin as output
  pinMode(yellowLedPin, OUTPUT); // Set Yellow LED pin as output
  pinMode(greenLedPin, OUTPUT);  // Set Green LED pin as output
  pinMode(buzzerPin, OUTPUT);  // Set Buzzer pin as output
  Serial.begin(9600);  // Initialize serial communication

LED fixed on breadboard

Step 4: Inside the void loop() function, type:

long duration, distance;

// Clear the TRIG pin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Send trigger pulse
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Read echo time
duration = pulseIn(echoPin, HIGH);

// Calculate distance in cm
distance = (duration / 2) / 29.1;

Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

// Water level control
if (distance < 10) {
  digitalWrite(redLedPin, HIGH);
  digitalWrite(yellowLedPin, LOW);
  digitalWrite(greenLedPin, LOW);
  digitalWrite(buzzerPin, HIGH);
}
else if (distance < 20) {
  digitalWrite(redLedPin, LOW);
  digitalWrite(yellowLedPin, HIGH);
  digitalWrite(greenLedPin, LOW);
  digitalWrite(buzzerPin, LOW);
}
else {
  digitalWrite(redLedPin, LOW);
  digitalWrite(yellowLedPin, LOW);
  digitalWrite(greenLedPin, HIGH);
  digitalWrite(buzzerPin, LOW);
}

delay(1000);

LED fixed on breadboard

LED fixed on breadboard

Step 4: Save your code. See the Getting Started section

Step 5: Select the arduino board and port See the Getting Started section:Selecting Arduino Board Type and Uploading your code.

Step 6: Upload your code. See the Getting Started section:Selecting Arduino Board Type and Uploading your code

CONCLUSION

This project demonstrated how an ultrasonic sensor, LEDs, and a buzzer can be used together to monitor water levels in a tank. It helped in understanding how distance sensing works and how outputs like LEDs and buzzers can provide visual and audio alerts for real-life applications such as water level monitoring systems.