This week's assignment is to Build and Program a smart circuit using an Arduino UNO which reads a signal from an input component to control an action component using Code Blocks.
I chose a smart circuit that can work as a bird alarm so that it can alert me if any birds are close to my plant and have some LEDs that flash gradually according to the bird's distance from the plants:
1- green LED= birds are near but it`s still a safe distance
2- yellow LED:= birds are close but we are not in the dangerous distance
3- red LED with buzzer= they are in.
as the birds get afraid of any tiny action or change(flash or sound) and if they come too close a buzzer will be turned on, at the same time it can be a parking sensor device.
I used TINKERCAD software to simulate my circuit before implementing it.
First, I chose the output & input components I wanted, to help me implement my idea correctly.
Input component
Ultrasonic sensor
Out components
LEDs & Buzzer
How my circuit is working
I programmed the sensor to read different distances with different outputs from each distance.
The first one is when a body is 30 or more cm. Apart, The green LED should light up.
The second one is when a body is < 30 > 20 cm. The yellow LED should light up. other than that the green & yellow are turned off.
The third one is when a body is < 20cm. the red LED & the buzzer are ON other than that all the components are OFF.
Connections
sensor: VCC ➡️ 5V (Arduino)
Trig ➡️ ~9
Echo➡️ ~10
GND ➡️ -ve rail (breadboard)
{-ve rail on breadboard ➡️ Arduino GND}
Buzzer: -ve ➡️ -ve rail (Breadboard)
+ve ➡️ ~8 (Arduino)
3 LEDs & 3 Resistors:
-ve leg ➡️ -ve rail
+ve leg ➡️ one resistor side, and the other side with Arduino
green ➡️ ~11, Yellow ➡️ ~12, Red ➡️ ~13
Circuit Simulation
Written Code
Code Blocks
I wanted to make a range for the ultrasonic sensor to read it and not disturb so I used the Math blocks the (>,<,=)block set my first distance then I used the Read Ultrasonic sensor block.
Then I chose the IF\ ELSE condition from the control blocks to set my condition which translated into:
if the sensor reads > 30 cm. the green LED will light up, I made this equation by using the Math blocks.
If the sensor reads < 30 > 20 cm. the Yellow LED will light up.
If the sensor reads < 20cmThe red LED will light up & the buzzer will be on.
To make the Green LED light up only I set its pin which is 11 on the Arduino to be high only in this condition if this condition is not fulfilled (ELSE) it will be LOW and it will read the second condition (put the second IF in the first ELSE) which is Yellow LED light up when its pin which is 12 on the Arduino is high ELSE: all the LEDs and buzzer pins are LOW and it will read the third condition (put the third IF in the Second ELSE which is the buzzer & Red LED pins are high then they will be on ELSE all the pins are LOW.
Connected the actual components as the TINKERCAD diagram.
Used the 5V adapter as it is suitable for the sensor range.
measured the distances needed and labeled sticky notes to make sure of the distances.
The Device is functional
Components Mounting
My challenge during this assignment was that the circuit was working on Tinkercad and when I connected it physically it didn`t work so, my instructor suggested another way to write my block codes that would be more accurate and it worked.
My challenge during this assignment was that the circuit was working on Tinkercad and when I connected it physically it didn`t work so, my instructor suggested another way to write my block codes that would be more accurate and it worked.
Old Code Blocks
New Code Block