Have you been naughty or nice this year? This is usually a question that torments children and they have to wait until Christmas morning to find the answer. With our state of the art Sant-a-Scanner, we can say with scientific certainty if you are on the naughty or nice list in under a minute! I was really impressed with the work we did. While I helped, my high school students did most of the wiring and coding themselves (Which will be obvious if you look at the code.)
- A Raspberry Pi 3B+ with a power supply, and SD card with a loaded operating system
- Ultrasonic Distance Sensor (HC-SR04) with a 3D printed case
- 4 meter NeoPixel strip
- 5 Volt Power Supply for the NeoPixels
- Silicon wire kit
You can download the code on my GitHub.
We started by installing the Adafruit NeoPixel and Blinka libraries from the terminal. You may need to install pip3, but the terminal will show you the command you need to download pip if it fails.
sudo pip3 install rpi_ws281x adafruit-circuitpython-neopixel
sudo python3 -m pip install --force-reinstall adafruit-blinka
Then we followed the tutorial here in order to get the distance sensor working. We used the same pins and wiring as they did in the picture.
We also followed this wiring diagram from Adafruit with the external power supply and the diode to make sure we didn’t damage the LEDs. We read the documentation from Adafruit to see how to program the LEDs on the led strip. It is well done and easy to follow. The only problem that we ran in to was the pi couldn’t find the packages we installed if we ran sudo python3 christmas.py, but worked if we added -E to the command.
#This failed to load the adafruit libraries
sudo python3 christmas.py
#This worked
sudo -E python3 christmas.py
We then combined the code from the two projects so if you were within 40 centimeters, the lights would trigger a light sequence.
To finalize the project, we made it so when the sensor is waiting, the lights switch between green and red. When someone gets close, we cycle through white lights, then pulse red or green randomly.
Once students had things wired correctly, they soldered the wires to the distance sensor, and we enclosed it in the 3D printed case and attached it to the door with a magnet. This was their first time soldering, and I think they did a nice job.
We then ran the program over an ssh connection so we didn’t have to get hook a monitor up to the pi everytime we wanted to start the program.
To improve this project, I would like to refactor the code, and learn about chrono tasks so the program would start automatically at the start of the school day.
how could you insult us for only learning code for less the two years of learning. the “(Which will be obvious if you look at the code.)” comment was a but rude. even though understandable, you can at least make it nicer than that.
Lol! Not meant to be an insult. I am really proud of the work you did.