PART-2 || PWM CONTROL WITH BUTTONS || DC MOTORS SPEED CONTROL WTH POTENTIOMETER


PWM CONTROL WITH BUTTONS 

( DC MOTORS SPEED CONTROL WTH POTENTIOMETER )

CIRCUIT DIAGRAM:


COMPONENTS LIST : 
  1. ARDUINO UNO / NANO
  2. L298N MOTOR DRIVER
  3. DC MOTORS
  4. 100K POTENTIOMETER
  5. BATTERY
  6. JUMPER WIRES
  7. PUSHBUTTONS/ TACTICAL BUTTONS



SOURCE CODE:
int EnableA = 3; int EnableB = 5; int LMT1 = 4;//LEFT MOTOR TERMINAL int LMT2 = 6; int RMT1 = 7;//RIGHT MOTOR TERMINAL int RMT2 = 8; int potValue = 0; int motorValue = 0; void setup() { pinMode(LMT1, OUTPUT); pinMode(LMT2, OUTPUT); pinMode(RMT1, OUTPUT); pinMode(RMT2, OUTPUT); pinMode(EnableA, OUTPUT); pinMode(EnableB, OUTPUT); pinMode(A0, INPUT);//POTENTIOMETER pinMode(A1, INPUT_PULLUP);//BUTTON1 pinMode(A2, INPUT_PULLUP);//BUTTON2 } void loop(){ int potValue = analogRead(A0); int motorValue = map(potValue, 0, 1023, 0, 255); int BUTTON1 = digitalRead(A1);//READ BUTTON1 int BUTTON2 = digitalRead(A2);//READ BUTTON2 if(BUTTON1 == 0){//MOTORS RUN FORWARD digitalWrite(LMT1, HIGH); digitalWrite(LMT2, LOW); digitalWrite(RMT1, HIGH); digitalWrite(RMT2, LOW); analogWrite(EnableA, motorValue); analogWrite(EnableB, motorValue); } if(BUTTON2 == 0){//MOTORS RUN BACKWARD digitalWrite(LMT1, LOW); digitalWrite(LMT2, HIGH); digitalWrite(RMT1, LOW); digitalWrite(RMT2, HIGH); analogWrite(EnableA, motorValue); analogWrite(EnableB, motorValue); } if(BUTTON1 == 1 && BUTTON2 == 1){//MOTORS STOP digitalWrite(LMT1, LOW); digitalWrite(LMT2, LOW); digitalWrite(RMT1, LOW); digitalWrite(RMT2, LOW); analogWrite(EnableA, motorValue); analogWrite(EnableB, motorValue); } }

Post a Comment

0 Comments