Electrical – Using LED’s to track the sun with ESP32 analog inputs

arduinoesp32led

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.

Best Answer

Your setup should work if the ADC input impedance is high enough.

I assume that you are using the LED in photovoltaic mode as shown below. The output of the LED will be weak, the ADC input impedance will need to be about 1 Mohm or higher. I just tried a 100k load and the voltage was significantly less, with a 1 M load the voltage output is almost the same.

To troubleshoot, you need to try something simpler. Connect a voltage source instead and see what happens. Use a power supply set to 1V or one AA battery.

If your setup can read a stiff voltage input, then put a 100k resistor in series. If it changes considerably, you have found the problem.

You may need to ask a simpler question, such as: "why can't my ESP32 read a voltage with a 100k series resistor". Then people won't be distracted with your solar system choices. The comments are useful, but aren't addressing your problem.

schematic

simulate this circuit – Schematic created using CircuitLab

I personally think that your system design isn't too bad. No it won't work on cloudy days, but your photocells won't produce much on these days anyway. You could have your motor set the angle to south if the voltages on both your sensors are low. You seem to be more comfortable with software, you can handle this once your sensors are working.