Project 1 - Controlling a DC motor using PWM and monitoring its Running status
Overview of the Project :
Implement a system on the simulator for controlling a DC motor using L293 motor driver, monitor its status and print the running status of motor on the LCD Display.
Goals :
- Implement a system on simulator for Controlling the DC motor using L293 motor driver.
- Displaying the running status of DC motor on the LCD display.
Key Highlights of the Project :
- The DC motor can be controlled by using L293 motor driver.
- The speed of a DC motor can be controlled by varying its input voltage, for doing this is to use PWM (Pulse Width Modulation).
- L293D IC is a typical Motor Driver IC which allows the DC motor to drive on any direction.
Deliverables of this project :
- Implement the system for controlling DC motor.
- Controlling the speed of the DC motor using PMW.
- Displaying the present running status of DC machine on LCD display.
Expected Outcomes :
- Implement a system on simulator to control a DC motor using PMW
- Monitoring the running status of the DC motor using L293 motor driver which allows the DC motor to drive on any direction.
- Running status i.e. on which direction the DC motor is running is to be displayed on the LCD screen.
Ans :
To implement a system on the simulator for controlling a DC motor using L293 motor driver, monitor its status and print the running status of motor on the LCD Display. For that we required,
Components Used in the Circuit :
1: Arduino Uno - 1
2: DC Motor - 1
3: L293 IC - 1
4: LCD Display (Hd44780) - 1
5: Volt Meter - 1
6: Oscilloscope - 1
7: Power Source (5V) - 1
8: Potentiometer (1K ohm) - 1
9: Push Buttons - 3
10: Ground (0V) - 4
11: Connecting Wires - As required
Wiring Connections :
Step 1: Connect Power Source :
- Connect the positive terminal (+) of the 5V power source to the one side of potentiometer.
Step 2: Connect L293 IC :
- Connect the L293's pin (EN34) to Arduino Uno's digital pin 8.
- Connect the L293's pin (3A) to Arduino Uno's digital pin 10.
- Connect the L293's pin (4A) to Arduino Uno's digital pin 9.
- Connect the L293's pin (3Y) to the DC Motor Positive Terminal.
- Connect the L293's pin (4Y) to the DC Motor Negitive Terminal.
- Connect Ground (0V) to the L293's pin (4Y).
Step 3: Connect DC Motor :
- Connect Positive terminal of the DC motor to L293's pin (3Y).
- Connect the Negitive terminal of the DC motor to L293's pin (4Y).
Step 4: Connect Potentiometer :
- Connect one end of the potentiometer to the 5V power source.
- Connect the middle pin of the potentiometer to the Arduino Uno's analog pin A0.
- Connect the other end of the potentiometer to the Ground (0V).
Step 5: Connect LCD Display :
- Connect the D7 of the LCD to the Arduino Uno's pin (2).
- Connect the D6 of the LCD to the Arduino Uno's pin (3).
- Connect the D5 of the LCD to the Arduino Uno's pin (4).
- Connect the D4 of the LCD to the Arduino Uno's pin (5).
- Connect the EN of the LCD to the Arduino Uno's pin (11).
- Connect the RS of the LCD to the Arduino Uno's pin (12).
- Connect the RW of the LCD to the Ground (0V).
Step 6: Connect Push Buttons :
- Connect one end of each push button to Arduino Uno's digital pins (A1, A2, A3).
- Connect all the other end of the push buttons to the Ground (0V).
Step 7: Connect Volt Meter :
- Connect the volt meter Positive Terminal to the DC Motor Positive Terminal.
- Connect the volt meter Negitive Terminal to the DC Motor Negitive Terminal.
Step 8: Connect Oscilloscope :
- Connect the Oscilloscope Channel 1 at frequency (50Hz) to the Output Terminal of Volt meter.
Step 9: Final Checks :
- Double-check all connections, ensuring there are no loose wires or accidental short circuits.
- Power on the circuit and make sure all components are functioning as expected.
Logic Used in the Code :
1: Initialization (setup function) :
- The serial communication is initialized with a baud rate of 9600.
- Pin modes are set for the potentiometer and push buttons.
- Pin modes are set for the motor control pins (EN, IN1, IN2) and LCD pins.
- The LCD is initialized with a 16x2 configuration.
- The LCD displays "Project1" for 2 seconds and then clears the display.
2: Main Loop (loop function) :
- Analog read is performed on the potentiometer to get a value between 0 and 1023.
- The potentiometer reading is mapped to a duty cycle range of 0 to 255 and a percentage range of 0 to 100.
- The calculated duty cycle is written to the motor enable pin (EN) using analogWrite.
- The current duty cycle is displayed on the LCD at the top row.
3: Button Input :
- Three push buttons (Forward, Stop, Backward) are read using digitalRead.
- If the Forward button is pressed (digitalRead(bt_F) == 0), the set variable is set to 1.
- If the Stop button is pressed (digitalRead(bt_S) == 0), the set variable is set to 0.
- If the Backward button is pressed (digitalRead(bt_B) == 0), the set variable is set to 2.
4: Motor Control :
- Depending on the value of the set variable, different actions are taken to control the motor.
- If set is 0, the motor is stopped by setting both motor control pins (M1_3A and M1_4A) to LOW.
- If set is 1, the motor rotates clockwise by setting M1_3A to HIGH and M1_4A to LOW.
- If set is 2, the motor rotates anticlockwise by setting M1_3A to LOW and M1_4A to HIGH.
5: Display on LCD :
- The status of the motor (Stop, Clockwise, Anticlockwise) is displayed on the second row of the LCD.
6: Delay :
- A delay of 50 milliseconds is introduced at the end of the loop to control the loop execution frequency.
Code Used :
#include <LiquidCrystal.h> /* The LiquidCrystal library provides functions to interact with LCDs (Liquid Crystal Displays) based on the Hitachi HD44780 driver */
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); /* initializes an instance of the LiquidCrystal class named lcd with specified pins for RS, E, and data pins */
#define potentiometer A0 /* This line defines potentiometer as a symbolic name for the analog pin A0 */
#define bt_F A1 /* This line defines bt_F as a symbolic name for the analog pin A1 */
#define bt_S A2 /* This line defines bt_S as a symbolic name for the analog pin A2 */
#define bt_B A3 /* This line defines bt_B as a symbolic name for the analog pin A3 */
#define M1_34EN 10 /* This line defines M1_34EN as a symbolic name for digital pin 10 */
#define M1_3A 9 /* This line defines M1_3A as a symbolic name for digital pin 9 */
#define M1_4A 8 /* This line defines M1_4A as a symbolic name for digital pin 8 */
int read_ADC = 0; /* Variables are declared to store the analog reading, duty cycle, duty cycle for display, and the set state */ int duty_cycle; int duty_cycle_lcd; int set = 0;
void setup() /* It is used for initializing variables, setting pin modes, and performing other setup tasks */
{
Serial.begin(9600); /* Serial communication is initialized at a baud rate of 9600 */
pinMode(potentiometer, INPUT); /* Pin modes are set for the potentiometer, push buttons, and motor control pins */
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); /* The LCD is initialized with a 16x2 configuration, and "Project1" is displayed for 2 seconds */
lcd.setCursor(0, 1); lcd.print("Project1"); delay(2000); lcd.clear(); /* Clear the LCD */
}
void loop() /* where the main logic of the code resides, and it continuously runs in a loop */
{
read_ADC = analogRead(potentiometer); /* Analog reading of the potentiometer is performed, and the values are mapped to duty cycle ranges */
duty_cycle = map(read_ADC, 0, 1023, 0, 255); duty_cycle_lcd = map(read_ADC, 0, 1023, 0, 100);
analogWrite(M1_34EN, duty_cycle); /* The duty cycle is applied to the motor using analogWrite to control its speed */
lcd.setCursor(0, 0);
lcd.print("Duty Cycle:"); /* The current duty cycle is displayed on the LCD */
lcd.print(duty_cycle_lcd);
lcd.print("% ");
if (digitalRead(bt_F) == 0) set = 1; /* Push buttons are read, and the set variable is updated based on button presses */
if (digitalRead(bt_S) == 0) set = 0; if (digitalRead(bt_B) == 0) set = 2;
lcd.setCursor(0, 1); /* Motor control pins are set accordingly to achieve the desired direction */
if (set == 0) { lcd.print(" Stop "); /* Motor status (Stop, Clockwise, Anticlockwise) is displayed on the LCD */
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); /* A delay of 50 milliseconds is introduced to control the loop execution frequency */
}
Output :
1: The LCD will display the duty cycle percentage on the first line.
2: The second line of the LCD will indicate the current motor status (Stop, Clockwise, Anticlockwise) based on the button inputs.
3: The DC motor speed will vary based on the potentiometer position.
4: The motor direction will change according to the button inputs (0 for stop, 1 for clockwise, 2 for anticlockwise).
Step by step Instructions :
1. Initialization :
- The #include <LiquidCrystal.h> directive includes the LiquidCrystal library for interfacing with LCDs.
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2); initializes an LCD object named lcd with specified pin configurations.
2. Pin and Variable Definitions :
- #define statements assign symbolic names to various pins and components for readability and easy modifications.
- potentiometer, bt_F, bt_S, bt_B, M1_34EN, M1_3A, and M1_4A are symbolic names for corresponding pin numbers.
3. Variable Declarations :
- int read_ADC = 0;, int duty_cycle;, int duty_cycle_lcd;, and int set = 0; declare variables for analog reading, duty cycle, duty cycle for LCD display, and set state.
4. Setup Function :
- void setup() {...} is a special function called once during startup.
- Serial.begin(9600); initializes serial communication at a baud rate of 9600.
- pinMode() sets pin modes for the potentiometer, push buttons, and motor control pins.
- lcd.begin(16, 2); initializes the LCD with a 16x2 configuration.
- A message "Project1" is displayed on the LCD for 2 seconds, and then the LCD is cleared.
5. Loop Function :
- void loop() {...} is the main loop that continuously executes.
- analogRead(potentiometer); reads the analog value from the potentiometer.
- map() scales the analog reading to a duty cycle range for motor speed control.
- analogWrite(M1_34EN, duty_cycle); applies the duty cycle to control the motor speed.
- LCD displays the current duty cycle percentage and motor status based on push button inputs.
- delay(50); introduces a delay to control the loop execution frequency.
6. Motor Control :
- The motor is controlled based on the set state (set variable) determined by the push buttons.
- digitalWrite() sets the motor control pins (M1_3A and M1_4A) based on the set state.
7. Display on LCD :
- The LCD displays the duty cycle percentage and motor status (Stop, Clockwise, Anticlockwise).
8. Serial Communication :
- Serial communication can be used for debugging or additional information, and it's initialized in the setup function.
Uses :
1: Robotics Projects :
This system can be integrated into robotics projects where precise control of DC motor movement and speed is essential. The L293 motor driver allows bidirectional control, making it suitable for robotics applications.
2: Automation Systems :
In automated systems, such as conveyor belts or robotic arms, the ability to control the direction and speed of a DC motor is crucial. The LCD display can provide real-time feedback on the motor's status.
3: Smart Home Devices :
This project can be adapted for smart home applications, like controlling window blinds, curtains, or other movable fixtures. The LCD display can show the current position or status of these devices.
4: Educational Purposes :
The project is also valuable for educational purposes, helping students learn about motor control, PWM, and interfacing with displays. It provides a hands-on experience with electronics and programming.
5: Prototyping and Development :
Engineers and hobbyists can use this system as a starting point for prototyping various projects that involve motor control. It serves as a foundation for more complex systems.
6: Industrial Automation :
In industrial settings, similar motor control systems are used for controlling machinery. The ability to monitor the running status of a motor is crucial for maintenance and troubleshooting.
7: DIY Electronics Projects :
Hobbyists and electronics enthusiasts can use this project as a basis for creating their own electronic devices. It's a practical and educational way to experiment with motor control and display integration.
8: Research and Development :
Researchers working on projects involving motor control and automation may find this system useful for testing and validating their ideas before implementing them in larger-scale applications.