Description
With Halloween coming up at the end of the month, I thought I would do a little festive October project. I explored motion as an output focusing on the vibration caused by the DC motor with a cork eccentric weight attached to it. The goal was to make one of those spooky door decorations so if someone came to my front door and stepped on the mat on the ground in front the FSR would read in this pressure and then in response the ghost would glow red and move about as a spooky tune played in the background. The only problem was that the FSR I soldered to longer wires broke already, so I had to use my FSR that was connected directly to the breadboard, unfortunately.
Components Used
red LED (Light Emitting Diode)
20-ohm resistor (red, red, brown, gold)
1k resistor
DC motor
diode
transistor
FSR
piezo speaker
Arduino Code
/*
* Happy Halloween! Ghost
*/
int potPin = 1; // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int redPin = 10; // select the pin for the red LED
int speakerOut = 7; // select the pin for the piezo speaker
int val = 0; // variable to store the value coming from the sensor
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
//byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p";
// thanks to John Ward for helping me come up with the spooky melody.
// I attempted to use the E minor triad followed by the D minor triad (minus the a)
// so e g b d f
//byte melody[] = "4e4g4b3e3g3b2e2g2b1e1g1b2p8p8p8p4d4f4a3d3f3a2d2f2a1d1f1a2p8p8p8p";
//byte melody[] = "4e4g4e4g4e4g4e4g4e4g4e4g4d4f4d4f4d4f4d4f4d4f4d4f4d4f4d4f2p";
//byte melody[] = "4e4g4b4e4g4b4d4f4d4f4e4g4b4e4g4b4d4f4d4f4e4g4b4e4g4b4d4f4d4f2p";
//byte melody[] = "4e4g4e4g4e4g4e4g4d4f4d4f4d4f4d4f4d4f4d4f4d4f4d4f2p";
byte melody[] = "4e4g4b4e4g4b8d8f4e4g4b4e4g4b8d8f4e4g4b4e4g4b8d8f2p";
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
// 10 20 30
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int statePin = LOW;
void setup() {
pinMode(redPin, OUTPUT); // sets the pin as output
pinMode(speakerOut, OUTPUT); // sets the pin as output
Serial.begin(9600);
analogWrite(redPin, 0);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
Serial.println(val);
//if the FSR detects pressure then that means
// someone is stepping on the mat
if(val > 50) {
// send full power to the motor to make the ghost move
analogWrite(motorPin, 255); // analogWrite can be between 0-255
analogWrite(redPin, 255);
digitalWrite(speakerOut, LOW);
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin;
//digitalWrite(ledPin, statePin);
for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody[count*2 + 1]) {
digitalWrite(speakerOut,HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerOut, LOW);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == 'p') {
// make a pause of a certain size
digitalWrite(speakerOut, 0);
}
}
}
}
}
// no one is on the mat
else
analogWrite(redPin, 0);
analogWrite(motorPin, 0);
//digitalWrite(speakerOut, 0);
}
Item
![lab6bread lab6bread](../../../../system/files/images/lab6breadboard.thumbnail.jpg)
breadboard
![lab6ghost lab6ghost](../../../../system/files/images/lab6ghost.thumbnail.jpg)
ghost setup
video:
<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/HleaOUez1qA"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/HleaOUez1qA" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>