The circuit in question appears to be a security system that involves user interaction through a keypad and visual feedback via an LCD display. It includes a microcontroller (STM32 Nucleo 64 F411RE) for processing inputs and controlling outputs, an ESP8266 NodeMCU for WiFi connectivity, a 4x4 membrane matrix keypad for input, an Adafruit Standard LCD (16x2) for display, a potentiometer for contrast adjustment on the LCD, a Tower Pro SG90 servo motor for physical lock control, and two LEDs (green and red) for status indication.
#include "stm32f4xx_hal.h"
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>
LiquidCrystal lcd(D10, D11, D12, D13, D14, D15);
Servo servo;
String receivedOTP = "";
String enteredOTP = "";
bool locked = true;
// Keypad setup
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {D7, D6, D5, D4};
byte colPins[COLS] = {D3, D2, D1, D0};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
lcd.begin(16, 2);
servo.attach(D9);
Serial.begin(9600);
pinMode(D8, OUTPUT); // Lock LED
pinMode(D7, OUTPUT); // Unlock LED
lockDoor();
}
void loop() {
if (Serial.available()) {
receivedOTP = Serial.readStringUntil('\n');
}
char key = keypad.getKey();
if (key) {
if (key == '#') {
checkOTP();
} else {
enteredOTP += key;
lcd.setCursor(0, 1);
lcd.print(enteredOTP);
}
}
}
void checkOTP() {
if (enteredOTP == receivedOTP) {
unlockDoor();
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Incorrect OTP");
delay(2000);
enteredOTP = "";
lcd.clear();
}
}
void lockDoor() {
servo.write(0); // Lock position
locked = true;
digitalWrite(D8, HIGH); // Turn on Lock LED
digitalWrite(D7, LOW); // Turn off Unlock LED
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Door Locked");
}
void unlockDoor() {
servo.write(90); // Unlock position
locked = false;
digitalWrite(D8, LOW); // Turn off Lock LED
digitalWrite(D7, HIGH); // Turn on Unlock LED
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Door Unlocked");
delay(5000); // Delay before auto-lock
lockDoor();
}
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "your_BLYNK_AUTH_TOKEN"; // Replace with your Blynk Auth Token
const char* ssid = "your_SSID"; // Replace with your WiFi SSID
const char* password = "your_PASSWORD"; // Replace with your WiFi password
String otp = "1234"; // OTP to be sent to STM32
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
Blynk.begin(auth, ssid, password);
}
void loop() {
Blynk.run();
if (/* Condition to send OTP */) {
Serial.println(otp);
}
}
(Note: The actual condition to send the OTP from the ESP8266 to the STM32 is not provided in the code snippet and should be implemented based on the specific requirements of the application.)