In this lab, we used DC motor and controlled RPM using a potentiometer. The motor was used to both rotate objects and vibrate.
For this homework I decided to make a beer/drink protection system. I used the potentiometer to control the RPM of the cutting system, a photocell to detect when someone was reaching for my drink, and a speaker system to sound an alarm. My deterrent was constructed from a cork, stick, and wires. The cork was attached to the DC motor; and when a person reached for my drink the photocell would detect the change in light intensity and the alarm would sound and the motor would rotate the arm.
My roommates haven’t touched my drinks since.
Materials:
1- Arduino Uno
1- Breadboard
1- 1 kilo-ohm resistor
1- 10 kilo-ohm resistor
1 - 1N4004 Diode
1 - TIP120 Transistor
1 - DC Motor
1 - Battery pack with 2 AA batteries
1 – Photosensor
1 - Pot
1 - Piezo Buzzer
1 - cork
1 - stick
Wires
CODE:
/*
* one pot fades one motor
* modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
* Modified again by dave
*/
int potPin = 0; // select the input pin for the potentiometer
int sensor = 1;
int motorPin = 9; // select the pin for the Motor
int speakerPin = 7;
int val = 0; // variable to store the value coming from the sensor
int val2;
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
val2 = analogRead(sensor);
if (val2 < 270)
{
analogWrite(motorPin, val/4); // analogWrite can be between 0-255
for( int i=0; i<50; i++ ) { // play it for 50 cycles
digitalWrite(speakerPin, HIGH);
delayMicroseconds(1);
digitalWrite(speakerPin, LOW);
delayMicroseconds(1);
} }
else {
analogWrite(motorPin, LOW);
digitalWrite(speakerPin, LOW);
}}
- Login to post comments