Smart Door and smart Alarm
I was inspired by Kareem Abdel Aziz's advertisement for a smart city, where everything operates intelligently.
Programs needed:
IDE.
Tinker Cad.
GUI.
Components needed:
1.Arduino.
2.USB Cable.
3.Jumpers.
4.Bluetooth Module.
5.Servo Motor
6.Breadboard.
8.Buzzer.
Design using TinkerCAD
To design and prepare this project before implementation, I used several tools and software, including an IDE for programming, TinkerCAD for circuit simulation, and a GUI for user interaction. First, I created the circuit layout in TinkerCAD to visualize the connections and ensure compatibility between components. Below is a breakdown of how each component is connected to the Arduino:
Component Connections:
Bluetooth Module (HC-05/HC-06)
VCC → 5V (Arduino)
GND → GND (Arduino)
TX → RX (Pin 10) (Arduino)
RX → TX (Pin 11) (Arduino) (Use a voltage divider if needed to step down from 5V to 3.3V)
Servo Motor
VCC (Red Wire) → 5V (Arduino)
GND (Black Wire) → GND (Arduino)
Signal (Yellow Wire) → Pin 9 (Arduino)
Buzzer
Positive (Long Leg) → Pin 8 (Arduino)
Negative (Short Leg) → GND (Arduino)
Breadboard (Used to manage connections and provide a stable circuit layout.)
Jumper Wires (Used for connections between components and Arduino.)
USB Cable (Used to upload the code to the Arduino and provide power.)
After designing the circuit in TinkerCAD, I tested the setup virtually by simulating input signals. Once the circuit was confirmed to work correctly, I physically built it on a breadboard and ensured all connections were stable before moving to coding and implementation.
For implementation, I assembled the physical circuit by following the designed connections. After ensuring all components were securely placed, I uploaded the Arduino code via the Arduino IDE. The Bluetooth module was used to establish wireless communication, while the GUI allowed users to send commands to the Arduino.
Component Connections:
Bluetooth Module (HC-05/HC-06)
VCC → 5V (Arduino)
GND → GND (Arduino)
TX → RX (Pin 10) (Arduino)
RX → TX (Pin 11) (Arduino) (Use a voltage divider if needed to step down from 5V to 3.3V)
Servo Motor
VCC (Red Wire) → 5V (Arduino)
GND (Black Wire) → GND (Arduino)
Signal (Yellow Wire) → Pin 9 (Arduino)
Buzzer
Positive (Long Leg) → Pin 8 (Arduino)
Negative (Short Leg) → GND (Arduino)
Breadboard (Used to manage connections and provide a stable circuit layout.)
Jumper Wires (Used for connections between components and Arduino.)
USB Cable (Used to upload the code to the Arduino and provide power.)
To test the system:
I used a Bluetooth terminal app on a mobile device to send commands ('O' for open and 'C' for close).
The servo motor responded to these commands by changing its position.
The buzzer was activated momentarily when the servo moved.
The system was tested multiple times to ensure proper function and debugging was done as needed.
This approach ensured that the project was successfully implemented, allowing for a remote-controlled servo and buzzer using Bluetooth communication.
This Arduino code allows you to control a servo motor and a buzzer wirelessly using a Bluetooth module (HC-05/HC-06). The system receives commands ('O' to open, 'C' to close) via Bluetooth, moves the servo motor, and triggers the buzzer.
1. Including the Servo Library
#include <Servo.h>
The Servo.h library is included to control the servo motor.
This library simplifies positioning the servo by specifying an angle (0° to 180°).
2. Defining Variables and Pins
Servo myServo; // Create a Servo object
char command; // Variable to store received Bluetooth command
#define BUZZER 8 // Define the buzzer pin
#define SERVO_PIN 9 // Define the servo pin
#define BLUETOOTH_TX 10 // TX pin of Bluetooth module (Connect to RX of HC-05)
#define BLUETOOTH_RX 11 // RX pin of Bluetooth module (Connect to TX of HC-05)
myServo: Creates a servo object to control the motor.
command: A variable to store the received Bluetooth command.
BUZZER (Pin 8): Digital pin connected to the buzzer.
SERVO_PIN (Pin 9): Digital pin connected to the servo motor.
BLUETOOTH_TX (Pin 10) and BLUETOOTH_RX (Pin 11): Defines the pins where the Bluetooth module is connected.
3. Setup Function (Runs Once at Startup)
void setup() {
Serial.begin(9600); // Start serial communication
myServo.attach(SERVO_PIN); // Attach the servo to pin 9
pinMode(BUZZER, OUTPUT); // Set buzzer pin as output
digitalWrite(BUZZER, LOW); // Initially turn off the buzzer
}
Serial.begin(9600): Starts serial communication at 9600 baud rate for Bluetooth communication.
myServo.attach(SERVO_PIN): Links the servo object to pin 9.
pinMode(BUZZER, OUTPUT): Sets the buzzer pin as an output.
digitalWrite(BUZZER, LOW): Ensures the buzzer is OFF at startup.
4. Loop Function (Runs Continuously)
void loop() {
if (Serial.available()) { // Check if data is available from Bluetooth
command = Serial.read(); // Read the received character
Serial.println(command); // Print the command for debugging
Serial.available(): Checks if a Bluetooth command has been received.
Serial.read(): Reads the incoming character ('O' or 'C') and stores it in command.
Serial.println(command): Prints the received command to the Serial Monitor for debugging.
5. Checking the Received Command
if (command == 'O') { // 'O' opens the servo
myServo.write(90); // Move servo to 90 degrees
digitalWrite(BUZZER, HIGH); // Turn on buzzer
delay(1000); // Keep buzzer on for 1 second
digitalWrite(BUZZER, LOW); // Turn off buzzer
}
If the received command is 'O', it:
Moves the servo to 90° (open position).
Turns on the buzzer.
Keeps the buzzer on for 1 second.
Turns the buzzer off.
6. Closing the Servo
else if (command == 'C') { // 'C' closes the servo
myServo.write(0); // Move servo back to 0 degrees
}
}
}
If the received command is 'C', it:
Moves the servo back to 0° (closed position).
The buzzer does not activate in this case.
The Bluetooth module receives a signal from a mobile app or PC.
The Arduino reads the received character via Bluetooth.
If the command is:
'O': The servo opens to 90°, and the buzzer beeps for 1 second.
'C': The servo closes to 0°.
The loop continues waiting for new commands.
The CODE on IDE
Title of Media
Title of Media
Title of Media
Title of Media