This circuit is designed to measure current using an ACS712 Current Sensor and display the measured value on an LCD screen. The Arduino UNO serves as the central microcontroller unit to process the sensor data and control the LCD display via I2C communication. The LCD screen is a 16x2 character display that provides a user-friendly interface to display the current readings. The ACS712 Current Sensor is capable of measuring current and provides an analog output that is read by the Arduino UNO.
#include <Wire.h> // Include the Wire library for I2C communication
#include <LiquidCrystal_I2C.h> // Include the LiquidCrystal_I2C library for controlling the LCD
// Initialize the LCD with the I2C address 0x27, 16 columns, and 2 rows
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600); // Start serial communication at a baud rate of 9600
lcd.begin(16, 2); // Initialize the LCD dimensions (16 columns x 2 rows)
lcd.backlight(); // Turn on the LCD backlight for visibility
lcd.print("Ammeter Ready"); // Display a startup message on the LCD
delay(2000); // Wait for 2 seconds to allow the message to be read
lcd.clear(); // Clear the display after the delay
}
void loop() {
// Read the output voltage from the current sensor (connected to analog pin A0)
int sensorValue = analogRead(A0);
// Convert the sensor value (0-1023) to voltage (0-5V)
float voltage = sensorValue * (5.0 / 1023.0);
// Calculate current based on the sensor output
// Assuming the sensor outputs 2.5V at 0A and has a sensitivity of 0.1V/A
float current = (voltage - 2.5) / 0.1;
// Display the current value on the LCD
lcd.setCursor(0, 0); // Set cursor to the first row (line 0)
lcd.print("Current: "); // Print the label "Current: "
lcd.setCursor(0, 1); // Move the cursor to the second row (line 1)
lcd.print(current, 2); // Print the current value with 2 decimal places
lcd.print(" A"); // Append the unit "A" for amperes
// Output the current value to the Serial Monitor
Serial.print("Current: "); // Print label for the Serial Monitor
Serial.print(current, 2); // Print current value with 2 decimal places
Serial.println(" A"); // Append the unit "A" for amperes to the Serial output
delay(1000); // Delay for 1 second before taking the next reading
}
This code initializes the LCD and sets up the Arduino to read the current sensor's output. It then continuously reads the sensor, calculates the current, and displays the result on the LCD and the Serial Monitor.