This week’s assignment is to Communicate wirelessly with a Smart Circuit via a Graphical User Interface (GUI) on your phone or PC.
I get inspiration from smart doors so I want to make a smart door for my home to control opening the door and the entrance lights to my guests remotely.
Electronic Copmonents:
Arduino IDE
The App interface
I started with simulating the circuit on Tinkercad to make sure of the connection as fellow:
1- connect the Bluetooth module with the breadboard and Arduino as fellow:
- Txd to Rx in Arduino.
- Rxd to TX in Arduino.
- Vcc to 5v on breadboeard.
- GND to GND on breadboard.
2- connect the led (output) leg to the resistor to ground and the other to pin 3.
3- connect Servo motor (output) ground to ground, positive to 5v and the other leg to pin 5.
4-Build the circuit with the same wiring with adding Bluetooth module as mentioned.
5- Start to write the code so first we had to add character the data coming from the serial read then in the void setup we had to serial begin Notice in Serial.begin() we pass in the value 9600. This is called the baud rate – it sets the speed of the serial communication, and represents bits per second. Both devices must have the same baud rate selected for Serial Communication to work.
6- mention the pins used and its state ether input or output
pin(5) for the servo motor (output).
pin(3) for the led (output).
7- then the void loop
first make the incoming data character take the serial read from the monitor
then we add if condition the device have 4 modes only
1-the led and the motor is off which is the default.
2-the led is on when the serial read is 1.
3-the led is off when the serial read is 2.
4-the servo rotate to 90 deg when the serial read is 3.
5-the servo rotate to 0 deg is on when the serial read is 4.
so we needed 4 if conditions the serial read is 1 then pin (3) are HIGH to turn the led on, the serial read is 2 then pin (3) are low to turn the led off, the serial read is 3 then the servo rotate 90 deg to open the door and finally the serial read is 4 then the servo rotate to 0 deg to close the door.
After uploading the code it works only for the led but the motor doesn't work so I found that I forgot to include the servo library. Then I include the servo.h library and the motor still not working so I checked the circuit and wiring to found that the jumper that connected to the servo’s ground has a crooked pin so it wasn’t connected well so I replace it with another one and the servo working well.
It was the best thing I have tried within whole sessions is to make such a robotic arm.