Ultrasonic Security System
The 6th-week assignment of the Maker Diploma is about making things get smart by using Arduino and code blocks that translate into Arduino C programming language to perform a specific command or function. The required is building and programming a smart circuit using an Arduino UNO to read a signal from an input component and control an action component using code blocks.
I looked for cool ideas to build the smart circuit and I found a tutorial on Arduino Project Hub about an "Ultrasonic Security System" to create a little security device using an Arduino. Since I'll be using an Ultrasonic sensor and a Piezo buzzer in my final project, I decided to proceed with this idea.ย
I used Tinkercad to design, simulate, and program the security system's smart circuit with code blocks to make sure it was functional before being prototyped on an actual breadboard.ย
Then, I used Arduino IDE to view the Arduino C code and upload it to the Arduino board.
Finally, I used the following components and materials to build my actual circuit and wire it:
Breadboard
Jumper wires
Arduino UNO
Ultrasonic sensor
Piezo buzzer
Red, yellow, and green LEDs
220โฆ resistors
Arduino USB cable
I started by designing and simulating the smart circuit for the Ultrasonic security system using Tinkercad. My goal was to use an Arduino UNO board to control the input and output as follows:ย
Input: Ultrasonic sensor to measure the distance to an object using ultrasonic sound wavesย
Output: Piezo buzzer and red, yellow, and green LEDs to make a sound and emit light
Then, I started connecting my smart circuit and I used the following pins on the Arduino:
5V pin: on the Arduino to the positive channel of the breadboard
GND pin: on the Arduino to the negative channel of the breadboard
Pin 3: Echo Ultrasonic Sensor
Pin 2: Trig Ultrasonic Sensor
Pin 9: Buzzer
Pin 4: Red LED
Pin 5: Yellow LED
Pin 6: Green LED
The wires connected to the LEDs are connected in line with the positive side of each LED, while the negative side of the LEDs is connected to the negative channel of the breadboard using 220โฆ resistors.ย
After that, I started working on the code blocks to build the code that would be uploaded to the Arduino board. The idea of the security system is that when the Ultrasonic sensor reads a distance from an object approaching, the following actions will happen:
At 30 cm, the green LED will emit light
At 20 cm, the yellow LED will emit light
At 10 cm, the red LED will emit light and the buzzer will make an alarming sound.
Finally, I started the simulation to make sure the smart circuit was functional and I copied the code text to Arduino IDE to upload it to the Arduino board.
I started implementing and breadboarding the physical smart circuit with an Arduino board and components. I wired the components together following my Tinkercad design. I wired the Arduino 5V pin to the positive channel of the breadboard and the GND to the negative channel. Then, I wired the Ultrasonic sensor GND, VCC, Echo, and Trig pins. After that, I wired the Buzzer to Arduino pin 9 (positive) and the breadboard negative channel using 220โฆ resistor. Finally, I connected the LEDs to the Arduino pins 4,5,6 in line with the positive side of each LED, while the negative side of the LEDs is connected to the negative channel of the breadboard using 220โฆ resistors.ย
Once the wiring for the smart circuit was complete, I connected the Arduino board to my laptop and uploaded the code using Arduino IDE. It worked perfectly and was fully functional.
It took me a while to understand Arduino's different pins and how to use code blocks to program it. I faced an issue while working on the assignment related to the Piezo buzzer wiring and code. The tutorial that I followed from Arduino Project Hub wired the buzzer to pin 7 and was set to 1000. I couldn't figure out how to build code blocks for it, and there were several failed attempts. Then, I thought I should go back to the week's videos about the buzzer and I understood that a buzzer is an analog output. So I changed it to pin 9 and dragged the code block output set pin (9) to a value (1000). After that, it worked perfectly with the red LED.