The Idea for This week's assignment is to build a smart circuit, mine will be the base of a barking sensor for cars. when it senses obstacle or another car approaching it lights the corresponding led as an alert.
I got Inspired when I heard what the sensor can do and the idea just clicked.
We Used Tinker CAD to simulate The Circuit and its component.
It is easy to use and safer to test our project without risking the component.
We use Arduino Uno as The Brain
We Use Ultrasonic Sensor as The Distance Input.
We use Arduino IDE as Code software.
Components:
Arduino Uno
Ultrasonic Sensor
Wires
LEDs
Breadboard
Power adapter
The Inputs:
Ultrasonic Sensor.
The Output
The LEDs.
Open Tinker CAD.
Select New and Then Choose Circuit.
Select Breadboard small.
Select 3 LEDs Red, Yellow and Green.
Select 3 Resistance of 220 Ohm
Select Arduino Uno Board.
Select Ultrasonic Distance Sensor.
we used the code blocks with the following in mind:
At 15m to 10 cm turn the green LED on and the rest off.
At 10 to 5cm Turn the yellow LED on and the rest off.
Below 5cm Turn the Red LED on and the rest off.
So, the first "If" Is if anything in a distance more than 15 cm don't turn on any LED.
The rest of the conditions were trickier, we had to add to parameters, so we used the and block to determine a range for the activation of certain LED. so, in the second condition we made the green LED Turn only when the distance was 15cm or less but more than 10 cm and the other LEDs Remain off. the same goes for the third condition, turn on the Yellow LED and the rest off when the distance is 10cm or less but more than 5 cm.
The condition was set to turn the Red LED on and the rest off when the distance was 5cm and less.
Connect the (+) of the breadboard with the 5v pin on the Arduino.
Connect the (-) of the breadboard with the ground pin on the Arduino.
Put the 3 LEDs on the breadboard.
Connect the one end of a resistor with the cathode end of the LED and the other with the (-) of the breadboard which is connected to the Arduino.
Connect the anode end of the LED with the digital pins of the Arduino as follows: Red = 2, Yellow = 3, Green = 4.
Connect the Ultrasound distance sensor as follows: Power to the (+) of the breadboard, Ground to the (-) of the breadboard, Trigger to pin 5, Echo to pin 6.
The Challenge was to make the code read value bigger than a number but smaller than another.
I Asked the instructor and gave me a hint. So I used of the "and" function and made it work.
The "and" block is a nesting block works to add 2 conditions together.
Using Code Blocks is a friendly way to code. It should make it easier and more manageable.