Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Controlled GSM Relay for UPI Payment-Based Charging

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled GSM Relay for UPI Payment-Based Charging

Circuit Documentation

Summary

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.

Component List

Microcontroller

Communication Module

Power Control

Power Sources

Display

Indicators

Protection

User Input

Resistors

Power Management

Wiring Details

Arduino Micro (Rev3)

Sim800l

1 Channel 5V Relay Module

Battery AAx3 4.5V

I2C LCD 16x2 Screen

LED: Two Pin (red)

Pushbutton

Resistors

USB Female

1N4007 Rectifier Diode

Documented Code

#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.