Arduino-Based Smart Security System with Ultrasonic Sensor, Keypad, and RGB LED
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit consists of various components including an Arduino UNO, sensors, LEDs, a keypad, an LCD, and a buzzer. The circuit is designed to perform multiple functions such as detecting obstacles using an ultrasonic sensor, reading sound levels, displaying information on an LCD, and evaluating password strength entered via a keypad. The RGB LED and other LEDs provide visual feedback based on sensor inputs and password strength.
Component List
4X4 Membrane Matrix Keypad
- Pins: R1, R2, R3, R4, C1, C2, C3, C4
- Description: A keypad used for inputting passwords.
- Purpose: To allow user input for password evaluation.
8x8 Matrix
- Pins: vcc, DIN, clk, CS, Gnd, gnd, CLK
- Description: An 8x8 LED matrix.
- Purpose: To display patterns or information visually.
Arduino UNO
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
- Description: A microcontroller board.
- Purpose: To control the circuit and execute the embedded code.
Ultrasonic Sensor
- Pins: +VCC, Trigger, Echo, GND
- Description: A sensor to measure distance.
- Purpose: To detect obstacles and measure distance.
LED: Two Pin (red)
- Pins: cathode, anode
- Description: A red LED.
- Purpose: To provide visual feedback.
LED: Two Pin (green)
- Pins: cathode, anode
- Description: A green LED.
- Purpose: To provide visual feedback.
LED: Two Pin (yellow)
- Pins: cathode, anode
- Description: A yellow LED.
- Purpose: To provide visual feedback.
Resistor
- Pins: pin1, pin2
- Description: A resistor with 200 Ohms resistance.
- Purpose: To limit current through LEDs.
16x2 I2C LCD
- Pins: GND, VCC, SDA, SCL
- Description: A 16x2 character LCD with I2C interface.
- Purpose: To display information.
Buzzer
- Pins: PIN, GND
- Description: A buzzer.
- Purpose: To provide audible feedback.
RGB LED (Wokwi compatible)
- Pins: R, COM, G, B
- Description: An RGB LED.
- Purpose: To provide multi-color visual feedback.
Sound Sensor
- Pins: Analog, GND, VCC, Digital
- Description: A sensor to detect sound levels.
- Purpose: To detect sound and provide input to the microcontroller.
Wiring Details
4X4 Membrane Matrix Keypad
- R1 to Arduino UNO D9
- R2 to Arduino UNO D8
- R3 to Arduino UNO D7
- R4 to Arduino UNO D6
- C1 to Arduino UNO D5
- C2 to Arduino UNO D4
- C3 to Arduino UNO D3
- C4 to Arduino UNO D2
8x8 Matrix
- vcc to Arduino UNO 5V
- DIN to Arduino UNO A3
- clk to Arduino UNO A1
- CS to Arduino UNO A2
- Gnd to Arduino UNO GND
Arduino UNO
- 5V to Ultrasonic Sensor +VCC, Sound Sensor VCC, 8x8 Matrix vcc, 16x2 I2C LCD VCC
- GND to Ultrasonic Sensor GND, Sound Sensor GND, RGB LED COM, 8x8 Matrix Gnd, 16x2 I2C LCD GND, Resistors pin1
- A0 to Buzzer PIN
- A1 to 8x8 Matrix clk
- A2 to 8x8 Matrix CS
- A3 to 8x8 Matrix DIN
- A4 to 16x2 I2C LCD SDA
- A5 to 16x2 I2C LCD SCL
- D13 to LED (green) anode
- D12 to LED (yellow) anode
- D11 to LED (red) anode
- D9 to Ultrasonic Sensor Trigger
- D8 to Ultrasonic Sensor Echo
- D6 to RGB LED B
- D5 to RGB LED G
- D3 to RGB LED R
- D11 to Sound Sensor Digital
Ultrasonic Sensor
- +VCC to Arduino UNO 5V
- Trigger to Arduino UNO D9
- Echo to Arduino UNO D8
- GND to Arduino UNO GND
LED: Two Pin (red)
- anode to Arduino UNO D11
- cathode to Resistor pin2
LED: Two Pin (green)
- anode to Arduino UNO D13
- cathode to Resistor pin2
LED: Two Pin (yellow)
- anode to Arduino UNO D12
- cathode to Resistor pin2
Resistor
- pin1 to Arduino UNO GND
- pin2 to LED (red) cathode, LED (green) cathode, LED (yellow) cathode
16x2 I2C LCD
- GND to Arduino UNO GND
- VCC to Arduino UNO 5V
- SDA to Arduino UNO A4
- SCL to Arduino UNO A5
Buzzer
- PIN to Arduino UNO A0
- GND to Resistor pin1
RGB LED (Wokwi compatible)
- R to Arduino UNO D3
- COM to Arduino UNO GND
- G to Arduino UNO D5
- B to Arduino UNO D6
Sound Sensor
- Analog (not connected)
- GND to Arduino UNO GND
- VCC to Arduino UNO 5V
- Digital to Arduino UNO D11
Documented Code
Arduino UNO (Instance 1)
// Pin Definitions
const int trigPin = 9;
const int echoPin = 8;
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
const int micPin = 11;
// Thresholds
const int distanceThreshold = 20; // in cm
const int soundThreshold = 500; // Adjust based on sound module output
const int debounceDelay = 200; // Debounce delay for sound input in ms
// Variables
long duration;
int distance;
bool stopCommand = false; // Tracks if the "stop" command has been detected
static unsigned long lastSoundTime = 0;
void setup() {
// Ultrasonic Sensor
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// RGB LED
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
// Microphone
pinMode(micPin, INPUT);
// Serial Monitor
Serial.begin(9600);
}
void loop() {
// Measure distance using Ultrasonic Sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2; // Convert to cm
// Read sound level
int soundLevel = analogRead(micPin);
Serial.print("Sound Level: ");
Serial.print(soundLevel);
Serial.print(" | Distance: ");
Serial.print(distance);
Serial.print(" cm | Stop Command: ");
Serial.println(stopCommand ? "ON" : "OFF");
// Check for the "stop" command
if (soundLevel > soundThreshold