This circuit is designed to control a charging system using an Arduino Micro microcontroller. It features a GSM module (Sim800l) for communication, a relay module for controlling power to a charging device, an I2C LCD screen for displaying information, and various other components such as resistors, an LED, a pushbutton, and a diode for protection. The system operates by receiving payments via SMS, which then adds balance to the system, allowing for a certain amount of charging time.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
// Initialize the LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Set up the GSM Module
SoftwareSerial gsmSerial(1, 0); // RX, TX
// Pin Definitions
const int relayPin = 7; // Pin connected to the relay module
const int buttonPin = 2; // Pin connected to the button
const int ledPin = 13; // Onboard LED for status indication
// Variables
int balance = 0; // Prepaid balance (in seconds)
const int chargeRate = 1; // Amount to deduct per second of charging
void setup() {
// Initialize pins
pinMode(relayPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // Using internal pull-up resistor
pinMode(ledPin, OUTPUT);
// Initialize the LCD
lcd.begin(16, 2); // Corrected to include the number of columns and rows
lcd.backlight();
lcd.print("UPI Charging");
// Initialize GSM Module
gsmSerial.begin(9600);
sendSMS("System Ready for UPI Payment!");
// Initial state
digitalWrite(relayPin, LOW); // Ensure relay is off
digitalWrite(ledPin, LOW); // LED off initially
}
void loop() {
// Check if an SMS is received
if (gsmSerial.available()) {
String sms = gsmSerial.readString();
if (sms.indexOf("PAYMENT") >= 0) {
// Simulate UPI payment received
balance += 60; // Add 60 seconds of charge time
sendSMS("Payment Received. Balance Added: 60s");
}
}
// Display current balance
lcd.setCursor(0, 1);
lcd.print("Balance: ");
lcd.print(balance);
lcd.print("s "); // Print seconds
// If balance is greater than 0, enable charging
if (balance > 0) {
digitalWrite(relayPin, HIGH); // Turn on the relay (charging enabled)
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(1000); // 1 second delay
// Deduct balance
balance -= chargeRate; // Deduct 1 second of charge time
} else {
// No balance, disable charging
digitalWrite(relayPin, LOW); // Turn off the relay
digitalWrite(ledPin, LOW); // Turn off the LED
}
}
void sendSMS(String message) {
gsmSerial.println("AT+CMGF=1"); // Set SMS mode to text
delay(100);
gsmSerial.println("AT+CMGS=\"+1234567890\""); // Replace with your phone number
delay(100);
gsmSerial.println(message);
delay(100);
gsmSerial.write(26); // ASCII code for CTRL+Z to send the message
delay(1000);
}
This code is responsible for controlling the charging system. It initializes the LCD and GSM module, sets up the pins, and enters a loop where it checks for incoming SMS messages indicating payment. Upon receiving a payment, it adds balance and enables the relay to allow charging. The balance is displayed on the LCD and is decremented every second until it runs out, at which point the relay and LED are turned off. The sendSMS
function is used to send SMS messages to notify the user of system status.