Assignment: DC Motor: Actuation Assignment 1
Collaborators:
Assignment: DC Motor: Actuation Assignment 1
Collaborators: Ljuba Miljkovic
The purpose of this lab was to:
Ljuba found an old clock that had been discarded, and we decided to try and use the DC motor to manipulate the hands of the clock in an interesting way. Our idea was to make a "Twister" game with two rotational surfaces (each powered by DC motors). The first rotational spinner would tell the player which color should be his/her target, and the second rotational spinner would tell the user which hand or foot to use on his/her target. We decided that the player should flick a piezo speaker to spin the DC motors, since the piezo speaker does a pretty good job of detecting vibrations.
int motorPinSmall = 9; // select the pin for the small motor int motorPinBig = 8; // select the pin for the big motor int speakerPin = 5; // select the input pin for the piezo speaker // (will detect input and serve as the "spinner" driver). int thresholdVal = 100; // the minimum int val = 0; // variable to store the value coming from the sensor void setup() { Serial.begin(9600); pinMode(speakerPin, INPUT); //gets the "spinner" value. } void loop() { val = analogRead(speakerPin); if(val > thresholdVal) { int numIterations = 2*val/100; int i = 0; Serial.println(numIterations); val = val/4; for(i=0; i < numIterations; i++) { analogWrite(motorPinBig, val*2); // analogWrite can be between 0-255 analogWrite(motorPinSmall, val/2); // analogWrite can be between 0-255 delay(50); } } else { analogWrite(motorPinBig, 0); analogWrite(motorPinSmall, 0); } }