- One large plastic pumpkin
- One Raspberry Pi 4 (with peripherals)
- One Arduino starter kit that works with Raspberry Pi
- One hot glue gun
- Ribbon, ideally in holiday theme colors
The items you'll need in the starter kit are one infrared motion sensor, a breadboard, two small LED lights, a ribbon to connect the breadboard to the Raspberry Pi, and cabling to configure all of these pieces together. You can find each of these items online, and I suggest the starter kit for the entertaining things you can do beyond this project.
After receiving my Pi, including the SD card, I went online and followed the Raspberry Pi imager instructions. This allowed for quick installation of the OS onto the SD card. Note: you need the ability to put the SD card in an SD card-reader slot. I have an external attached SD card reader, but some computers have them built in. On your local computer, you also need a VNC viewer.
After installing the OS and running updates, I had some extra steps to get everything to work correctly. To do this, you'll need the following:
- Python 3
- Python3-devel
- Pip
- RPi GPIO (pip install RPi.GPIO)
- A code editor (Thonny is on the Raspberry Pi OS)
Next, set up a VNCviewer, so you can log in when you have the Pi hidden in your pumpkin.
To do this, run the below command, then follow the instructions below.
sudo raspi-config
When this menu pops up, choose Interface Options:
choose VNC and enable it on the pop-up:
You can also use Secure Shell (SSH) for this, but during the troubleshooting phase, I used VNC. When logged into your Raspberry Pi, gather the IP address and use it for SSH and a VNC connection. If you've moved rooms, you can also use your router or WiFi switch to tell you the IP address of the Pi.
Now that everything is installed, you can move on to building your breadboard with lights.
Everyone should try pumpkin bread(board)Many people haven't seen or worked with a breadboard, so I've added pictures of my parts, starting with my base components.
Jess Cherry CC BY-SA 4.0
Jess Cherry CC BY-SA 4.0
These two pieces are put together with the extension shield in the center, as shown.
Jess Cherry CC BY-SA 4.0
The ribbon connects to the pin slot in the Raspberry Pi, making the board a new extension we can code and play with. The ribbon isn't required, it's just makes working with the GPIO pins convenient. If you don't want to purchase a ribbon, you can connect female-to-male jumper cables directly from the pins on the Pi to the breadboard. Here are the components you need:
- Raspberry Pi (version 4 or 3)
- Breadboard
- GPIO expansion ribbon cable
- Jumper cables (x6 male-to-male)
- Resistor 220Ω
- HC-SR501 or any similar proximity sensor (x1)
- LED (x2)
Once you have all of the pieces, you can put everything together. First, take a look at how the pins are defined on the board. This is my personal extension board; the one you have may be different. The pin definitions matter when you get to coding, so keep very good track of your cabling. Below is the schematic of my extension.
As you can see, the schematic has both the defined BCM (Broadcom SOC Channel) GPIO numbering on the physical board and the physical numbering you use within the code to create routines and functions.
Now it's time to connect some cabling. First, start with the sensor. I was provided with cables to connect in my kit, so I'll add pictures as I go. This is the sensor with a power(+) ground(-) and sensor connection to extension board(s).
For the cable colors: power is red, ground is black, and yellow carries the sensor data.
ess Cherry CC BY-SA 4.0
I plug in the cables with power/red to the 5V pin, ground/black to the GRN pin, and sensor/yellow to the GPIO 17 pin, later to be defined as 11 in the code.
ext, it's time to set up the lights. Each LED light has two pins, one shorter than the other. The long side (anode) always lines up with the pin cable, and the shorter (cathode) with the ground and resistor.
Jess Cherry CC BY-SA 4.0
For the first light, I use GPIO18 (pin 12) and GPIO25 for the signal. This is important because the code communicates with these pins. You can change which pin you use, but then you must change the code. Here's a diagram of the end result:
Jess Cherry CC BY-SA 4.0
Now that everything is cabled up, it's time to start working on the code.
How to use a snake to set up a pumpkinIf you've already installed Python 3, you have everything you need to start working through this line by line. In this example, I am using Python 3 with the RPI package. Start with the imported packages, RPI and time from sleep (this helps create the flicker effect described later in the tutorial). I called my Python file senseled.py, but you can name your file whatever you want.
Next, define your two LED pins and sensor pin. Earlier in this post, I provided these pin numbers while wiring the card, so you can see those exact numbers below.
Since you have two lights to set up to flicker together in this example, I also created a defined array to use later:
leds = [ledPin1, ledPin2]
Next, define the setup of the board and pins using the RPi.GPIO package. To do this, set the mode on the board. I chose to use the physical numbering system in my setup, but you can use the BCM if you prefer. Remember that you can never use both. Here's an example of each:
For this example, use the pin numbering in my setup. Set the two pins to output mode, which means all commands output to the lights. Then, set the sensor to input mode so that as the sensor sees movement, it inputs the data to the board to output the lights. This is what these definitions look like:
Now that the board and pins are defined, you can put together your main function. For this, I use the array in a for
loop, then an if statement based on the sensor input. If you are unfamiliar with these functions, you can check out this
If the sensor receives input, the LED output is high (powered on) for.03 seconds, then low (powered off) while printing the message led turned on.
If the sensor receives no input, the LEDs are powered down while printing the message led turned off
.
While you can mathematically choose the brightness level, I found it easier to set the sleep timer between powering on and powering off. I set this after many tests of the amount of time needed to create a flickering candle effect.
Finally, you need some clean up to release your resources when the program is ended:
Now that everything has been defined to run, you can run your code. Start the program, run the setup, try your main, and if a KeyboardInterrupt is received, destroy and clean everything up.
Now that you've created your program, the final result should look like this:
To start, I had a very large plastic pumpkin gifted by our family to my husband and me.
Finally, I put the Pi and extension card in the pumpkin and cabeled the power through the back.
Jess Cherry CC BY-SA 4.0
With everything cabled, I was ready to VNC into my Pi and turn on the Python, then wait for something to move to test it out.
Comments