Project tutorial
Smart Halloween Pumpkin Lamp

Smart Halloween Pumpkin Lamp © GPL3+

A 3D-Printed Halloween Pumpkin Lamp that changes color and hums a halloween song when it hears a noise around.

  • 2,481 views
  • 0 comments
  • 9 respects

Components and supplies

Apps and online services

About this project

https://www.youtube.com/embed/OOJNGcGnJZ8?feature=oembed

Halloween is coming up soon and probably you need something to impress your friends.

This is the project for you: a 3D-Printed Halloween Pumpkin Lamp that changes color and hums a halloween song when it hears a noise around.

The design is very simple, as most of the dirty job is done for you by Zerynth, the programming tool, and by Zerynth Shield, the multi-sensor shield compatible with Arduino-like and Particle boards.

Step 1: Required Material

The project requires few elements:

  • Arduino DUE or ST Nucleo F401RE or Particle Photon or Mikroe Flip&Click. No matter which board you use, Zerynth is multi-board compatible! You can find all the Supported Boards details in the dedicated section of the Zerynth documentation.
  • the Zerynth Shield (available here: http://www.zerynth.com/zerynth-shield/). A ready to use multi-sensors board that adds smart functions to your everyday life objects. It is a multiboard shield that presents a set of sensors and actuators, including sensors for touch detection, infrared LED, microphone, light sensor and temperature sensor.

Step 2: Assembling

Nothing could be easier.

With a set of sensors on board and all the most used communication ports ready to be plugged, the Zerynth Shield allows makers, designers and IoT professionals to easily develop their smart objects, without care about wiring and soldering becoming crazy with funky circuits.

Just piggyback the Zerynth Shield onto your Arduino and and take full advantage of the microphone and the buzzer.

In the Zerynth Shield there's also included a port dedicated to the connection of Adafruit Neopixel LEDs strips. Port pins are: GND; Vin; LED control pin.

Put all the boards and the LEDs into the 3D-Printed Pumpkin Lamp and you're done!

Step 3: Programming

Using Zerynth is very easy!

  • copy the code that you can find in this hackster
  • upload the code on your board and you're done!

The code is very simple and has a lot of comments. For any questions or suggestions please feel free to post on the Zerynth community forums: http://community.zerynth.com/

Step 4: Enjoy it!

Did you like it? Let’s get hardcore!

Perhaps you would like to remotely control your Pumpkin lamp? With Zerynth you can easily do this too!

Take a look at the image above: a lamp controlled via mobile for IoT ambient light. The related tutorial is almost ready... stay tuned!

Luigi F. Cerfeda (@L_F_Cerfeda) - Zerynth team

Code

Smart Halloween Pumpkin Lamp - main.pyPython
################################################################################
# Smart Halloween Pumpkin Lamp
#
# Created by Zerynth Team 2015 CC
# Author: L. Rizzello
################################################################################
 
import streams
from community.floyd.rtttl import rtttl
import threading
# import toishield module
from toishield import toishield
# import neopixel module
from neopixel import ledstrips as neo
 
streams.serial()
 
# set detection enabled and pumpkin inactive by default
toishield.microphone.detectionEnabled = True
toishield.microphone.activePumpkin = False
# set some variable for sound detection
toishield.microphone.staticMin = 4096
toishield.microphone.staticMax = -4096
toishield.microphone.resetMinMaxCounter = 0
 
# declare leds to blink!
leds = neo.ledstrip(toishield.led_pin, 16)
leds.setall(0,0,0)
leds.on()
 
# semaphore initialized to 0 -> red: if a thread tries to acquire the semaphore
# it blocks if the semaphore has not been turned 'green' (released)
semaphore = threading.Semaphore(0)
 
# define a RTTTL Halloween melody to be played by passing it the RTTTL string.
# find more songs at http://ez4mobile.com/nokiatone/rtttf.htm and many other websites
hsong = rtttl.tune('Halloween:d=4,o=5,b=180:8d6,8g,8g,8d6,8g,8g,8d6,8g,8d#6,8g,8d6,8g,8g,8d6,8g,8g,8d6,8g,8d#6,8g,8c#6,8f#,8f#,8c#6,8f#,8f#,8c#6,8f#,8d6,8f#,8c#6,8f#,8f#,8c#6,8f#,8f#,8c#6,8f#,8d6,8f#')
 
# If you use Particle Photon uncomment the following line and short-circuit the Buzzer and Aux2 pins
# toishield.buzzer_pin=D9.PWM
 
def blink():
    # blink while the pumpkin is active
    while toishield.microphone.activePumpkin:
        leds.setall(255,0,0)
        leds.on()
        sleep(500)
        leds.setall(255,140,0)
        leds.on()
        sleep(500)
    leds.setall(0,0,0)
    leds.on()
    semaphore.release()

def playHalloween():
    # plays halloween song two times, then disables pumpkin, but also waits
    # at the semaphore to synchronize with blinking thread
    for i in range(2):
        hsong.play(toishield.buzzer_pin)
    toishield.microphone.activePumpkin = False
    semaphore.acquire()
    sleep(1000)
    print("enabled again")
    toishield.microphone.detectionEnabled = True

def scare():
    # this is called when the sound exceeds the threshold, waits one second
    # and starts scaring!
    sleep(1000)
    thread(playHalloween)
    thread(blink)

# define a function that takes a sensor object as parameter and checks the
# maximum peak to peak extension of the signal in a preset window
# look at this
# example for details on how the sound detector works
def detectSound(obj):
    if (obj.resetMinMaxCounter == obj._observationWindowN):
        extension = obj.staticMax - obj.staticMin
        if (extension > 1000):
            if obj.detectionEnabled:
                obj.detectionEnabled = False
                obj.activePumpkin = True
                thread(scare)
        obj.staticMax, obj.staticMin = -4096, 4096
        obj.resetMinMaxCounter = 0
    else:
        c = obj.currentSample()
        if (c > obj.staticMax):
            obj.staticMax = c
        elif (c < obj.staticMin):
            obj.staticMin = c
        obj.resetMinMaxCounter += 1

# set 'detectSound' as the function to be applied to the object at every sampling step    
toishield.microphone.doEverySample(detectSound)
# start sampling at 1 millisecond (1 kHZ) with a window length of 50 so that
# the lowest detectable frequency is 20 Hz
toishield.microphone.startSampling(1,50,"raw")

Schematics

Shield setup
Just piggyback the Zerynth Shield onto your Arduino and and take full advantage of the microphone and the buzzer.

Put all the boards and the LEDs into the 3D-Printed Pumpkin Lamp and you're done!
If15 4

Comments

Similar projects you might like

IoT Ambient Light: Zerynth Lamp

Project tutorial by Luigi Francesco Cerfeda

  • 7,001 views
  • 0 comments
  • 30 respects

Stranger Blinks: Send Messages from the Upside-Down

Project tutorial by Luigi Francesco Cerfeda

  • 3,424 views
  • 1 comment
  • 10 respects

Smart Home - Smart Rules using ARTIK Cloud & Photon

Project tutorial by Raghavendra Ponuganti

  • 3,864 views
  • 2 comments
  • 12 respects

Wifi Death Lamp

Project showcase by Jhn S

  • 29,029 views
  • 3 comments
  • 82 respects

LUMOS: Smart Lamp for Better Sleep

Project tutorial by Jonathan Pereira

  • 5,644 views
  • 1 comment
  • 26 respects
Add projectSign up / Login