Control a DC motor with a propeller using an Arduino
FunduinoPublished on
Geschwindigkeit und Drehrichtung eines Gleichstrommotors über eine H-Brücke steuern
You need this
L9110 motor driver - 2.5-12 V, 2 channels, with motor and propeller
3,05 € *Item no. F23106461About the product — L9110 motor driver - 2.5-12 V, 2 channels, with motor and propeller
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
Breadboard cables male-female - 40 pieces, 20 cm
1,74 € *Item no. FUN-1010554About the product — Breadboard cables male-female - 40 pieces, 20 cm
All 3 parts together 15,91 € *Ready to ship immediately · Delivery time: 1-3 business days
* All prices include statutory VAT, plus shipping costs.
Why a motor needs an H-bridge
Module connections
Control direction and speed
Turn the motor to the right at full speed
int MotorA = 10; // Pin INA on digital PWM pin 10
int MotorB = 11; // Pin INB on digital PWM pin 11
void setup()
{
pinMode(MotorA, OUTPUT); // Define pin 10 (Motor A) as an output
pinMode(MotorB, OUTPUT); // Define pin 11 (Motor B) as an output
}
void loop()
{
// Both values range from 0 to 255. The greater the difference between
// Motor A and Motor B, the faster the motor turns.
analogWrite(MotorA, 0);
analogWrite(MotorB, 255);
}Extension: Speed adjustment via rotary knob
Control the speed using a potentiometer
int MotorA = 10; // Pin INA on digital PWM pin 10
int MotorB = 11; // Pin INB on digital PWM pin 11
// The word "input" now stands for A0. The potentiometer signal is connected there.
int input = A0;
int sensorValue = 0; // Variable for the sensor value, initial value 0
int speed = 0; // Variable for the speed, initial value 0
void setup()
{
pinMode(MotorA, OUTPUT); // Define pin 10 (Motor A) as an output
pinMode(MotorB, OUTPUT); // Define pin 11 (Motor B) as an output
}
void loop()
{
// The voltage at the dial is read and stored as a number between 0 and 1023
// under "sensorValue".
sensorValue = analogRead(input);
// The map command converts the range 0 to 1023 into 0 to 255. This lets
// the value be passed directly to analogWrite.
speed = map(sensorValue, 0, 1023, 0, 255);
// This value stays at 0 - changing MotorB controls the speed.
analogWrite(MotorA, 0);
analogWrite(MotorB, speed);
}Rate the instructions