Object Activated Tree Light Display
by just_another_person in Circuits > Microcontrollers
573 Views, 11 Favorites, 0 Comments
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:
- 1x breadboard
- 1x Raspberry Pi Pico
- 5x LEDs
- 5x 220 ohm resistors
- 1x Ultrasonic Sensor
- ~6x male-male jumper wires
- 4 male-female jumper wires
- 4x 1.5 volt batteries + battery pack
Construction:
- tree design printout (example template linked below)
- cardboard
- exacto knife/scissors
- hot glue gun
Downloads
Circuit-- LEDs
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
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
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.
Assembling Tree
Using hot glue, attach the tree printout to a piece of cardboard (reference above image for proper positioning)
Insert Circuit Into Tree
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
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!!