Challenge

Project 1 - Controlling a DC motor using PWM and monitoring its Running status

Answer

#include <LiquidCrystal.h>

// Motor control pins

#define ENA 5 // Enable pin for motor driver (PWM)

#define IN1 6 // Input pin 1 for motor driver

#define IN2 7 // Input pin 2 for motor driver

// LCD pins

#define RS 8

#define EN 9

#define D4 10

#define D5 11

#define D6 12

#define D7 13

LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);

int motorSpeed; // Motor speed control variable

void setup() {

pinMode(ENA, OUTPUT);

pinMode(IN1, OUTPUT);

pinMode(IN2, OUTPUT);

// Initialize LCD

lcd.begin(16, 2);

lcd.print("Motor Control");

}

void loop() {

// Read analog input from potentiometer to control motor speed

motorSpeed = analogRead(A0) / 4; // Map 0-1023 to 0-255

// Control motor direction and speed

digitalWrite(IN1, HIGH);

digitalWrite(IN2, LOW);

analogWrite(ENA, motorSpeed);

// Display motor status on LCD

lcd.setCursor(0, 1);

lcd.print("Running ");

delay(1000); // Adjust delay as needed

}

Please I dont now how to put a screenshot of simulation

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.