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

26 Views, 0 Favorites, 0 Comments

How to Make an Autocut Charging Mini DC IPS at Home Using Atmega328P IC | Step-by-Step Guide

Autocut Charger2.jpg

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

  1. Automatic Load Control: The system detects power outages and switches the load automatically to the battery backup.
  2. Automatic Battery Charging: Monitors battery voltage and controls the charging process.
  3. Manual Control: Includes a push button to override the automatic system and manually control the load.
  4. 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:

  1. Atmega328P IC (Microcontroller)
  2. Crystal 16Mhz (for stable clocking of the Atmega328P)
  3. 103VR Capacitor (for voltage regulation)
  4. 10K Resistor (pull-up for reset pin)
  5. DC Relay 5V 2P (to switch the load automatically)
  6. BC547 Transistor (for relay control)
  7. 1K Resistor (base resistor for the transistor)
  8. 22pf Capacitors (for crystal oscillator stabilization)
  9. 104pf Capacitors (for filtering)
  10. L7805 Voltage Regulator (to regulate the input voltage to 5V for the microcontroller)
  11. Rechargeable Battery (12V recommended)
  12. Solar Panel (Optional for renewable charging)
  13. Push Button (for manual load control)
  14. Autocaut Charging Circuit (automatic battery charging)
  15. Wires, Connectors, and Basic Tools (soldering iron, multimeter, etc.)

How It Works

How It Works:

  1. 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.
  2. Crystal 16Mhz: The external clock ensures stable operation of the Atmega328P.
  3. 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.
  4. 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.
  5. Manual Override: The push button allows manual control of the load, letting you turn it on or off as needed.


Circuit Diagram Explanation

Schematic_Full-Autocut-mini-IPS_2024-09-25.png

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:

  1. 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.
  2. 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.
  3. 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.

  1. Without I2C: Connect the LCD in 4-bit mode to the Atmega328P:
  2. RS to digital pin 12
  3. E to digital pin 11
  4. D4 to D7 to digital pins 5, 4, 3, 2 respectively.
  5. VDD to 5V, VSS to ground.
  6. A 10K potentiometer is connected to the VO pin for contrast adjustment.
  7. 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:

  1. 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.
  2. 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.

  1. The relay is controlled by the BC547 transistor:
  2. Base of the BC547 is connected to digital pin 7 of the Atmega328P through a 1K resistor.
  3. The collector of the BC547 is connected to one end of the relay coil.
  4. The emitter of the BC547 is connected to ground.
  5. 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.

  1. Connect the push button to pin 2 of the Atmega328P.
  2. 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.

  1. The input pin is connected to the 12V battery.
  2. The output pin provides 5V, which is connected to the Vcc pin of the Atmega328P and other components requiring 5V.
  3. 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;


  1. relayPin: This is connected to the base of the BC547 transistor, which controls the relay.
  2. buttonPin: The pin connected to the push button for manual load control.
  3. chargePin: This analog pin is connected to the voltage divider to read the battery voltage.
  4. loadState: A variable that keeps track of whether the load is ON or OFF.
  5. manualControl: A boolean flag that keeps track of whether manual control is activated via the push button.
  6. 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:

  1. (sensorValue * (5.0 / 1023.0)): Converts the sensor value to the actual voltage based on the 5V reference.
  2. 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:

  1. If the battery voltage drops below 11.5V (discharged), the relay turns on, powering the load, and the system starts charging the battery.
  2. If the voltage rises above 13.5V (fully charged), the relay turns off, stopping the charging to protect the battery from overcharging.

LCD Display:

  1. lcd.setCursor(0, 0): Sets the cursor to the first line of the LCD to display the charging status.
  2. lcd.print("Charging: ON/OFF"): Displays whether the charging is currently ON or OFF.
  3. 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

}


  1. Manual Control Logic:
  2. If the push button is pressed, it toggles the loadState (ON/OFF).
  3. 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.
  4. When the button is released (buttonState == LOW), manualControl is reset, so the button can be pressed again to toggle the load.
  5. LCD Display for Load State:
  6. This section updates the LCD to show the current load state (ON or OFF).
  7. 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).
  8. The current state of the load (ON/OFF) is displayed accordingly.
  9. Debouncing:
  10. A small delay (delay(100)) is added to prevent accidental multiple button presses caused by mechanical bouncing of the switch.

Code Flow Summary

  1. Setup:
  2. Initializes the pins, LCD display, and relay.
  3. Main Loop:
  4. Reads the battery voltage and decides whether to turn on/off the charging (by controlling the relay).
  5. Displays battery voltage and charging status on the LCD.
  6. Reads the push button state for manual control and toggles the load accordingly.
  7. Updates the LCD display to show whether the load is ON or OFF.
  8. Manual Load Control:
  9. 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

অটোমেটিক অটোকাট Mini DC IPS তৈরি করুন ডিসপ্লে সহ | DIY Mini IPS | Battery Charger

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.