SunTracker SolarPanel - Arduino UNO
A solar panel tracking the sun using 4 LDR'S also measuring the Input Voltage and displaying it on the LCD.
Components and supplies
1
SG90 mini servo
3
Variable Resistor 10k ohm
1
Arduino Uno Rev3
1
MG995 servo motor
1
Solar Panel
1
16 X 2 LCD with I2C Adapter
4
LDR Resistor
Tools and machines
1
Soldering kit
Apps and platforms
1
Arduino IDE 2.0 (beta)
Project description
Code
SolarTracker code
c
copy and upload on board.
1#include <LiquidCrystal_I2C.h> 2#include <Servo.h> 3 4LiquidCrystal_I2C lcd(0x27, 16, 2); //LCD setup 5 6//LDRS Pin connection 7const int LDR_TOP_LEFT = A4; 8const int LDR_TOP_RIGHT = A3; 9const int LDR_BOTTOM_LEFT = A2; 10const int LDR_BOTTOM_RIGHT = A1; 11 12const int LIGHT_THRESHOLD = 75; //change by need, makes the ldrs more sensetive 13 14//Servos 15Servo servo_horizontal; 16Servo servo_vertical; 17int pos_sh = 90; 18int pos_sv = 90; 19const int UPPER_LIMIT_POS = 160; //Upper Servo limit 20const int LOWER_LIMIT_POS = 20; //Lower Servo limit 21 22//Voltage measure 23#define Voltage_pin A0 24float input_voltage = 0; 25float real_voltage = 0; 26 27void setup() { 28 //Serial.begin(9600); //enable to check if ldrs properly working 29 pinMode(A0,INPUT); 30 pinMode(A1,INPUT); 31 pinMode(A2,INPUT); 32 pinMode(A3,INPUT); 33 pinMode(A4,INPUT); 34 pinMode(9,OUTPUT); 35 pinMode(13,OUTPUT); 36 37 lcd.init(); 38 lcd.backlight(); 39 lcd.clear(); 40 delay(100); 41 lcd.setCursor(0,0); 42 lcd.print("SolarPanel"); 43 lcd.setCursor(0,1); 44 lcd.print("Project by halkin"); 45 delay(2000); 46 lcd.clear(); 47 servo_vertical.attach(9); 48 servo_horizontal.attach(13); 49 delay(100); 50 servo_vertical.write(50); 51 servo_horizontal.write(80); 52 delay(500); 53} 54 55void loop() { 56 //reading and calculating sun position 57 int ldr_tl_value = analogRead(LDR_TOP_LEFT); 58 int ldr_tr_value = analogRead(LDR_TOP_RIGHT); 59 int ldr_bl_value = analogRead(LDR_BOTTOM_LEFT); 60 int ldr_br_value = analogRead(LDR_BOTTOM_RIGHT); 61 62 int average_top = (ldr_tl_value + ldr_tr_value) / 2; //average top ldrs 63 int average_bottom = (ldr_bl_value + ldr_br_value) / 2; //average botom ldrs 64 int average_left = (ldr_tl_value + ldr_bl_value) / 2; //average left ldrs 65 int average_right = (ldr_tr_value + ldr_br_value) / 2; //average right ldrs 66 //masuring Voltage on panel and dispaling on lsd 67 voltageMeasure(); 68 //void to move panel directly on sun 69 moveSolarTracker(average_top, average_bottom, average_left, average_right); 70 71} 72 73void moveSolarTracker(int average_top, int average_bottom, int average_left, int average_right) { 74 /* 75 //Ldrs checker 76 Serial.print("top;"); Serial.println(average_top); 77 Serial.print("bottom;"); Serial.println(average_bottom); 78 Serial.print("left;"); Serial.println(average_left); 79 Serial.print("right;"); Serial.println(average_right); 80 Serial.println(""); 81 */ 82 83 //movement Horizontal(left or right) 84 if ((average_left - average_right) > LIGHT_THRESHOLD && pos_sh < UPPER_LIMIT_POS) { 85 pos_sh--; 86 servo_horizontal.write(pos_sh); 87 } 88 else if ((average_right - average_left) > LIGHT_THRESHOLD && pos_sh > LOWER_LIMIT_POS) { 89 pos_sh++; 90 servo_horizontal.write(pos_sh); 91 } 92 //movement Vertical(up or down) 93 if ((average_top - average_bottom) > LIGHT_THRESHOLD && pos_sv < UPPER_LIMIT_POS) { 94 pos_sv++; 95 servo_vertical.write(pos_sv); 96 } 97 else if ((average_bottom - average_top) > LIGHT_THRESHOLD && pos_sv > LOWER_LIMIT_POS) { 98 pos_sv--; 99 servo_vertical.write(pos_sv); 100 } 101 102} 103 104void voltageMeasure(){ 105 input_voltage = analogRead(Voltage_pin); 106 real_voltage = 3*((input_voltage*5.0)/1024);//input voltage decreased by voltage divider, so we calculate it to be acurate. 107 lcd.setCursor(0,0); 108 lcd.print("Voltage:"); 109 lcd.setCursor(9,0); 110 lcd.print(real_voltage); 111 lcd.setCursor(13,0); 112 lcd.print("v"); 113 delay(500); 114}
Comments
Only logged in users can leave comments