Description:
I set out to make a game using a DC motor and ended up with a modified version of Wheel of Fortune. The wheel is a plastic lid with 6 wedges: three are covered in pieces of paper with amounts of money written on them and the other three are translucent. The user uses the potentiometer to adjust the speed of the spinning wheel, then stops it with the FSR. As the wheel slowly comes to a stop, the LED flashes and piezo speaker buzzes every time a colored wedge of the wheel passes over the photocell. If a wedge stops above the photocell, the sound continues, signifying a win.
To keep the motor from wobbling, it is wedged in a cylindrical contact lens case with nickels in the bottom (for weight) that is taped to the styrofoam base inside a flower-shaped sponge. The sponge is there to raise the photocell closer to the lid to achieve a more even light condition.
Materials:
FSR
Potentiometer
Photocell
Resistors
DC motor, diode, transistor
Piezo speaker
LED
Plastic take-out container lid
Flower-shaped sponge
Cylindrical contact lens case with nickels in the bottom for weight
Electrical tape
Colored paper
Ardunio code:
/*
* One pot fades one motor with FSR stop and photocell controlling piezo buzzer
* Used for spinner in Wheel of Fortune creation
* by Chelsey Tanaka
* modified version of one pot fades one motor, which is
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
*
* Code to calibrate the photocell to the max and min light levels is from:
* David A Mellis, created 29 Oct 2008
* Modified 4 Sep 2010 by Tom Igoe
* http://arduino.cc/en/Tutorial/Calibration
*/
int potPin = 0; // select the input pin for the potentiometer
int fsrPin = 1; // select input pin for FSR
int motorPin = 9; // select the pin for the Motor
int photPin = 2; // select input pin for photocell
int ledPin = 10; // select the pin for the LED
int speakerPin = 7; // select pin for the piezo buzzer
int potVal = 0; // variable to store the value coming from the potentiometer
int fsrVal = 0; // variable to store value from FSR
int photVal = 0; // variable to store value from photocell
// variables for calibrating photocell:
int sensorValue = 0; // the sensor value
int sensorMin = 1023; // set minimum high and look for anything lower
int sensorMax = 0; // set max low and look for anything higher
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // declare ledPin as OUTPUT
pinMode(speakerPin, OUTPUT); // declare piezo pin as OUTPUT
digitalWrite(ledPin, HIGH); //turn LED on for calibration period of 5 sec
// calibrate during the first five seconds
while (millis() < 5000) {
sensorValue = analogRead(photPin);
// record the maximum sensor value
if (sensorValue > sensorMax)
{
sensorMax = sensorValue;
}
// record the minimum sensor value
if (sensorValue < sensorMin)
{
sensorMin = sensorValue;
}
}
// signal the end of the calibration period
digitalWrite(13, LOW);
}
void loop() {
potVal = analogRead(potPin); // read the value from the sensor, between 0 - 1024
fsrVal = analogRead(fsrPin); // read the value from the FSR
photVal = analogRead(photPin); //read value from photocell, 0 to 1023
if(fsrVal>300) //corresponds to a medium touch
{
analogWrite(motorPin,0); // turn motor off
}
else
{
analogWrite(motorPin,potVal/4); // otherwise, write pot value/4
// to adjust for range to the motor
}
if(photVal<sensorMax-50) // in tests, range between low and high was ~100
// so Max light level - 50 should mean there's a wedge in the way
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
if(fsrVal>300 && photVal<sensorMax-50) //only turn on speaker if user is pushing
// FSR and photocell value is low
{
tone (speakerPin,262, 500);
}
else
{
noTone(speakerPin);
}
}