Description
I used Arduino with a DC motor. I followed the lab instruction and set up the Arduino with a DC motor. I used the sample code provided in the lab to make Arduino interact with the DC motor. I also made a paper wind mill and attached it to the DC motor. Lastly, I uploaded the code and took pictures of the result.
Components
- 1 Arduino
- 1 DC Motor
- 1 Breadboard
- 1 batery case
- 1 paper wind mill
- 1 Transistor
- 1Diode
- 2 Batteries
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
}