This week's assignment is to communicate wirelessly with a smart circuit via a Graphical User Interface (GUI) on phone or PC. I decided to make a Smart Door Lock. The cirucit controls a motor to lock and unlock door along with status notifier (buzzer). This idea supports the concept of wireless serial communication & making things talk to things.
Software: Tinkercad
Software:Arduino IDE
Software:Arduino BlueControl app
Components: Arduino Uno board
Components: Micro Servo motor
Components: Buzzer
Components: HC-05 Bluetooth module
Components: Jumper wires
Circuit connection on Tinkercad
Circuit design:
Link for circuit: Here
On Fritzing, I started to put the components I will use in my circuit. The circuit contains two action components, Buzzer and Servo. Also, and input component which is bluetooth to send data to arduino.
I wired the 5V and GND from Arduino to breadboard.
I connected the buzzer on analog output pin 11 with +ve terminal and GND with -ve terminal.
I connected the Servo on analog output pin 10 for signal and powered it using the rails.
Finally, the bluetooth module is connected from RX (blue.) to TX (arduino) and TX (blue.) to RX (arduino) and powered it form breadboard .
Arduino code for the circuit
Code & logic:
I started first by dividing the problem and defining the objectives clearly and what I want to achieve.
I declared a variable for buzzer and another one for incoming data to store input.
In setup function, I wrote the pinMode for buzzer attached the servo to its pin (3). I also started the serial to test with with and set servo intially to angle 0 degree.
In loop funciton, I checked first if there is input with (.available) funciton.
I took the input from user using (.read) function.
Then there is three cases. if input is "1" the servo moves and buzzer makes one beep. (open door)
The other case is if input is "2" the servo goes bake and makes two beeps. (close door)
The last case if anything else is input, the program says "Invalid Input".
Circuit Implementation and mounting:
I started putting the components on the breadboard.
I connected the 5v and GND from Arduino to the rails on breadboard.
I connected the buzzer on analog pin 11 and other leg to GND on arduino directly.
I connected the servo with arduino power and signal pin 3.
After that, I connected the bluetooth module with pin 1 and 2 for RX & TX.
Finally, I selected the board and the port then clicked upload.
Buzzer connected on arduino directly
Bluetooth module connected with arduino and breadboard
Servo connection with breadboard and pin 3
5v and gnd from Arduino
Final outcome
After I connected the circuit, it is logical to try it first with serial monitor before connecting bluetooth as it is exactly the same circuit and code to exclude them when bluetooth connection fails. When I did that, there was a space printed and also the phrase Invalid Input which exists in another else if different from the input I enter. After I searched online, the reason turned out to be that when I press enter, the computer sends the letter "\n" as an input so it is not only the number but also the enter is considered. The solution was to edit line ending form menu on the top right of serial monitor.
Serial monitor outputs non expected output
Solution is to edit line ending
It was very cool when I realized that I can make arduino talk to another arduino to exapand its functionalities. it was nice!
This week we controlled components with bluetooth and made a small robotic arm to catch some fishes using silk and magnets. It was nice to make moving objects and connect its parts.