Object Activated Tree Light Display

by just_another_person in Circuits > Microcontrollers

570 Views, 11 Favorites, 0 Comments

Object Activated Tree Light Display

Screenshot 2024-05-06 214313.png
Object Activated Tree Light Display

This project uses ultrasonic sensors and LEDs to create a light display that is activated when an object is placed to the side of it. It's a pretty beginner-friendly build for people starting off with microcontrollers, especially if you want to make a quick showcase display. Using this tutorial, you can learn the basics of making the project, although it really is open to interpretation with the colors of LEDs you use and the light sequences.

Supplies

Circuit:

Construction:

  • tree design printout (example template linked below)
  • cardboard
  • exacto knife/scissors
  • hot glue gun

Circuit-- LEDs

IMG_7401.jpeg
Screenshot 2024-05-04 203233.png

For the LEDs, connect the positive end of the LED to the corresponding GPIO pin (refer to the code & pinout chart above-- I used GPIO 0, 8, 11, 13, and 15), and the negative end to a 220 ohm resistor, and through that to a ground pin. Reference the proper connections/GPIO pinouts using the Pico diagram above.

Circuit-- Ultrasonic

IMG_7403.jpeg

Add the Ultrasonic to the circuit, with the following connections:

  • VCC- Vbus (pin 40)
  • Trig- GPIO pin (for this code, I used pin 4)
  • Echo- GPIO pin (I used pin 5)
  • Ground- any ground pin

Code

code1tree.png
code2tree.png

The link the code is below, but here's a brief explanation of it (reference the annotated numbers in the image above):

1) Imports:

time & sleep-- sleep is used to delay the execution of part of the program for a given amount of seconds

Pin, PWM (Pulse Width Modulation)-- useful for controlling the amount of power delivered the output. Since we're also importing Pin, it means we refer to the pins while setting up by their GPIO number rather than pin (board) number.

math-- to preform basic math functions in the code

2) LED & Ultrasonic connections: Refer to the GPIO connections made in the steps above, and modify the outputs for any changed pins.

3) Distance Function: The ultrasonic sensor sends an ultrasonic wave, which is then reflected back by nearby objects. This function times how long it takes for the sensor to send and receive the waves (lines 31 and 33), and then uses the distance formula (distance=speed/time-- line 36) to find how far the waves went. It divides that distance by two to only measure the distance the wave takes reaching the object.

4) While True loop: if the distance from an object is less than 70 centimeters away, then it triggers the LEDs to light up. Using LED.on, sleep commands, and LED. off, you can program your own custom light sequence.


Code: https://github.com/just-another-person1/Projects-/blob/main/Object%20Activated%20Tree%20Light%20Display

Assembling Tree

IMG_7404.jpeg

Using hot glue, attach the tree printout to a piece of cardboard (reference above image for proper positioning)

Insert Circuit Into Tree

IMG_7407.jpeg
IMG_7406.jpeg

Cut a hole for each LED (5 total), around different areas in the tree (they should be around the middle area so it's easier to enclose the project later on). Hot glue the breadboard onto the center of the tree.

Battery and Ultrasonic Holder

IMG_7412.jpeg
IMG_7408.jpeg

Add three supports for the bottom of the tree, with one of them having a hole for the ultrasonic sensor, and then hot glue them onto the tree. For the battery pack, connect the positive end to the Vbus, and the negative end to ground. Then, attach it to the base of the tree. For the cover, add two cardboard supports on either side of the circuit, then glue a final piece of cardboard on top (pictured above).

Now, put an object in front of the sensor to enjoy your light show!!