session 7arduino -
session 7arduino -
important note
We can use PWM signal to control the speed of
the DC Motor (when the duty cycle of PWM signal
increases then the speed increases).
.
DC Motor
pinMode(Relay,OUTPUT);
}
void loop() {
digitalWrite(Relay,HIGH);}
Proteus design
H-Bridge
It is used to control the direction of motor.
H-Bridge
code:
To control direction using H-bridge.
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
delay(1000);
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
delay(1000);
}
Motor Driver
Instead of using previous circuit you may use transistorized H
Bridge in which freewheeling diodes are used to avoid
problems due to back emf. Thus it requires minimum four
transistors, diodes and resistors for each motor. It is better to
use readymade ICs such as L293D or L293 and L298N motor
driver instead of making your own H Bridge, which simplifies
your project.
L293D can provide up to 600mA current, in the voltage ranging
from 4.5 to 36v.
L293D
The L293D Motor Driver is a controller that uses an
H-Bridge to easily control the direction and speed of
up to 2 DC motors
L298N MOTOR driver
L298N PINOUT
L298N PINOUT
IN1 and IN2 control the direction of the motor
connected to OUT1 and OUT2.
IN3 and IN4 control the direction of the motor
connected to OUT3 and OUT4.
Input EN1 is used to control speed of motor 1and
EN2 for motor 2.
L298N
You can power the L298N with up to 12V by
plugging your power source into the pin on the
L298N labelled "12V". The pin labelled "5V" is a 5V
output that you can use to power your Arduino
code :
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
analogWrite(speed_motor2,127);
delay(1000);
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
analogWrite(speed_motor1,127);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, HIGH);
analogWrite(speed_motor2,127);
delay(1000);
}
Proteus design