I needed this assignment idea to be related to the servo motor, so I can be more familiar with it since a big portion of my final project is based on it, upon a few searches, I found a very relatable application that may be applied to many applications in out daily life, and it is the car parking system using ultrasonic sensor and LDR module.
Here is the link of inspiration:
https://create.arduino.cc/projecthub/guruashishchoudhary29/automatic-parking-system-81d9fa
Tinkercad
Used to simulate electrical circuits and components, so you can calibrate your circuit calculations and needs before even going to the hardware steps.
Tools and Materials
Arduino Uno Board
Ultrasonic Sensor
LDR Module
Servo Motor
LED
Breadboard
Jumpers and Wires
Arduino IDE
Used to compile the code written in the programming sketches and upload it directly to our Arduino Board.
Input Components:
- Ultrasonic senor.
- LDR module.
Output components:
- Servo motor.
- LED.
So the first thing the code does is processing the data of both ultrasonic sensor and LDR modules.
The ultrasonic sensor takes the distance between it and the first object front of it.
The LDR module gives us a digital status, whether anything blocks it from all the sources of light or not.
So if BOTH the distance equals to or less than 5 cm and the LDR module is blocked from light, only then, the garage door is opened using servo motor and a LED is powered on, else, the LED will be off and the servo will return to its initial state.
The code consists of 9 parts, which will be explained in the following lines:
Part 1:
It is basically summoning all the libraries we will want to use in this program, in our case the servo motor library.
Part 2:
Defining all the instances of the hardware components we will use.
Part 3:
In this part we stored the pins numbers in meaningful variables so it can be easily used across the code without any problem, this is called decoupling.
Part 4:
Initiating the variables that will be used by the sensors.
Part 5:
Initiating hardware components and setting the state for every used pin.
Part 6:
Measuring light intensity by LDR module and storing result in variable while printing it in serial monitor.
Part 7:
Measuring distance between the sensor and the object in front of, while storing the result in variable and printing it in serial monitor.
Part 8:
Defining the condition to open the garage door.
Part 9:
Defining the default state when no object is infront of the garage door.
The main function of the circuit is to act like a parking system, if the car is on a certain distance, which will be determined by the ultrasonic sensor and the LDR module, the garage door, that is represented by a servo motor, will open and a light that is represented by LED will be powered up, else both will close or will stay closed.
So first after I finished the circuit diagram in Tinkercad, just prepared the components I used and fixed it in the breadboard, and after fixing all the components I started connecting them to the Arduino board.
Then I started programming and testing the functionality of each component apart, and when I get the handle of how the component works and how I want to use it, I merge it into my code, applying the OOP practices while working.
After validating the connections and the code are both working fine and as expected, then all the components where merged and fixed in the enclosure to have our final SMART GARAGE product prototype.
Was helping my peers in explaining and going through difficulties in the coding and programming part, as I have working experience in, summary to the topics was how to make the code modular while interacting with different sensors and components like ultrasonic sensor, LCD and others.
While we were troubleshooting a colleague - Bassem - circuit diagram, we encountered an error while using the 4 legged push button, Ibrahim helped us with getting through with this and explained that those kind of push buttons need to have each 2 legs on a separate side of the breadboard, and that was the point we didn't notice