Description:
The goal of the assignment was to explore motion as an output using the DC Motor. I decided to make a simple buzzer of the kind used in the television game show Jeopardy! Television contestants buzz in and have a brief period to provide their answer before forfeiting the question.
The DC motor would provide tactile feedback about the various stages when the buzzer is activated by providing different vibration intensities.
Step 1: Trigger Answer Stage
After the user depresses the “on” button, the device will emit a green LED stage indicating the early stages of the answer period. The device will have a weak DC signal that is not enough to actually trigger a rotation, but provides just enough “sound” coming from the DC motor trying its best (unsuccessfully) to turn.
Step 2: Nearing End of Answer Stage
If the button has not been switched again (indicating off), the device will enter the next phase. The blue light will turn on and the green light will stop. The DC motor will increase intensity sufficient to actually vibrate the motor in brief pulses.
Step 3: End of Answer Stage
If the button has not been switched again (indicating off), the device will enter the next phase. The red light will turn on and the blue light will stop. The device will make a noise using the piezo speakers. In addition, the device will emit the strongest pulses of vibration. This stays in a continual loop until the user depresses the “button” to signal stop.
The hardest part of the program was figuring out a good method to create the vibration. I went to the dollar store and found a small plastic like gear which had a hole which I could wedge the endpoint of the DC motor. Next hardest was finding some sort of artifact that would feel comfortable enough to hold in the hand to house the “button”. The button was a simple on/off switch.
Sample video: http://youtu.be/kawvHbFF0iY
Components Used:
1- Breadboard
1- Arduino Uno
1 LEDs (Blue, Green, Red)
1 USB interface cable to Arduino
1 10K Ohm Resistors
1 on/off switch
1 DC motor
1 2 x 1.5V AA battery pack
1 Piezo Buzzer
3 1k Ohm resistor
Code
/*
* Buzzer uses simple on/off switch to turn on three stages of output
* Stage 1: Green LED and very weak DC pulses
* Stage 2: Blue LED with moderaly strong DC pulses
* Stage 3: Red LED with strong pulses continuously until switch is turned off
* Modified again by dave
*/
int potPin = 0; // select the input pin for the potentiometer
int onOffSwitch = 10;
int motorPin = 9; // select the pin for the Motor
int val = 0; // variable to store the value coming from the sensor
int digitalval = 0;
// ledPin
int ledPinRed = 6; // select the output pin for the RED LED
int ledPinGreen = 5; // select the output pin for Green LED
int ledPinBlue = 3; // select the output pin for Green LED
// note names and their corresponding half-periods
int speakerPin = 7;
byte names[] ={ 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
void setup() {
Serial.begin(9600);
pinMode(onOffSwitch,INPUT);
pinMode(motorPin, OUTPUT);
pinMode(speakerPin, OUTPUT);
}
void loop() {
digitalval = digitalRead(onOffSwitch);
if(digitalval == HIGH){ // Switch is in the off stage
Serial.println("Off");
}else if (digitalval == LOW){ // Switch is in the on stage
Serial.println("On");
//Turn on beginning of Answer Period
analogWrite(ledPinGreen, 175);
buzz(motorPin, 100, 300, 15);
analogWrite(ledPinGreen, 0);
if(digitalRead(onOffSwitch) == LOW){ // Switch is in the on stage
//Getting towards the middle
analogWrite(ledPinBlue, 175);
buzz(motorPin, 175, 200, 10);
analogWrite(ledPinBlue, 0);
}
//Done
while(digitalRead(onOffSwitch) == LOW){ // Switch must be turned off to quit
analogWrite(ledPinRed, 175);
buzz(motorPin, 250, 50, 2);
playNote('c',25);
delay(10);
}
analogWrite(ledPinRed, 0);
delay(1000);
}
}
/*
* buzz is a helper function that pulses the DC motor
* motorPin => Pin which signals to motor
* power => Intensity of DC spinning (0-255)
* time => Time in milliseconds to spin
* interval => # of intervals to spin
*/
void buzz(int motorPin, int power, int time, int interval){
for( int counter =0; counter < interval; counter ++){
analogWrite(motorPin,power);
delay(time);
analogWrite(motorPin,0);
delay(100);
}
}
// simple function takes a pin and triggers blinking sequence
void blink(int ledPin, int intervals, int duration ){
for(int counter = 0; counter < intervals; counter ++){
analogWrite(ledPin, 175);
delay(duration);
analogWrite(ledPin, 0);
delay(100);
}
}
//plays a note for cycle
void playNote(int serByte, int cycles){
for (int count=0;count<=8;count++) { // look for the note
if (names[count] == serByte) { // ahh, found it
for( int i=0; i<cycles; i++ ) { // play it for 50 cycles
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tones[count]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[count]);
}
}
}
}
- Login to post comments