Tinkering Lights + Distance Sensor

by 753755 in Circuits > Arduino

65 Views, 0 Favorites, 0 Comments

Tinkering Lights + Distance Sensor

coverphoto2.jpg
Sizzling Uusam-Gogo (1).png

In this circuit, the LEDs light up sequentially, and their speed is influenced by the distance sensor. The closer an object is to the sensor, the slower the LEDs light up. Conversely, the further away the object, the faster the LEDs illuminate.


Feel free to download the video below for a quick demonstration of how the circuit operates. I have also provided a schematic.

Downloads

Supplies

engineeringfinal.supplies.jpg
  • 1kΩ resistor x5
  • Red LEDs x5 
  • Breadboard x1
  • Jumper wires
  • Distance sensor x1
  • Arduino x1
  • Wire cutter/stripper
  • Power source

Connecting LEDs

ins1.jpg

Connect the LEDs and resistors in series, ensuring each LED is paired with the appropriate (1KΩ) resistor to manage current. Make sure the resistors are connected to the negative terminal. To distribute power efficiently, connect the positive (+) terminals to the positive other (+) terminals, and vice versa with the negative (-). This configuration ensures even power distribution across all components.

Connecting LEDs

ins3.jpg

Connect the wires from the LEDs to the Arduino, ensuring each LED is connected to a specific pin that can be programmed in subsequent steps. This setup allows for precise control and coding of the LED's behavior.

Connecting Distance Sensor

ins2.jpg

Position the distance sensor in a suitable location. Give it enough space so we can add wiring.

Connecting Echo, Trig, Power, GND

ins5.jpg

Attach red wires to VCC for power and black wires to GND for ground. We use specific colors for organization, though it doesn't matter. Use suitable wires to connect the trig and echo pins to the Arduino. I personally connected to pins 8 and 9, if you choose to do differently, you MUST change these values in the code which will be given.

Connecting Power and Ground

ins4.jpg

Insert red and black wires into the power and ground rails of the breadboard. These will be used to supply power to the breadboard from the Arduino. The specific side on which these wires are placed does not affect power distribution, thanks to our previously established connections between terminals.

Add Code

Download and paste this code into the Arduino IDE software! It enables the distance sensor to function, controls the behavior of the LEDs, and adjusts their speed. I've personally connected the TRIG pin to pin 9 on the Arduino and the ECHO pin to pin 8 on the Arduino. The specific LED pin connections are flexible and do not affect the code or circuit performance in any way, so connect them to any #s. Personally, I did 3-7.

Working Circuit!

ins6.jpg

Have fun with your working circuit! The end result should make the LEDs impacted by the distance sensor, the timer gets larger if the distance is shorter.

The timer is set to 350 when the distance is less than 5 cm, 220 for distances between 5 and 8 cm, 150 for distances between 8 and 12 cm, 20 for distances between 12 and 15 cm, and 100 for distances of 15 cm or more. Higher timer values correspond to slower LED timing. Thus, LEDs slow down when the distance is less than 5 cm and speed up as the distance increases.

Of course, if you want the LEDs to blink faster when the distance is shorter, it's quite easy to change the values of the timer in the code attached in the previous step.