This week I had a fun Idea, it's an RGB led that emits different lights according to a distance given from an ultrasonic sensor.
A distance less than 10cm gives a green light, between 10 and 20 cm yellow light, between 20 and 30 cm red light (which is traffic light if your noticed :-) ) and more than 30 cm gives white light.
I used Tinkercad to simulate the electronic circuit using code blocks.
Using this method is very easy and it allow me to take the Arduino code without typing it which is very cool.
Also this way of simulating the electronic circuit allow me to discover any problems in simulation which is better to prevent the burning of any component in real life.
I used ultrasonic sensor to detect the distance, RGB led to display colors, 3 1 Kilo ohm resistors for each color in the RGB led and jumpers to gather the circuit all together.
The code is all based on IF functions, the first one ask if the distance is smaller than 10cm if yes the led emits green, if no another IF functions asks if the distance is smaller than 20, if yes the led emits yellow (which is red + green), if no another IF function is added that asks if the distance is smaller than 30, if yes the led emits red and if no then the distance has to be greater than 30 then the led emits white color (which is red + green + blue)
I used the small breadboard as it consume less space than the large one.I did the exact same connection the one on Tinkercad.
I used the Ultrasonic sensor in the kit, but the problem was it had 4 pins and the one on Tinkercad had only 3, but I realized that there's an echo and trigger pin and on tinker cad there was only one that do both functions.
so I copied the code on Tinkercad to Arduino program and changed the (readUltrasonicDistance(7, 7)) to (readUltrasonicDistance(6, 7))Here I told the Arduino that the Trigger pin is on 6 and echo pin is on 7.
I didn't know which one was first the trigger or echo but I got it by luck at the beginning, but after that I realized that in tinkercad in code blocks, he asked first about the trigger then the echo (that's when it made sense).
Electronic circuit
During the week sessions we had a lot of conversations about each others projects and had a lot of fun benefiting each others.
Also I had some trouble with the exercises during the week and I got help from my friends in the diploma and the Instructors.
I did some research and asked my friends in the diploma to know the exact resistor that should be connected in series with the RGB led.
I didn't know about the trigger and echo pins in the real Ultrasonic sensor, but at the lab the instructors gave us some help to understand more about them and we had exercise with the Ultrasonic sensor.
The circuit didn't work at the beginning as I did something wrong in the connection but I realized it and fixed it right away
It was the first time to use Code blocks which I think is the first step to get to know more about the Arduino code and the logic behind it.
It's going to be very beneficial in the final project as it's a very good training for making a smart device for the first time.
Making a Simple smart device for the first time using Arduino code, it was a great feeling to see firstly the device working in the simulation in tinkercad after some trouble shooting, and even greater when It finally worked in reality.
Title of Media