March 17, 2010 11:02 PM
Motion Sensing Glow Skull
by Anna Kaziunas FranceI am ready for Halloween early this year. For my I/O sensor project for Fab Academy I put together a Arduino-controlled motion sensing glowing skull. When motion is detected by the parallax motion sensor, the board turns on the LEDs in the mouth and fades in and out the LEDs glued into the eye sockets.
The code works - but needs to be modified, right now after the motion is activated, the lights stay on / fade in and out in an infinite loop until the power is switched off. Look for an update to this post.
/* -----------------------------------------------------------------
Anna Kaziunas France
--------------------------------------------------------------------
Fab Academy - Sensors I/O Module
Glowing Skull Project
03/02/2010
--------------------------------------------------------------------
Motion Sensor code:
Motion Sensor code:I have seen this code a few places,
it is never attributed to anyone in particular.
I saw it last at: http://www.ladyada.net/learn/sensors/pir.html
--------------------------------------------------------------------
LED Fader code by: By David A. Mellis - Created 1 Nov 2008
Modified 17 June 2009: By Tom Igoe
http://arduino.cc/en/Tutorial/Fading
--------------------------------------------------------------------
Combined / Modified by Anna Kaziunas France - 03 March 2010
--------------------------------------------------------------------
--------------------------------------------------------------------
Purpose of this Program
--------------------------------------------------------------------
Read input value from the sensor
Determine if motion is present (input is HIGH)
When motion is detected via motion sensor:
1. Eyes slowly glow red (fade in and out - continue)
2. Mouth glows (steady)
When motion is not detected after (length of time)
Switch off LEDs
------------------------------------------------------------------*/
// Variables
int ledPinSolid = 13; // choose the pin for the LED
int ledPinFade = 11; //
int inputPinSensor = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPinSolid, OUTPUT); // declare Solid LEDs as output
pinMode(ledPinFade, OUTPUT); // declare Fader LEDs as output
pinMode(inputPinSensor, INPUT); // declare sensor as input
Serial.begin(9600);
}
// Begin Motion Detection
void loop() {
val = digitalRead(inputPinSensor); // reading input value
if (val == HIGH) { // if the input is HIGH
digitalWrite(ledPinSolid, HIGH); // turn LED ON
// sets the value (range from 0 to 255):
analogWrite(ledPinFade, HIGH); // turn LED ON
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue < = 255; fadeValue +=10) {
// wait for 30 milliseconds to see the fade in effect
delay(400);
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=10) {
// sets the value (range from 0 to 255):
analogWrite(ledPinFade, fadeValue);
// wait for 10 milliseconds to see the dimming effect
delay(110);
}
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected Huzzah!");
// We only want to print on the output change, not state
pirState = HIGH;
}
}
else {
digitalWrite(ledPinFade, LOW); // turn Fader LEDs OFF
digitalWrite(ledPinSolid, LOW); // turn Solid LEDs OFF
if (pirState == HIGH) {
// we have just turned of
Serial.println("Motion ended");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
Puppet Master Final Project Page Updated
Shopbot Project - Modular Shelving
Diploma Completion Checklist Update - 08.14.2010
Unsuccessful Modela Troubleshooting - Partially Successful Switch to Roland Vinyl Cutter
Very Basic Beginner Assembly Tutorial III: How to Use Avrdude
Very Basic Beginner Assembly Tutorial II: How to Use Gavrasm to compile an .asm flie
Very Basic Assembly Tutorial I: Where to Get Gavrasm for the Mac OS
Complete and Working --> Modified Hello Echo + Button + FTDI v.2
Modified Hello Echo + Button + FTDI v.2 ---> In Progress
Modified Hello Echo + Button + FTDI v.1
Mantis Hardware / Software Trial Run
First 3D Scans - Modela Scan of Laughing Die and Shell
Interlocking Rings - 3D Printing
MakerBot Cupcake CNC- Assembling the Plastruder mk4 Spindle
Capacitive Sensing - PuppetMaster v.1-v.2
[Revised] Fab Academy Final Project Proposal: PuppetMaster
FabISB Round 2: Stuffing and Programming the Board
Making Programming, Connector and Serial Cables
Final Project Licencing and Distribution
Internet 0 / Zero - Milling, Stuffing & Setting Up the Boards
Spindle Assembly - Mantis Milling Machine
PuppetMaster Final Project Page
Encoded Building Materials with Computer Numerical Control Assembly
Final Project Plan: PuppetMaster Universal Remote
Final project: pinball machine themed on an unfinished opera by Dylan Thomas and Stravinsky
Electronics design and production
The Fabian: an Arduino-compatible, student-friendly board for Fab Labs
Super simple bootstrap 3-axis controller
Breadboard-friendly Attiny45 board
Using a GUI to Control Processing Output with ControlIP5, Firmata via Serial
My favorite python/GTK reference
Fab ISB - Round 1: Milling Out The Board
Completed TARDIS Cast | Working Light