Fire Breathing Arduino Pumpkin With IR Remote Control

Oct 29, 2015

 

A small change to another fire-breathing Arduino pumpkin replaces a proximity sensor with an small IR remote control.

 

When we searched for Halloween Arduino projects the Fire Breathing Jack-O-Lantern of Death from Rick Osgood got my kids more excited than anything else. It also wasn't very complicated or expensive. Video on is available at the previous link, and the Arduino code is available here.

The only issue was the proximity sensor – the idea that you had to get close to the sensor to see the effect was a problem. Rick's code elegantly handles this, his pumpkin won't fire if anything is too close to the proximity sensor, but that wasn't going to be enough. We would have to locate the pumpkin where people couldn't get close to it, which meant we would need another way of firing it.

 

Wiring

The wiring is very well documented in the video above – nothing to add there. It's worth noting that when connected to six AA batteries the sprayer did not seem to get enough power to activate. It sounded like it was trying, but not quite making it. Connecting to a larger power source (in one case a laptop, another case an external phone battery – both connected by USB) always fixed the problem.

 

Code

We started with this slight modified version of the Sunfounder code for their Infrared Receiver experiment. Please note that this requires the IRemote.h library, available on GitHub, to be installed.

 

#include <IRremote.h>
 
const int irReceiverPin = 7;
const int ledPin = 13;
 
IRrecv irrecv(irReceiverPin);
decode_results results;
 
void setup()
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn();
}
 
void loop()
{
  if (irrecv.decode(&results)) {
    Serial.print("irCode: ");
    Serial.print(results.value, HEX);
    Serial.print(", bits: ");
    Serial.println(results.bits);
    irrecv.resume();
  }
  delay(600);
  if (results.value == 0xE318261B)
  {
    flameOn(); // press the fire button
  }
  else
  {
    flameOff(); // do not press fire button
  }
}
 
 
void flameOn() {
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(100);
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(100);
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(100);
  results.value = 0 ;
}
 
void flameOff() {
  digitalWrite(ledPin, LOW);
  results.value = 0 ;
}

 

The changes were that we added Flame On and Flame Off sub routines even though we're not actually triggering the sprayer yet. For now we're using the LED to make sure that we're getting the signal to fire – a Flame On condition causes the LED to flash. A Flame Off condition has to set the Remote results variable to o, otherwise the code continues to believe that the fire button is pressed.

Once that was working the next step was to start adding Rick's code that triggers the spray:

 

/*
  Remote Controlled Fire Pumpkin, based on FireLantern v1 from Rick Osgood
 
 
  : connect Glade VCC to Aduino 3.3V
  : connect Glade GND to Arduino GND
  : connect Glade "Manual" switch wire to Arduino pin 2 (motorpin)
 
*/
 
// Libraries
#include <IRremote.h>
 
// Constants
const int irReceiverPin = 7;
const int ledPin = 13;
 
const int motorPin = 2;
 
const int wait_time = 3000; // seconds to wait after firing before it can fire again
 
 
IRrecv irrecv(irReceiverPin);
decode_results results;
 
void setup()
{
  pinMode(ledPin, OUTPUT);
 
  pinMode(motorPin, OUTPUT);
  flameOff(); // do not press fire button; // make sure fire button starts unpressed (When button is pulled to ground it will fire)
 
  Serial.begin(9600);
  irrecv.enableIRIn();
}
 
void loop()
{
  if (irrecv.decode(&results)) {
    Serial.print("irCode: ");
    Serial.print(results.value, HEX);
    Serial.print(", bits: ");
    Serial.println(results.bits);
    irrecv.resume();
  }
  delay(100);
  if (results.value == 0xE318261B)
  {
    flameOn(); // press the fire button
  }
  else
  {
    flameOff(); // do not press fire button
  }
}
 
 
// SUBROUTINE – flame on
void flameOn() {
  digitalWrite(ledPin, HIGH);
  digitalWrite(motorPin, LOW);
  delay(wait_time);
  results.value = 0 ; // clear variable, which otherwise persists causing us to just remain in the loop
}
 
 
// SUBROUTINE – flame off
void flameOff() {
  digitalWrite(ledPin, LOW);
  digitalWrite(motorPin, HIGH);
  results.value = 0 ; // clear variable, which otherwise persists causing us to just remain in the loop
}

 

