ferequiz.blogg.se

Can arduino be used to control a forward and reverse motor
Can arduino be used to control a forward and reverse motor








can arduino be used to control a forward and reverse motor

Then we turn the motor OFF by setting in2 LOW with digitalWrite(in2, LOW). We use delay(2000) to keep the motor spinning in reverse for two seconds. The delay(1000) function keeps the motor OFF for one second.Īfter the motor is OFF for one second, we reverse the direction of the motor by setting in1 LOW, and in2 HIGH with digitalWrite(in1, LOW) and digitalWrite(in2, HIGH). Then, digitalWrite(in1, LOW) turns the motor OFF by setting in1 LOW. The delay(2000) function keeps the motor spinning for two seconds. In the loop section, digitalWrite(in1, HIGH) and digitalWrite(in2, LOW) turns in1 HIGH, and in2 LOW, which makes the motor spin in one direction. Then in the setup section, we set in1 and in2 as outputs with the pinMode() function.

can arduino be used to control a forward and reverse motor

The first two lines of code assign the in1 variable to Arudino pin 10, and the in2 variable to pin 11.

can arduino be used to control a forward and reverse motor

Once you’ve built the circuit above, upload this code to your Arduino: int in1 = 10 Here, we’re using a 12V supply to power the motor, and a separate 5V supply to power the Arduino and L293D. You will probably need a separate power supply for the motor. To build this project, connect the DC motor, L293D, and Arduino like this: You’ll learn basic to advanced Arduino programming and circuit building techniques that will prepare you to build any project. If you want to learn more about the Arduino, check out our Ultimate Guide to the Arduino video course. Let’s build an example project that will make a DC motor spin in one direction for two seconds, stop, then spin in the opposite direction for two seconds. To build the example projects, you’ll need the following parts:Ĭonnect the DC Motor and L293D to the Arduino In this tutorial, we’re going to build a few example projects to demonstrate how to use the L293D to control DC motors on the Arduino. To turn the motor OFF, send a LOW signal to the input 2 pin. To make the motor spin in the opposite direction, send a LOW signal to the input 1 pin, and a HIGH signal to the input 2 pin. This will cause the motor to spin in one direction. To turn the H-bridge 1 motor ON, send a HIGH signal to the input 1 pin, and LOW signal to the input 2 pin. Input 4: motor control signal for H-bridge 2.Input 3: motor control signal for H-bridge 2.Input 2: motor control signal for H-bridge 1.Input 1: motor control signal for H-bridge 1.Enable 3, 4: turns ON/OFF H-bridge 2 (HIGH enables, LOW disables).Enable 1, 2: turns ON/OFF H-bridge 1 (HIGH enables, LOW disables).Vcc 2: power supply for the motors (4.5V to 36V DC).H-bridge 1 can control one motor, and H-bridge 2 can control another motor.










Can arduino be used to control a forward and reverse motor