I wanted to do something related to my final project to test myself and see the time I'll take .
My final project is a smart home so I decided to make a smart door ; opens in 2 different modes controlling them with a slide switch , the first mode : the door opens when I write a correct password and the second mode when I'm at a distance lower than 10 cm from the door.
Slide switch
Arduino Uno and it's cable
Ultrasonic sensor
One buzzer
Some male-female and male-male wires
Breadboard
Avometer
A box from cardboard
Arduino APP.
Servo motor
3*4 Keypad
Sewing thread
I need cardboard to be the enclosure and to make a door to be opened, I need Arduino Uno to be the microcontroller of the project and it's cable to connect it to the PC,I need Arduino App to write the code of the project, A keypad is necessary to write the password, buzzer to show that if I need to write another password or not ,I need also Ultrasonic sensor to detect the distance ,A servo to open the door with the help of sewing thread, I need a slide switch to make me move from one mode to the other . I needed also a breadboard to help me to connect my wires. And finally, Avometer to check my wiring.
Design in TinkerCAD website
I used the search tab to collect my tools then I started connecting them : the ultrasonic needs a power and ground also needs two output I used pins 11and12,Then I connected the servo with input pin 10.I didn't find 3*4 keypad in tinkercad so I used keypad 4*4 but I didn't connect column(4) pin the other pins were connected from (2-8)pins in the Arduino .I used also the slide switch and connected it to pin 13. Finally I put the buzzer and connected one pin of it to an analog pin(9) to have different sounds. , and the other pin was put to the ground.
After connecting the wires in Tinkercad I moved to Arduino App to write the code , I started writing a code to operate the servo using the ultrasonic only.
I used servo examples from the App to help me see how to write the code of servo and what libraries I may need . I took 3 lines : #include <Servo.h> , Servo myservo and myservo.attach().
Then I attached it to pin 10 and made the servo set its position to zero degree .
I moved to the Ultrasonic code I searched for it first and found that it will need to send some waves , get them back and calculate the distance from the time it needed to come back. So , I attached the trigger as output in pin 11 and echo as input in pin 12 .Then I made trigger LOW then HIGH then LOW to send waves and took it in the echo pin using pulsIn function.
Finally , I made the condition that the distance is lower than 10 cm the servo will move 180 degrees else it will be the same. I used print serial to help me catch errors if any.
Ultrasonic with servo code
The final Arduino code for ultrasonic and Keypad
I then moved to the keypad code and wrote it in a different file ,This week tutorial helped me to write its code.
First, I downloaded the library then made a two dimensional array to store the rows and columns and used input pins from 2 until 8.I used the function getKey to get the number which I press and store them in variables : digit1,2,3,4 and enter.
I used a count variable to be a flag so that I can know I have entered 4 digits and pressed enter. After I have entered what I need I will check first for the enter key using switch case ; if False I will make a sound in the buzzer and won't change the servo , if True I will check for the digits . Once I found the digits True I'll open the door and make a worm sound with the buzzer. If not I won't open it .
Finally , I have made a new digital input pin (13) for the mode switch and made a condition for it ; if it read HIGH I'll put the whole Keypad code inside , else I'll put the whole ultrasonic code( from the last file ) to be implemented.
I didn't know how to make the servo open or close the door , I searched to know and found people using something like iron wires so I decided to use sewing thread :)
This week I have learned how to download libraries to Arduino App and how to get examples to know what functions I'll use.
Also, I learned how to deal with Keypad as it's the first time for me to use.
Finally, I have learned how to merge two modes in one code using the slide switch.
Saeed surprised us and came to fab-lab Mansoura ♥