Here we declare motorPin 2, the one used to fire the sprayer, and also add a constant (wait_time) for the delay between sprays.

We also get rid of the LED flashing, but still light the LED during the Flame On subroutine, and hold it for the wait_time delay. This does a couple of things. First it gives valuable feedback on whether the signal was received, which is helpful in debugging. If the LED doesn't flash the IR receiver didn't get a signal (or at least the right signal) and no flame should be expected.

It also tells us whether we're currently locked out from another spray – as long as we are in the wait_time delay we can't trigger another flame. This was really useful because we let neighbourhood kids take turns firing it and, not being the most patient beings, they tended to just keep pumping the button. It was easy to explain that they need to wait until the LED went out.

Later the wait_time value would be adjusted. On Halloween night, when adults were triggering the flame for kids coming to the door, it helped to tighten it up a little. There are misfires sometimes, when the Arduino gets the IR signal but doesn't trigger the spray, or they spray doesn't ignite, and three seconds can be a long time when expectant kids are waiting.

 

Physical Setup

It was set up like in the video, with the candle (pilot light) on the lip of the mouth. It would have looked better with the flame inside, but with that setup the spray would not ignite reliably.

This setup also meant that the eyes were not very well lit, as there really wasn't any light inside the pumpkin. Eventually this was addressed by adding a few more small candles, tea lights, inside the pumpkin, beside and behind the sprayer. This gave it a much better jack-o-lantern type appearance when not firing.

The flame from the sprayer would sometimes put out the pilot light (candle). This was best addressed by having the candle as far away from the direct spray as possible while still reliably igniting i, Too far from the spray and it won't ignite, too close and the candle gets blown out.

The flame effect is definitely most impressive from the side, where you get a better sense of the length of the flame. It was best to fire it when visitors were beside it rather than looking directly at it.

 

Improvements

One ongoing concern is that the built-in timed spray function is still active, so it appears that every so often the thing just goes off by itself. This can be a little unnerving. Also – there is no safety mechanism to prevent this automatic fire (or a remote control fire) from happening when someone is close by.

Adding a proximity sensor, connected to a relay, that cut all power to the sprayer when someone was too close would be a good improvement.

Sound would help too. The problem is that you need to have the fire far enough away from the kids that they don't get burned, but that also means they may not notice it. Some kind of audible alert, maybe even starting briefly before the flame, could help draw attention.

 



Tags: Arduino

Related Content

Arduino Project – LED Skull 5: Adding Subroutines/Functions

This code was a great opportunity to introduce the idea of subroutines and returning values from subroutines (functions) with an Arduino Uno.

Arduino Project – LED Skull 4: Add HC-SR04 Ultrasonic Module

The next step in creating a spookier skull was to add an HC-SR04 ultrasonic module that would fire the LEDs based on proximity to a viewer.

Arduino Project – LED Skull Eyes 3: Adding a Second Eye

The next step involves adding a second "eye" (LED), independent of the first, to maintain the wink effect.

Arduino Project – LED Skull Eyes 2: Wink Effect

More variables and the addition of a "wink" effect to make the LED skull eyes seem more animated.

Arduino Project – LED Skull Eyes 1

The first part of this project (adding LED "eyes" to a skull, driven by an Arduino UNO) was about teaching code optimization, abstraction and commenting.

Arduino IDE "'lt' was not declared in this scope" Error

Be aware of a small encoding issue and the resulting "lt/gt was not declared in this scope" error when pasting into the excellent Arduino IDE for Mac.

Category List


Tag List


Tag Cloud



Archive