#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Servo setup
Servo myServo;
// LCD setup (address 0x27, 16 columns x 2 rows)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Pins
const int potPin = A0;
const int servoPin = 9;
void setup() {
myServo.attach(servoPin);
lcd.begin(16, 2); // ✅ Fix: provide rows and columns
lcd.backlight();
Serial.begin(9600);
}
void loop() {
int potValue = analogRead(potPin); // Read potentiometer (0–1023)
int angle = map(potValue, 0, 1023, 0, 180); // Convert to angle (0–180)
myServo.write(angle); // Move servo
// Display on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Servo Angle:");
lcd.setCursor(0, 1);
lcd.print(angle);
lcd.print((char)223); // Degree symbol
lcd.print(" deg");
// Display on Serial
Serial.print("Servo Angle: ");
Serial.println(angle);
delay(200);
}