|
| 1 | +/* |
| 2 | +Portable solar panel efficiency tracker. For testing out solar panels! |
| 3 | +See https://learn.adafruit.com/portable-solar-charging-tracker for more information |
| 4 | +Code is public domain, MIT License by Limor "Ladyada" Fried |
| 5 | +*/ |
| 6 | + |
| 7 | +// include the library code: |
| 8 | +#include <LiquidCrystal.h> |
| 9 | +#include <Wire.h> |
| 10 | + |
| 11 | +// initialize the library with the numbers of the interface pins |
| 12 | +LiquidCrystal lcd(2, 3, 4, 5, 6, 7 ); |
| 13 | + |
| 14 | +#define aref_voltage 3.3 // we tie 3.3V to ARef and measure it with a multimeter! |
| 15 | + |
| 16 | +int lipoPin = 3; // the battery |
| 17 | +float lipoMult = 1.666; // how much to multiply to get the original voltage |
| 18 | + |
| 19 | +int PVPin = 2; // the cell |
| 20 | +float PVMult = 2; // how much to multiply to get the original voltage |
| 21 | + |
| 22 | +int currentPin = 1; |
| 23 | +float currentMult = 208; // how much to multiply to get the original current draw |
| 24 | + |
| 25 | +void setup(void) { |
| 26 | + // We'll send debugging information via the Serial monitor |
| 27 | + Serial.begin(9600); |
| 28 | + |
| 29 | + // set up the LCD's number of rows and columns: |
| 30 | + lcd.begin(16, 2); |
| 31 | + lcd.clear(); |
| 32 | + // Print a message to the LCD. |
| 33 | + lcd.print("Solar logger"); |
| 34 | + delay(2000); |
| 35 | + lcd.clear(); |
| 36 | + // If you want to set the aref to something other than 5v |
| 37 | + analogReference(EXTERNAL); |
| 38 | + |
| 39 | + byte delta[8] = { |
| 40 | + B00000, |
| 41 | + B00100, |
| 42 | + B00100, |
| 43 | + B01010, |
| 44 | + B01010, |
| 45 | + B10001, |
| 46 | + B11111, |
| 47 | + B00000 |
| 48 | +}; |
| 49 | + |
| 50 | + lcd.createChar(0, delta); |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +void loop(void) { |
| 56 | + int adcreading; |
| 57 | + |
| 58 | + adcreading = analogRead(lipoPin); |
| 59 | + Serial.println(adcreading); |
| 60 | + |
| 61 | + float lipoV = adcreading; |
| 62 | + lipoV *= aref_voltage; |
| 63 | + lipoV /= 1024; |
| 64 | + lipoV *= lipoMult; |
| 65 | + |
| 66 | + lcd.clear(); |
| 67 | + Serial.print("LiPo voltage = "); |
| 68 | + Serial.println(lipoV); // the raw analog reading |
| 69 | + |
| 70 | + lcd.setCursor(0, 0); |
| 71 | + lcd.print("LiPo="); |
| 72 | + lcd.print(lipoV); |
| 73 | + lcd.print(' '); |
| 74 | + lcd.write((uint8_t)0); |
| 75 | + |
| 76 | + adcreading = analogRead(PVPin); |
| 77 | + float PVV = adcreading; |
| 78 | + PVV *= aref_voltage; |
| 79 | + PVV /= 1024; |
| 80 | + PVV *= PVMult; |
| 81 | + |
| 82 | + lcd.print((int)((PVV-lipoV) * 1000), DEC); // in mV |
| 83 | + lcd.print("mV"); |
| 84 | + |
| 85 | + Serial.print("PV voltage = "); |
| 86 | + Serial.println(PVV); // the raw analog reading |
| 87 | + |
| 88 | + lcd.setCursor(0, 1); |
| 89 | + lcd.print("PV="); |
| 90 | + lcd.print(PVV); |
| 91 | + |
| 92 | + adcreading = analogRead(currentPin); |
| 93 | + float currentI = adcreading; |
| 94 | + currentI *= aref_voltage; |
| 95 | + currentI /= 1024; |
| 96 | + currentI *= currentMult; |
| 97 | + Serial.print("Current (mA) = "); |
| 98 | + Serial.println(currentI); // the raw analog reading |
| 99 | + |
| 100 | + lcd.print(" I="); |
| 101 | + lcd.print((int)currentI); |
| 102 | + lcd.print("mA"); |
| 103 | + delay(1000); |
| 104 | +} |
0 commit comments