Challenge

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

1.

#include<LiquidCrystal.h>
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);
}

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.