I will Complete till the Complete features in my final Project idea. The complete features is to display the mode on a LCD Screen(Output), and nice to have features is switching between the modes Automatic and manual using a switch (Input). Also I will simulate the manual mode using a potentiometer (Input) , to move the Servo Motor (Output)
Software: Tinker CAD
1 Breadboard
1 Servo Motor
1 220 ohm resistor
Jumpers
LDR Module
Arduino UNO
1 potentiometer
1 LCD display with I2C module
1 Slide Switch
Software: Arduino IDE
LCD (i2c) Connections: Output
GND (LCD) → GND (Arduino)
VCC (LCD) → 5V (Arduino)
SDA (LCD) → A4 (Arduino)
SCL (LCD) → A5 (Arduino)
Servo Motor Connections: Output
Red Wire (Servo VCC) → 5V (Arduino)
Brown Wire (Servo GND) → GND (Arduino)
Orange Wire (Servo Signal) → Pin 9 (Arduino)
LDR Connections: Input
Connect one leg of the LDR to 5V (Arduino).
Connect the other leg of the LDR to one end of the 10kΩ resistor and to A0 (Arduino).
Connect the other end of the 1kΩ resistor to GND (Arduino).
Potentiometer Connections (Manual Mode): Input
Middle Pin (Potentiometer) → A1 (Arduino)
One Outer Pin (Potentiometer) → 5V (Arduino)
Other Outer Pin (Potentiometer) → GND (Arduino)
Slide Switch: Input
Pin 13 (Arduino) → Breadboard (Button or Switch)
I have thought about the idea of changing between the modes manual and automatic in the same way we have did it in the EOW session , using a slide switch connected to a digital input , and if it is on High then choose the Automatic, if low choose the manual.
For the manual mode , the code is simply to map the analog input of the variable resistor and print on the servo motor. And also print on the LCD that you are in the manual mode .
Set up all the necessary libraries and variables, like the Servo and LiquidCrystal_I2C.
Get the LCD ready.
Set up the pins:
Pin 13 for mode selection.
Pin A0 for the LDR sensor.
Pin A1 for manual servo control.
Start the serial communication for debugging.
Attach the servo to pin 9.
Display "Solar tracker" on the LCD.
Check if Pin 13 is HIGH (Automatic Mode):
If Yes:
Initialize the LCD and turn on the backlight.
Display "Automatic Mode".
Read the light value from the LDR sensor.
Show the LDR value on the LCD and send it to the serial monitor.
If the LDR value is less than 500:
Move the servo to 0° (point the panel away from the light).
Otherwise:
Move the servo to 180° (point the panel towards the light).
If No (Manual Mode):
Initialize the LCD and turn on the backlight.
Display "Manual Mode".
Read the input from pin A1.
Map the input value to a servo angle (0° to 180°) and move the servo accordingly.
The Main problem in this assignment was the LCD library , I have downloaded a lot of wrong libraries and the LCD used to show garbage values .
I got back to Askar's Tutorials and I searched about the right one and i used the examples from the Arduino IDE to start test the LCD.
The shown library in the screenshot is the right library that made the code works.