Represent distance by colors
If the object is 20 cm away or less the RGB LED goes RED
If the object is more than 20 cm away, the RGB goes Green
Software:
TinkerCAD
Components:
1- RGB LED
2- Breadboard
3- Arduino Uno
4- Jumper wires
5- Ultrasonic sensor
A) Wiring
1- Attach RGB LED on Breadboard
2- Wire the RGB with the Arduino using 220 ohm resistors
RED >> pin 11
BLUE >> pin 10
Green >> pin 9
Cathode >> GND
3- Wire the ultrasonic sesnor
Trigger >> pin 13
Echo >> pin 12
VCC >> 5V
GND >> GND
4- Attach the Arduino GND to the -ve of the breadboard
5- Attach the Arduino 5V to the +ve of the breadboard
B) Coding
1- Read ultrasonic sensor on Trigger pin 13 & Echo pin 12
2- If the distance is less than or equal 20 cm, set the RGB LED red
3- Else: the RGB LED will be green (the distance is more than 20)
Schematic Diagram
A) Circuit wiring
1- Attach RGB LED on Breadboard
2- Wire the RGB with the Arduino using 220 ohm resistors
RED >> pin 11
BLUE >> pin 10
Green >> pin 9
Cathode >> GND
3- Wire the ultrasonic sesnor
Trigger >> pin 13
Echo >> pin 12
VCC >> 5V
GND >> GND
4- Attach the Arduino GND to the -ve of the breadboard
5- Attach the Arduino 5V to the +ve of the breadboard
6- Copy text code from Tinkercad to Arduino IDE
7- Upload the code
Didn't get stuck
Sensing using ultrasonic sensor
Circuits ! <3