This week I decided to make a parking sensor device, where the function is to sense the distance between the car and the obstacle using ultrasonic sensors while indicating the distance by led lights or beeping sounds from a buzzer.
I used Arduino IDE to communicate with the Arduino UNO board and give it instructions.
I used TinkerCAD to design and simulate the circuit.
Ultrasonic sensor
LED
Sliding switch
Piezo buzzer
For this assignment I wanted to make a parking sensor with two modes:
The first mode is just a demonstration of the LED light and the buzzer sound.
The second mode is for sensing with the ultrasonic sensor.
First, I designed the circuit using Tinkercad and assigned:
the buzzer to 5
trig to 7
echo to 6
led to 3
the slide switch to 4
I started the code by defining the pin numbers.
Then I added the ultrasonic function to the code.
For the normal mode, the LED and buzzer will be turned on and off every 500 ms.
For the sensor mode, I added the equation to define the distance the ultrasonic reads:
Fast beeping sound (every 500 ms.) when the wall is at distance equal to or more than 30 cm, and less than 70 cm.
Faster beeping sound (every 250 ms.) when the car gets so close to the wall at distance equal to or more than 30 cm, and less than 10 cm.
I used the same connections from TinkerCAD to make the circuit in the real life.
I wrote the Arduino code and I made sure everything was right by clicking "Verify", then uploaded it to the Arduino board.
I used cardboard to make my enclosure. I wanted it to look like an actual garage.
I always had a problem when it comes to coding two modes, but then I took a look at our week 6 activity where we had to write the two modes for the fan and the LED until it all worked well.