This circuit is designed to function as a security system using a Reed Switch to detect an open/close event, LEDs to indicate system status, a Bluetooth module for remote communication, and an Arduino UNO microcontroller to control the system logic. The system operates by monitoring the state of the Reed Switch. When the switch is activated, the system checks for a Bluetooth connection. If a correct passcode is received via Bluetooth, the green LED lights up; otherwise, the red LED is activated. If the Reed Switch is not activated and no Bluetooth connection is present, the system sends an intruder alert message.
/*
* Arduino Sketch for Security System
*
* This code controls a security system using a Reed Switch, LEDs, and a Bluetooth module.
* When the Reed Switch is activated and the Bluetooth module is connected with the correct
* passcode, the green LED will light up. If the passcode is incorrect, the red LED will light up.
* If the Reed Switch is not activated and the Bluetooth module is not connected, an intruder
* alert message will be sent to the operating software.
*/
#include <SoftwareSerial.h>
// Pin definitions
const int reedSwitchPin = 10;
const int greenLEDPin = 11;
const int redLEDPin = 12;
const int bluetoothRxPin = 0;
const int bluetoothTxPin = 1;
// Bluetooth setup
SoftwareSerial bluetooth(bluetoothRxPin, bluetoothTxPin);
void setup() {
// Initialize serial communication
Serial.begin(9600);
bluetooth.begin(9600);
// Initialize pin modes
pinMode(reedSwitchPin, INPUT);
pinMode(greenLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
// Turn off LEDs initially
digitalWrite(greenLEDPin, LOW);
digitalWrite(redLEDPin, LOW);
}
void loop() {
// Check the state of the Reed Switch
int reedState = digitalRead(reedSwitchPin);
// Check if Bluetooth is connected
if (bluetooth.available()) {
String passcode = bluetooth.readString();
if (reedState == HIGH) {
if (passcode == "correct_passcode") {
// Correct passcode, light up green LED
digitalWrite(greenLEDPin, HIGH);
digitalWrite(redLEDPin, LOW);
} else {
// Incorrect passcode, light up red LED
digitalWrite(greenLEDPin, LOW);
digitalWrite(redLEDPin, HIGH);
}
}
} else if (reedState == LOW) {
// Reed Switch not activated and Bluetooth not connected
Serial.println("Intruder alert!");
}
// Small delay to avoid bouncing
delay(100);
}
This code is saved as sketch.ino
and is intended to be uploaded to the Arduino UNO microcontroller. It includes the necessary setup for the pins, the main loop for checking the Reed Switch state, and the logic for handling Bluetooth communication and LED control.