Description: For this lab, I built a circuit which takes input from a potentiometer and outputs values to a DC motor. Because the motor vibrates and spins, I decided to attach a thin cardboard cutout to the rotating axis, creating a functional makeshift fan to cool yourself off with!
Components:
1 Arduino Uno
1 Breadboard
1 potentiometer
1 motor
1 diode
1 transistor
1 resistor
1 battery
various 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 motorPin = 9; // select the pin for the Motor
int val = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
Serial.println(val);
analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}
- Login to post comments