DC MOTORS SPEED AND DIRECTION CONTROL WITH JOYSTICK AND POTENTIOMETER || I2C LCD DISPLAY VALUES


DC MOTORS SPEED AND DIRECTION CONTROL WITH JOYSTICK AND POTENTIOMETER || I2C LCD DISPLAY VALUES

CIRCUIT:-

CODE:-

#include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x3F,16,2);//Default address is 0x27 int LMT1 = 4; //LEFT MOTOR TERMINAL 1 int LMT2 = 5; //LEFT MOTOR TERMINAL 2 int RMT1 = 6; //RIGHT MOTOR TERMINAL 1 int RMT2 = 7; //RIGHT MOTOR TERMINAL 2 int ENABLEA = 3;//PWM PIN 3 int ENABLEB = 9;// PWM PIN 9 void setup() { lcd.init(); lcd.backlight(); pinMode(LMT1, OUTPUT); pinMode(LMT2, OUTPUT); pinMode(RMT1, OUTPUT); pinMode(RMT2, OUTPUT); pinMode(ENABLEA, OUTPUT); pinMode(ENABLEB, OUTPUT); pinMode(A0, INPUT);//JOYSTICK pinMode(A1, INPUT);//POTENTIOMETER } void loop() { int JOYSTICK = analogRead(A0);//JOYSTICK VALUE FROM 0 TO 1023 int POTENTIOMETER = analogRead(A1); int POT_VALUE = map(POTENTIOMETER, 0, 1024, 0, 256);//POTENTIOMETER FOR RPM CHANGE lcd.setCursor(0,0); // 1st COLUMN(0) 1st ROW(0) lcd.print("JOY ANGLE:"); lcd.print(JOYSTICK); lcd.setCursor(0,1); // 1st COLUMN(0) 2nd ROW(1) lcd.print("SPEED RPM:"); lcd.print(POT_VALUE); if(JOYSTICK > 520){ //MOTORS ROTATE CLOCKWISE WITH MAX SPEED 0 TO 255 digitalWrite(LMT1, HIGH); digitalWrite(LMT2, LOW); digitalWrite(RMT1, HIGH); digitalWrite(RMT2, LOW); analogWrite(ENABLEA, POT_VALUE);//MAXIMUM SPEED 255 analogWrite(ENABLEB, POT_VALUE); } else if(JOYSTICK < 500){ //MOTORS ROTATE ANTI CLOCKWISE WITH MAX SPEED 0 TO 255 digitalWrite(LMT1, LOW); digitalWrite(LMT2, HIGH); digitalWrite(RMT1, LOW); digitalWrite(RMT2, HIGH); analogWrite(ENABLEA, POT_VALUE);//MAXIMUM SPEED 255 analogWrite(ENABLEB, POT_VALUE); } else{ //MOTORS STOP ROTATE digitalWrite(LMT1, LOW); digitalWrite(LMT2, LOW); digitalWrite(RMT1, LOW); digitalWrite(RMT2, LOW); analogWrite(ENABLEA, 0); analogWrite(ENABLEB, 0); } }

Post a Comment

0 Comments