How to make Brushless Motor Speed Controller with Potentiometer using I2C LCD Display







            CODE 

#include <Wire.h>


#include <LiquidCrystal_I2C.h>


#include <Servo.h>




// I2C LCD standard address and size


LiquidCrystal_I2C lcd(0x27,  2, 1, 0, 4, 5, 6, 7, 3,POSITIVE);




Servo myServo;




const int potPin = A3;     // Potentiometer connected to A3


const int servoPin = 3;    // Servo signal connected to pin 3




void setup() {


  lcd.begin(16, 2);        // Initialize LCD


  lcd.backlight();         // Turn on backlight


  myServo.attach(servoPin); // Attach servo to pin 3




  lcd.setCursor(0, 0);


  lcd.print("Brushless Motor");


}




void loop() {


  int potValue = analogRead(potPin);         // Read potentiometer value (0-1023)


  int angle = map(potValue, 5, 200, 0, 180); // Map to servo angle (0-180)


  myServo.write(angle);                      // Set servo angle




  lcd.setCursor(0, 1);


  lcd.print("SPEED:     ");                  // Clear old value


  lcd.setCursor(7, 1);


  lcd.print(angle);                          // Show updated angle


  lcd.setCursor(10, 1);


  lcd.print("%  ");



  delay(100); // Small delay to avoid flicker


}

Post a Comment

Previous Post Next Post

Contact Form