How to Make an Autocut Charging Mini DC IPS at Home Using Atmega328P IC | Step-by-Step Guide
by Estiak khan Jhuman in Circuits > Arduino
68 Views, 3 Favorites, 0 Comments
How to Make an Autocut Charging Mini DC IPS at Home Using Atmega328P IC | Step-by-Step Guide
In this enhanced DIY project, we’ll build an Autocaut Charging Mini DC IPS using the Atmega328P microcontroller and integrate a 16x2 LCD display for real-time system status monitoring. To help you understand the project better, we will also go through the circuit diagram and explain how each component interacts to create an efficient, automatic backup power solution.
Key Features of the Project
- Automatic Load Control: The system detects power outages and switches the load automatically to the battery backup.
- Automatic Battery Charging: Monitors battery voltage and controls the charging process.
- Manual Control: Includes a push button to override the automatic system and manually control the load.
- Real-Time Status Display: A 16x2 LCD displays key information such as battery voltage, load state, and charging status.
Supplies
Materials You Need for the Autocaut Charging Mini DC IPS
Before getting started, make sure you have the following components ready:
- Atmega328P IC (Microcontroller)
- Crystal 16Mhz (for stable clocking of the Atmega328P)
- 103VR Capacitor (for voltage regulation)
- 10K Resistor (pull-up for reset pin)
- DC Relay 5V 2P (to switch the load automatically)
- BC547 Transistor (for relay control)
- 1K Resistor (base resistor for the transistor)
- 22pf Capacitors (for crystal oscillator stabilization)
- 104pf Capacitors (for filtering)
- L7805 Voltage Regulator (to regulate the input voltage to 5V for the microcontroller)
- Rechargeable Battery (12V recommended)
- Solar Panel (Optional for renewable charging)
- Push Button (for manual load control)
- Autocaut Charging Circuit (automatic battery charging)
- Wires, Connectors, and Basic Tools (soldering iron, multimeter, etc.)
How It Works
How It Works:
- Atmega328P IC: This is the brain of the system, controlling the relay, monitoring the battery charging status, and deciding when to turn the load on or off based on power availability.
- Crystal 16Mhz: The external clock ensures stable operation of the Atmega328P.
- Automatic Battery Charging: The system will continuously monitor the battery and charge it automatically when necessary, using a DC charging circuit integrated with the Atmega328P.
- Load On/Off Control: The relay will control the load (lights, fans, etc.), automatically turning it on during outages and switching it off when the grid power is restored.
- Manual Override: The push button allows manual control of the load, letting you turn it on or off as needed.
Circuit Diagram Explanation
JLCPCB PCB Fab & Assembly from $2! Sign up to Get $60 Coupons: https://jlcpcb.com/?from=EST Up to 50% off!
Get FREE 6-layer PCBs during JLCPCB Engineers Day: https://jlcpcb.com/engineers-day?from=ACT
1. Atmega328P Microcontroller
The Atmega328P is the brain of this system. It controls the load (via the relay), monitors the battery voltage, and displays information on the 16x2 LCD. Here’s how it’s connected:
- Power Supply: The L7805 voltage regulator steps down the 12V from the battery to 5V to power the Atmega328P. Connect the Vcc (pin 7) and GND (pin 8) of the microcontroller to 5V and ground.
- Crystal Oscillator: The 16MHz crystal oscillator is connected to the XTAL1 (pin 9) and XTAL2 (pin 10) pins, with 22pF capacitors to stabilize the clock frequency.
- Reset: Connect a 10K pull-up resistor to the RESET pin (pin 1) to ensure it stays high during normal operation.
2. 16x2 LCD Display
The LCD displays system status, including battery voltage and load state.
- Without I2C: Connect the LCD in 4-bit mode to the Atmega328P:
- RS to digital pin 12
- E to digital pin 11
- D4 to D7 to digital pins 5, 4, 3, 2 respectively.
- VDD to 5V, VSS to ground.
- A 10K potentiometer is connected to the VO pin for contrast adjustment.
- With I2C: If you're using an I2C module with the LCD, connect the SDA to A4 and SCL to A5 of the Atmega328P.
3. Battery Monitoring and Charging
To monitor the battery’s voltage and control charging:
- Analog Input: The battery voltage is monitored using the A0 analog input pin. You will likely need a voltage divider circuit (using two resistors) to scale the 12V battery voltage down to a measurable range (0-5V) for the microcontroller.
- Automatic Charging Control: The Atmega328P will read the battery voltage and decide whether to activate the charging circuit or stop it when the battery is fully charged.
4. DC Relay for Load Control
The DC Relay allows the microcontroller to automatically switch the load on or off based on power availability.
- The relay is controlled by the BC547 transistor:
- Base of the BC547 is connected to digital pin 7 of the Atmega328P through a 1K resistor.
- The collector of the BC547 is connected to one end of the relay coil.
- The emitter of the BC547 is connected to ground.
- When the Atmega328P sends a signal to the base, it activates the transistor, turning on the relay, and the load is powered from the backup battery.
5. Push Button for Manual Load Control
A push button is used to manually toggle the state of the load (on/off), overriding the automatic system.
- Connect the push button to pin 2 of the Atmega328P.
- Use a 10K pull-down resistor to ensure the pin reads LOW when the button is not pressed.
6. L7805 Voltage Regulator
The L7805 voltage regulator converts the 12V input from the battery to a stable 5V for powering the microcontroller and the LCD display.
- The input pin is connected to the 12V battery.
- The output pin provides 5V, which is connected to the Vcc pin of the Atmega328P and other components requiring 5V.
- A 104pF capacitor is placed at the input and output to smooth the voltage.
Code Explanation for Autocut Charging Mini DC IPS
1. Importing Libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the I2C address to 0x27 for a 16x2 LCD
Wire.h: This library is needed for I2C communication between the Atmega328P and the LCD display (if you use the I2C version of the 16x2 LCD).
LiquidCrystal_I2C.h: This library is specifically for controlling an LCD with an I2C interface.
lcd(0x27, 16, 2): This initializes the LCD display with the I2C address 0x27 and specifies that the display has 16 columns and 2 rows.
2. Pin Definitions and Global Variables
int relayPin = 7; // Relay control pin
int buttonPin = 2; // Push button pin
int chargePin = A0; // Pin to monitor battery voltage
int loadState = LOW; // Initial state of the load
bool manualControl = false; // Flag for manual override
float batteryVoltage = 0.0;
- relayPin: This is connected to the base of the BC547 transistor, which controls the relay.
- buttonPin: The pin connected to the push button for manual load control.
- chargePin: This analog pin is connected to the voltage divider to read the battery voltage.
- loadState: A variable that keeps track of whether the load is ON or OFF.
- manualControl: A boolean flag that keeps track of whether manual control is activated via the push button.
- batteryVoltage: Stores the calculated battery voltage from the analog reading.
3. Setup Function
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(buttonPin, INPUT);
lcd.begin(16, 2); // Initialize the LCD
lcd.setBacklight(1); // Turn on the backlight
Serial.begin(9600);
}
pinMode(relayPin, OUTPUT): Sets the relay pin as an output, so it can be used to control the relay.
pinMode(buttonPin, INPUT): Configures the push button pin as an input, so it can detect when the button is pressed.
lcd.begin(16, 2): Initializes the 16x2 LCD display.
lcd.setBacklight(1): Turns on the backlight of the LCD to make the display visible.
Serial.begin(9600): Initializes serial communication for debugging purposes (optional).
4. Main Loop: Reading Voltage, Controlling Relay, and Displaying on LCD
void loop() {
int buttonState = digitalRead(buttonPin);
int sensorValue = analogRead(chargePin); // Read battery voltage
batteryVoltage = (sensorValue * (5.0 / 1023.0)) * 4; // Adjust for 12V battery
buttonState: Reads the current state of the push button (pressed or not).
analogRead(chargePin): Reads the battery voltage from the analog pin (A0), which is connected to a voltage divider. The analog input value ranges from 0 to 1023.
batteryVoltage calculation: The sensor value (analogRead) is converted to the actual battery voltage. The formula:
- (sensorValue * (5.0 / 1023.0)): Converts the sensor value to the actual voltage based on the 5V reference.
- The result is multiplied by 4 because we use a voltage divider to scale down the 12V battery voltage to a safe level for the Atmega328P.
5. Automatic Charging Control and LCD Display Update
// Automatic battery charging logic
if (batteryVoltage < 11.5) { // Low voltage
digitalWrite(relayPin, HIGH); // Turn relay ON (load powered)
lcd.setCursor(0, 0);
lcd.print("Charging: ON ");
} else if (batteryVoltage > 13.5) { // Battery full
digitalWrite(relayPin, LOW); // Turn relay OFF (stop charging)
lcd.setCursor(0, 0);
lcd.print("Charging: OFF");
}
// Display battery voltage
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.print(batteryVoltage);
lcd.print("V");
Battery voltage control:
- If the battery voltage drops below 11.5V (discharged), the relay turns on, powering the load, and the system starts charging the battery.
- If the voltage rises above 13.5V (fully charged), the relay turns off, stopping the charging to protect the battery from overcharging.
LCD Display:
- lcd.setCursor(0, 0): Sets the cursor to the first line of the LCD to display the charging status.
- lcd.print("Charging: ON/OFF"): Displays whether the charging is currently ON or OFF.
- lcd.setCursor(0, 1): Moves the cursor to the second line of the LCD to display the current battery voltage.
6. Manual Control with Push Button
// Manual control using push button
if (buttonState == HIGH && !manualControl) {
manualControl = true;
loadState = !loadState; // Toggle load state
digitalWrite(relayPin, loadState);
} else if (buttonState == LOW) {
manualControl = false;
}
// Display load state
lcd.setCursor(10, 0);
if (loadState == HIGH) {
lcd.print("Load: ON ");
} else {
lcd.print("Load: OFF");
}
delay(100); // Small delay for debounce
}
- Manual Control Logic:
- If the push button is pressed, it toggles the loadState (ON/OFF).
- When the button is pressed (buttonState == HIGH) and manualControl is false, it switches the load state (from ON to OFF or vice versa). It also prevents rapid toggling by using the manualControl flag.
- When the button is released (buttonState == LOW), manualControl is reset, so the button can be pressed again to toggle the load.
- LCD Display for Load State:
- This section updates the LCD to show the current load state (ON or OFF).
- lcd.setCursor(10, 0): Moves the cursor to the 10th position of the first line of the LCD (so it doesn't overwrite the charging status).
- The current state of the load (ON/OFF) is displayed accordingly.
- Debouncing:
- A small delay (delay(100)) is added to prevent accidental multiple button presses caused by mechanical bouncing of the switch.
Code Flow Summary
- Setup:
- Initializes the pins, LCD display, and relay.
- Main Loop:
- Reads the battery voltage and decides whether to turn on/off the charging (by controlling the relay).
- Displays battery voltage and charging status on the LCD.
- Reads the push button state for manual control and toggles the load accordingly.
- Updates the LCD display to show whether the load is ON or OFF.
- Manual Load Control:
- The system can be manually overridden via the push button to switch the load on or off.
Code:
int relayPin = 7; // Relay control pin
int buttonPin = 2; // Push button pin
int chargePin = A0; // Pin to monitor battery voltage
int loadState = LOW; // Initial state of the load
bool manualControl = false; // Flag for manual override
float batteryVoltage = 0.0;
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(buttonPin, INPUT);
lcd.begin(16, 2); // Initialize the LCD
lcd.setBacklight(1); // Turn on the backlight
Serial.begin(9600);
}
void loop() {
int buttonState = digitalRead(buttonPin);
int sensorValue = analogRead(chargePin); // Read battery voltage
batteryVoltage = (sensorValue * (5.0 / 1023.0)) * 4; // Adjust for 12V battery
// Automatic battery charging logic
if (batteryVoltage < 11.5) { // Low voltage
digitalWrite(relayPin, HIGH); // Turn relay ON (load powered)
lcd.setCursor(0, 0);
lcd.print("Charging: ON");
} else if (batteryVoltage > 13.5) { // Battery full
digitalWrite(relayPin, LOW); // Turn relay OFF (stop charging)
lcd.setCursor(0, 0);
lcd.print("Charging: OFF");
}
// Display battery voltage
lcd.setCursor(0, 1);
lcd.print("Battery: ");
lcd.print(batteryVoltage);
lcd.print("V");
// Manual control using push button
if (buttonState == HIGH && !manualControl) {
manualControl = true;
loadState = !loadState; // Toggle load state
digitalWrite(relayPin, loadState);
} else if (buttonState == LOW) {
manualControl = false;
}
// Display load state
lcd.setCursor(10, 0);
if (loadState == HIGH) {
lcd.print("Load: ON ");
} else {
lcd.print("Load: OFF");
}
delay(100); // Small delay for debounce
}
Testing the System
Power the Atmega328P using the L7805 voltage regulator to step down the 12V battery to 5V.
Upload the code and check that the LCD display is showing the correct information: battery voltage, charging status, and load state.
Test the system by disconnecting and reconnecting the main power to see if the system switches to battery power and turns the load on automatically. Verify that the manual push button correctly toggles the load.
Final Assembly
Once the system is fully tested, house all components in a secure, ventilated enclosure.
Ensure that the LCD display is visible so you can monitor the system's status at any time.
Video Reference
JLCPCB PCB Fab & Assembly from $2! Sign up to Get $60 Coupons: https://jlcpcb.com/?from=EST Up to 50% off!
Get FREE 6-layer PCBs during JLCPCB Engineers Day: https://jlcpcb.com/engineers-day?from=ACT
Conclusion
Adding a 16x2 LCD display to your Autocaut Charging Mini DC IPS makes the system more functional and user-friendly by allowing you to monitor real-time data like battery voltage and load status. The integration of the Atmega328P microcontroller provides automatic load switching and battery management, while the manual push button gives you the ability to control the load manually when necessary.
This project not only enhances your DIY power backup system but also helps you gain a deeper understanding of embedded systems, electronics, and renewable energy solutions.