Project 1 - Controlling a DC motor using PWM and monitoring its Running status
DC MOTOR:
- A DC motor is defined as a class of electrical motors that convert direct current electrical energy into mechanical energy.
- When kept in a magnetic field, a current-carrying conductor gains torque and develops a tendency to move.
- Thus when electric fields and magnetic fields interact, a mechanical force arises.
- This is the principle on which the DC motors work.
L293 MOTOR DRIVER:
- L293d IC is known as a motor driver.
- It is a low voltage operating device like other ICs.
- The other ICs could have the same functions like L293d but they cannot provide the high voltage to the motor.
- L293d provides the continuous bidirectional Direct Current to the Motor.
- The Polarity of current can change at any time without affecting the whole IC or any other device in the circuit.
- L293d has an internal H-bridge installed for two motors.
CIRCUIT DIAGRAM:

CODE:
#include
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define potentiometer A0
#define bt_F A1
#define bt_S A2
#define bt_B A3
#define M1_34EN 10
#define M1_3A 9
#define M1_4A 8
int read_ADC=0;
int duty_cycle;
int duty_cycle_lcd;
int set = 0;
void setup(){
Serial.begin(9600);
pinMode(potentiometer, INPUT);
pinMode(bt_F, INPUT_PULLUP);
pinMode(bt_S, INPUT_PULLUP);
pinMode(bt_B, INPUT_PULLUP);
pinMode(M1_34EN, OUTPUT);
pinMode(M1_3A, OUTPUT);
pinMode(M1_4A, OUTPUT);
lcd.begin(16,2);
lcd.setCursor(0,1);
lcd.print("Hi");
delay(2000);
lcd.clear();
}
void loop() {
read_ADC = analogRead(potentiometer);
duty_cycle = map(read_ADC, 0, 1023, 0,255);
duty_cycle_lcd = map(read_ADC, 0, 1023,0, 100);
analogWrite(M1_34EN, duty_cycle);
lcd.setCursor(0,0);
lcd.print("Duty Cycle:");
lcd.print(duty_cycle_lcd);
lcd.print("% ");
if(digitalRead (bt_F) == 0)(set = 1);
if(digitalRead (bt_S) == 0)(set = 0);
if(digitalRead (bt_B) == 0)(set = 2);
lcd.setCursor(0,1);
if(set==0) { lcd.print(" Stop ");
digitalWrite(M1_3A, LOW);
digitalWrite(M1_4A, LOW);
}
if(set==1){lcd.print(" Clockwise ");
digitalWrite(M1_3A, HIGH);
digitalWrite(M1_4A, LOW);
}
if(set==2){lcd.print(" Anticlockwise ");
digitalWrite(M1_3A, LOW);
digitalWrite(M1_4A, HIGH);
}
delay(50);
}
OUTPUT:
