Halloween Pi

If you’re a reader of the MagPi magazine then you may have seen my Halloween Pi project in the October issue…

If not, then have a quick wander over to their site: http://www.themagpi.com/ and have a look!

Octobers magazine featured a little Halloween project I did – sadly, due to a few factors beyond my control – some family illness necessitating a round trip of some 5000 miles to Tenerife and back, and the seasonal availability (or rather lack or it!) meaning I was little pushed for time and unable to get a real pumpkin before the publication date, I felt I didn’t give it all it was worth, so I’m  re-doing it here for my own archival use and to maybe add a few more things into it.

The idea was to put some flashing LEDs inside a pumpkin along with a PIR sensor  so that when triggered by movement, the LEDs would flash some colourful patterns.

Because I couldn’t get a real one on-time, my pumpkin was built in a plastic bucket… Not that bad really, but could have been better – it was in the shape of a Halloween pumpkin though!


The Halloween Pi

The Halloween Pi

Inside the "pumpkin"

Inside the “pumpkin”

The brainbox of it all

The brainbox of it all

Rather than solder, I used some heat-shrink to hold the wires of the LED to the female to male patch leads. The little board on-top of the Pi is the Dtronixs Minipiio board and it’s all sitting inside an Adafruit case.

The rest of the hardware if fairly straightforward – They are common cathode RGB LEDs and the PIR sensor.


The Dtronixs board isn’t available – yet, but I understand “real soon now”…

If you’re outside the UK/Europe, then I strongly suggest looking at the Adafruit site for these bits & pieces, and more, but most hobby electronics shops should have everything you need.

Note that the resistors are a little lower than I’d normally use – these RGB LEDs are quite bright and need a slightly higher drive requirement than the common red/green/yellow ones to be effective. (and even here, those are the typical values for a 5v supply – the LED will be slightly dimmer powered from the Pi’s 3.3v, but you really won’t notice it)

Wiring it up

No surprises here – GPIO’s 0, 1 and 2 (wiringPi numbering convention) to the Red, Green and Blue of the first LED, 3, 4 and 5 to the RGB of the 2nd LED, and pin 7 to the input from the PIR sensor. A Fritzing diagram is below:

Breadboard layout

The first LED is on the right in this diagram. (Not that it really matters!)


I wanted to use the software PWM library in wiringPi to light the LEDs up and make some interesting colours/patterns, so that meant the software needed to be written in C (at least initially)

If you don’t already have the  wiringPi library and gpio utility installed, then:

git clone git://git.drogon.net/wiringPi
cd wiringPi

and that will get the code and install it for you.

Get the Halloween software by a similar method:

git clone git://git.drogon.net/halloweenPi
cd halloween

Before running the software, you can test the LEDs and sensor with the following commands:

for led in 0 1 2 3 4 5; do gpio mode $led out ; done
gpio mode 7 in
gpio write 0 1   # 1st Red LED ought to be on
gpio write 0 0 ; gpio write 1 1 # Red off, Green on
gpio write 1 0 ; gpio write 2 1 # Green off, Blue on

You can do the same for the 2nd LED using numbers 3, 4 and 5 respectively.

If you’ve wired the colours up wrongly, then it’s easy to change them and use the gpio command to check.

The PIR sensor works by firstly sampling the surrounding heat “signature” for a few seconds, then waiting for it to change. So to test it, you need to be very still… and keep on typing the following command: (Use the up-arrow key!)

gpio read 7

It should read 0 when not triggered and read 1 when it is triggered.

At this point, assuming all is OK, you can run the program:

sudo ./halloween

and see what happens. Remember that it needs 5 seconds of stillness to register, then you can move and see what happens.

If you want to change the patterns then you need to look at the ledPatterns.c file. You can use that as a template, or modify the code already there – whatever you do, have fun!


If you are carving a real pumpkin, then here is a suggestion or 2 – get a black marker pen and draw a zig-zag round the top, also decide where the back is and draw a short vertical line through the zig-zag – that way, you’ll know exactly where the top goes when you come to putting it back on again!

Scoop out the flesh, but don’t throw it away! You can use it to make some tasty roast pumpkin soup as follows:

Put the flesh into an ovenproof dish with a glug of olive oil and a sprinkling of salt and roast in a hot oven – 220C or Gas mark 7 for about half an hour or until it starts to take a little colour.

Remove from the oven and transfer into a pan. Add in half a vegetable stock cube (or a whole one if you carved a huge pumpkin!)  and a small tub of single cream. (again, maybe a a large pot if it’s a huge pumpkin!)

Mash or blitz with one of those hand-held mixer thing and return to the heat to thoroughly warm through – add a little milk or water if it’s a bit thick, and serve immediately with some fresh crusty bread.

For a little variation and more texture, add in a drained tin of sweetcorn and to make it a little warmer, try some smoked paprika sprinkled on-top when serving.

Some Halloween information

Halloween is an old festival or celebration, or ritual which has been adopted by many cultures and religions over the world. It’s roots may originate in acknowledging the autumn is ending and we should take stock for winter, or to remember the passing of souls, or a time to hide from ghouls or the souls of enemies (hence the masks and lanterns!)  For us, it’ll be a bit of fun, some hot soup and a fancy Raspberry Pi powered lantern!

In Scotland (Where I’m from), you should traditionally use a large yellow neep and make a “tumshie heed”. Some English counties may traditionally use a mangelwurzel and if you can get of suitable size that may be appropriate.

The modern trandition of “trick or treat” may originate from an early Christian practice of baking small round cakes for All Saints Day (November 1st)


Halloween Pi — 9 Comments

  1. Hi, I cloned wiringPi ok, but have error for halloween:

    afustini@lappy486:~/tmp$ git clone git://git.drogon.net/halloween
    Cloning into ‘halloween’…
    fatal: The remote end hung up unexpectedly

    Am I doing something wrong?

    • No – I’ve made a silly typo: IT should be:

      git clone git://git.drogon.net/halloweenPi

      I’ve fixed the text now, but give that a go.



  2. Hi
    I have wired up the Halloween project and the LEDs work. However I am struggling with the PIR sensor.
    The diagram above has the PIR middle pin connected to GPIO pin 7, but the MagPi diagram has it connected to GPIO pin 3.
    Plus the test command specifies 7.
    Which pin is correct and is the test command 7 correct?
    All help gratefully received

    • Hi,

      Unfortunately I had some issues with some of the PIR modules I tested – some were not very reliable )-: I bought several, but they seem to be 2 types – one type has 2 tiny little adjuster potentiometers on it, the other type doesn’t. It’s the type with the adjusters that are the more reliable – however they need wiring up slightly differently to the other type.

      So if you have the type with the adjusters on it, then look at my web article on it for the breadboard manual – it’s connected into GPIO pin 4/wiringPi pin 7 rather than GPIO pin 3 (1 on rev 1 boards).

      The difference is the output from the sensor – the ones without the adjuster have open collector outptus, so need a pull-up to 3.3v – which the I2C lines on the Pi gives (GPIO’s 0/1 or 2/3 depending on board revision), and the ones with the adjuster have a 3.3v logic level output, so don’t need the pull-ups.

      So plug it into GPIO 4/wiringPi pin 7, then run the tests suggested in the article on this site and let me know how you get on.


  3. Gordon
    Still struggling, can you confirm which pin is which on the PIR in your diagram above.
    Apologies from a novice


    • It’s wiringPi pin number 7. (or BCM_GPIO number 4)

      If you check the fritzing diagram – follow the yellow wire – it’s the 4th in from the right – P1 is 3.3v, then the 2 I2C pins, then the pin you want.