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() {

  int res = adcAttachPin(analogPin36);
  res = adcAttachPin(analogPin39);

void loop() {
  analogPin36val = analogRead(analogPin36);
  analogPin39val = analogRead(analogPin39);
  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.

  • 3
    \$\begingroup\$ Do you really mean "LED"? I know that they generate a signal under illumination, I'm just asking because you didn't mention "photodiodes" at all... \$\endgroup\$
    – Sim Son
    Commented May 25, 2021 at 2:14
  • 1
    \$\begingroup\$ Pinhole and 4-quadrant detector. You can extract a 4-quadrant detector from just about any old cd-rom drive (they need them to stay in focus with their astigmatic lensing system.) Pinhole to 4-quadrant detector determines the field of view (FOV.) Sun image and light intensity depend on the diameter of the pinhole. For example, at \$L=42\:\text{mm}\$ and a pinhole diameter of \$800\:\mu\text{m}\$ and 4-quad w/\$5\:\text{mm}\$ sides implies FOV of \$7^\circ\$. Pinhole optics is pretty simple, really. I also like Kate's solution. I've a book that gives all the formulas you'd need for that, too. \$\endgroup\$
    – jonk
    Commented May 25, 2021 at 4:19
  • 3
    \$\begingroup\$ Tim, the point here is that you need to have a background in a variety of techniques so that you can choose the one that better suits your specific situation. I actually think that, ignorant of other science theory, the idea of just plugging in your latitude and working out equations of sunrise and sunset and the arc across your sky is probably a lot easier than making detector systems to do similar things for you. Formulas are easy and don't require any science knowledge on your part. The disadvantage is that your code is specific to your location. 1ate's idea is the easy answer. \$\endgroup\$
    – jonk
    Commented May 25, 2021 at 4:27
  • 1
    \$\begingroup\$ Explain how ‘one will become shaded’. \$\endgroup\$
    – Chu
    Commented May 25, 2021 at 5:15
  • 1
    \$\begingroup\$ your voltmeter is a much smaller load (~10M) than an ESP's ADC (~100K); the ADC pulls down the voltage since the LED makes next to no current. \$\endgroup\$
    – dandavis
    Commented May 25, 2021 at 7:35

2 Answers 2


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.


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.

  • \$\begingroup\$ Why point North? \$\endgroup\$
    – HandyHowie
    Commented May 25, 2021 at 8:11
  • \$\begingroup\$ Fixed, south is optimum for fixed installations (or lacking good data). \$\endgroup\$
    – Mattman944
    Commented May 25, 2021 at 8:17
  • 3
    \$\begingroup\$ I guess it depends which hemisphere you are on. It looks like the OP is only just in the northern hemisphere. \$\endgroup\$
    – HandyHowie
    Commented May 25, 2021 at 8:20
  • \$\begingroup\$ @Mattman944 By far the best answer. Thank you so much! I'm doing exactly as you say now. :) \$\endgroup\$ Commented May 25, 2021 at 17:01

This has to be the worst way to go about it. Several reasons: Cloudy days where both get equal light; In the morning, neither is getting any light. I've seen this done your way as a college project and it didn't work out for those reasons.

Try using a look-up table that knows where the sun will be for your latitude and day of the year. Tie it into a feedback loop that can position the panel according to that data.

  • 2
    \$\begingroup\$ Agreed. Far better solution. No sunlight sensors required do no concern with sensors going bad in direct sunlight. \$\endgroup\$ Commented May 25, 2021 at 3:53
  • 2
    \$\begingroup\$ While you can do away with sunlight sensors this way, you have to replace them with an encoder to track the current position of the panel. Also, if both sensors get equal light due to clouds, it also means the panel will work the same no matter which way it points, so it might as well stay in the current position. \$\endgroup\$
    – TooTea
    Commented May 25, 2021 at 15:11
  • 1
    \$\begingroup\$ @Kate Moon I should have mentioned that this is no an RV so look-up tables are a non-starter for me. \$\endgroup\$ Commented May 25, 2021 at 16:58
  • 2
    \$\begingroup\$ @HandyHowie The microcontroller would also need a GPS to know where in North America I'm at. I'd also need to add an angle sensor to the pannels to know what angle they are at. Going this route is not looking all that good to me. Thanks for the idea though. \$\endgroup\$ Commented May 25, 2021 at 17:07
  • 1
    \$\begingroup\$ Just be aware that esp32 ADC have bad reputations. Especially at low voltage read. \$\endgroup\$
    – netmonk
    Commented May 25, 2021 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.