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

Wi-Fi Controlled RFID-Based Smart Socket with LCD Display Using ESP8266

View and Edit Project In Cirkit DesignerImage of Wi-Fi Controlled RFID-Based Smart Socket with LCD Display Using ESP8266

Circuit Documentation

Summary

This circuit is designed to integrate an ESP8266 NodeMCU microcontroller with an LCD I2C Display, an RFID-RC522 module, a relay module, and a socket. The circuit also includes a Mini AC-DC 110V-230V to 5V 700mA module for power conversion and an AC source. The primary function of this circuit is to read RFID cards, display information on the LCD, and control a relay based on the RFID card data.

Component List

  1. ESP8266 NodeMCU

    • Description: A low-cost Wi-Fi microcontroller with GPIO, PWM, ADC, I2C, and SPI capabilities.
    • Pins: D0, D1, D2, D3, D4, 3V3, GND, D5, D6, D7, D8, RX, TX, A0, RSV, SD3, SD2, SD1, CMD, SD0, CLK, EN, RST, VIN
  2. LCD I2C Display

    • Description: A 16x2 character LCD display with I2C interface.
    • Pins: GND, VCC, SDA, SCL
  3. RFID-RC522

    • Description: A low-cost RFID reader module that operates at 13.56 MHz.
    • Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA
  4. Relay Module 1 Channel

    • Description: A single-channel relay module used for switching high voltage devices.
    • Pins: S, 5V, GND, NC, COM, NO
  5. Socket

    • Description: A standard electrical socket.
    • Pins: Earth, Life, Neutral
  6. Mini AC-DC 110V-230V to 5V 700mA Module

    • Description: A power module that converts AC voltage (110V-230V) to 5V DC.
    • Pins: GND, 5V, Neutral, Life
  7. AC Source

    • Description: An AC power source.
    • Pins: -, +

Wiring Details

ESP8266 NodeMCU

LCD I2C Display

RFID-RC522

Relay Module 1 Channel

Socket

Mini AC-DC 110V-230V to 5V 700mA Module

AC Source

Documented Code

Main Code (sketch.ino)

#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ESP8266WiFi.h>
#include "User.h"
#include "LibHelper.h"

#define SS_PIN D4 // SDA
#define RST_PIN D3 // RST

MFRC522 rfid(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 lines display

const char* ssid = "MGTech IT Solutions";
const char* password = "mgtech2020";
// const char* ssid = "Excel";
// const char* password = "tanginamo";

unsigned long previousMillis = 0; // Stores the last time x was printed

bool isConnected = false;
String rfidUID = "";
bool cardPresent = false;
bool cardAccepted = false;
volatile unsigned long cardPulseTime;

String LCDTop = "";
String LCDBot = "";

unsigned long startTime = 0;
unsigned long elapsedTime = 0;
int seconds = 0;
int minutes = 0;
int hours = 0;
int previousSeconds = -1;
int previousMinutes = -1;
int previousHours = -1;

int credits = 0;
int creditTime = 0;

void connectToWiFi() {
  WiFi.begin(ssid, password);

  // Keep trying to connect until successful
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }

  // Connection successful
  Serial.println("");
  Serial.println("Wi-Fi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  setLCDText("WiFi Connected", WiFi.localIP().toString());

  previousMillis = millis();
}

void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
  
  lcd.init();
  lcd.backlight();
  
  setLCDText("Connecting WiFi", " ");
  Serial.print("Connecting WiFi");

  connectToWiFi();
}

void loop() {
  checkWifi();
  checkRFID();
  
  if (cardPresent && cardAccepted) {
    timeLoop();
  }

  delay(100);
}

void checkWifi() {
  unsigned long currentMillis = millis(); // Get the current time
  if (currentMillis - previousMillis >= 500