int motor = 9;
int potenciometer = 5;
void setup(){
pinMode(9,OUTPUT);
pinMode(5,INPUT);
Serial.begin(9600);
}
void loop(){
int value = analogRead(potenciometer);
//read input value: range between (0,1023)
int motor_speed = value/4;
//PWM can only ouput 255 different values
analogWrite(motor,motor_speed);
Serial.println(motor_speed);//for testing purposes
}
This is the connection I use to construct on breadboard.
Fortunately, the code works when I tested on breadboard and the results were true as what was expected.
This is before I tune the variable resistor. As you can see, the motor doesn't move.
In this picture, the motor move after I tune the variable resistor. If I tune it all the way, the motor will move to its maximum speed.
For this testing, I used the components DC motor 3V, Variable Resistor 10kΩ, Transistor TIP120, Diode 1N4001, resistor 330Ω and the Arduino microcontroller.
No comments:
Post a Comment