I am trying to automate single-axis tracking of the sun for solar panels on my RV. I have a 10mm LED mounted on each side such that if the panel is aimed directly at the sun, both LED's get full sunlight. As the sun moves, one will become shaded. With my multimeter, I get ~0.5VDC shaded and ~2.0VDC in full sunlight. For an Arduino or similar as a controller, this should be perfect.
However, I'm not getting valid values with the LED's connected to the ESP32. Putting an LED in the shade changes my analogRead() value very little. I am getting around 1,600 - 2,000 shaded or not.
const int analogPin36 = 36;
const int analogPin39 = 39;
int analogPin36val = 0;
int analogPin39val = 0;
void setup() {
Serial.begin(115200);
delay(1000);
pinMode(analogPin36,INPUT);
pinMode(analogPin39,INPUT);
int res = adcAttachPin(analogPin36);
res = adcAttachPin(analogPin39);
}
void loop() {
analogPin36val = analogRead(analogPin36);
delay(500);
analogPin39val = analogRead(analogPin39);
delay(500);
Serial.print("\t36: " + String(analogPin36val));
Serial.println("\t39: " + String(analogPin39val));
}
If I connect my multimeter to an LED while it is also connected to the ESP32, I do not get a full voltage reading. This leads me to believe the LEDs are not putting out enough amperage to drive both the meter and the analog input. Additionally, I'm wondering if there is simply not enough power to reliably drive the ESP32 analog inputs.
I could parallel more LEDs or swap the LEDs for tiny solar panels to increase power but I'd rather build an amp that ups the power without increasing voltage above the 3.3 limit of the ESP32.
Two hours later, it's dark outside. To my surprise, I'm still getting readings from the ESP32 so I put the voltmeter on. 0.2vdc. How can this be? I disconnect to check just the LED and 0.0vdc. I connect to the analog port and I get 0.2vdc. I've set the ports as INPUT. So confused... Why do I have any voltage on an analog input port?
I see elsewhere that many recommend using a photoresistor or LDR. This is not an option as they go bad after being in direct sunlight for a while.
UPDATE: Thanks to @Mattman944 I've figured it out. The issue is that the LEDs are not able to drive the ADC. In other words, the input resistance of the ADCs is too low for the LEDs The solution is to add a unity gain buffer between the LED and ADC. I've completed the circuit and bench tested it. Now to get it installed and write the code so it intelligently aims the panels.