How to build a solar tracker with LDRs and ATtiny85

By Jeremy Cook

With rising energy prices and environmental concerns, many are turning to solar power. There’s a lot to love about this technology, as it literally pulls usable energy out of thin air. However, since the sun arcs across the sky, rarely is a static solar panel aimed directly at our solar system’s “energy orb,” meaning less-than-perfect efficiency.

This problem can be readily solved with automated panels, which turn to face the correct direction. Building a solar tracker is fairly straightforward and can be accomplished with light-dependent resistors and a microcontroller. Instructions for how to make a solar tracking circuit are laid out in this article, which could serve as inspiration–or even as a starting point–for a larger scale system.

Component setup

For this build, the breadboard setup moves via a gearmotor attached to a 3D-printed assembly. Components-wise, you’ll need the following:

This solar tracker circuit, shown below, uses a pair of voltage dividers to feed voltage values from the left and right LDRs to the ATtiny85’s analog-to-digital converter pins (ADCs). These convert 0-5V signal to 0-255 values. Based on this information, the microcontroller is able to decide whether to rotate left, right, or stay in the same place to point toward a light source.

Body Image 1 How To Build a Solar Tracker with LDRs and ATtiny85

Arduino IDE code for this operation is shown below and is available for download on GitHub, along with the 3D-printable base and LDR shielding design. The setup is simplified by having the breadboard act as both a mechanical component and as the electrical connection system. Note that values may need to be adjusted depending on your LDR  and resistor setup.

Body Image 2 How To Build a Solar Tracker with LDRs and ATtiny85

ATtiny85: Low-power superstar

The ATtiny85 microcontroller used here is an extremely small all-in-one control package, set up to run at a 1 MHz internal clock. In active mode at 1 MHz with a 1.8V supply, this microcontroller draws only 300µA of current, and a fraction of that in power-down mode. In this build, the processor is supplied with around 5V, which means it uses about a single mA of current when active.

Compared to other devices, such as the ESP32 (which gives you wireless capabilities), this is a minuscule amount of power. Internal power drain is something that should be considered when designing energy harvesting devices, whether on a large or small scale.

Development considerations for solar bots

This device was put together in a short time to show how an autonomous sun tracking device can be simple to set up. In fact, it would even be possible to build a similar system based on discreet electronics, doing away with the microcontroller altogether.

Body Image 4 How To Build a Solar Tracker with LDRs and ATtiny85

At the same time, using a small computing device like the ATtiny85 provides lots of options as to the device’s behavior. For example, it may be advantageous to wait several minutes between checking the sun’s location, since the sun’s arc is slow and consistent, or even to take an average of LDR values to account for temporary cloud effects. You could even use a PID setup  to smooth out motor operations, or move based on any number of other mathematical functions.

Once you move past the basics, a microcontroller quickly pays for itself in simplicity. You could even apply two more LDRs and a plus-shaped light blocking jig to construct a full up/down/left/right tracker. You’d need another motor, and likely a more capable microcontroller (although the L293D module can accommodate a second motor without extra hardware).

One difficulty with using an ATtiny85 by itself is that there’s no built-in serial output or onboard programming capability. This means that tuning may require a more difficult trial-and-error process than if you could continuously monitor things on a computer screen. Reprogramming means removing the chip and inserting it into a programmer, or using an in-circuit programming arrangement. Neither is an insurmountable problem, but a simple dev board, like an Arduino Uno or similar, would make things much easier.

The downside is that you’ll eventually want to replace the dev board with another option, as such devices can be comparatively power hungry. The Arduino Uno, for example, uses nearly 50mA in its standard mode, or around 50 times the ATtiny85’s requirements at 1MHz.

Body Image 6 How To Build a Solar Tracker with LDRs and ATtiny85

One final consideration: many USB power packs shut themselves off if current isn’t being drawn. It seems that the ATTiny85’s 1mA current needs, plus the breadboard power supply, aren’t always enough to keep power flowing. A cheaper model may actually work better here.

Solar panel robots: Beyond local control

As admirably small and inexpensive as the ATtiny85 is, for other sun tracking you might consider upgrading to an ESP32 or other wireless-capable device. Such a setup could track the sun’s position without using any onboard sensors at all, relying instead on calculations based on the location, time, and date. It could also provide power generation and status feedback to your phone or a central system.

Of course, if you were to design and build a solar tracker for practical usage, you would need to ask the question of whether this sort of “solar panel robot” is indeed the best solution. In some cases, adding a few more panels to a solar array would produce a more cost-effective setup. This project is an interesting technology demonstrator, but don’t be afraid to step back and consider what works best for you!

See related product

ATTINY85-20PU

Microchip Technology Microcontrollers - MCUs View

See related product

L293D

STMicroelectronics Motor Controller and Driver ICs View

See related product

PGM-11801

SparkFun Electronics View

See related product

A000073 | Arduino Uno Rev3 SMD

Arduino S.r.l. Embedded System Development Boards and Kits View

Are you on the list?
Sign up to receive exclusive offers, product announcements, and the latest industry news.

Related news articles

Latest News

Sorry, your filter selection returned no results.

We've updated our privacy policy. Please take a moment to review these changes. By clicking I Agree to Arrow Electronics Terms Of Use  and have read and understand the Privacy Policy and Cookie Policy.

Our website places cookies on your device to improve your experience and to improve our site. Read more about the cookies we use and how to disable them here. Cookies and tracking technologies may be used for marketing purposes.
By clicking “Accept”, you are consenting to placement of cookies on your device and to our use of tracking technologies. Click “Read More” below for more information and instructions on how to disable cookies and tracking technologies. While acceptance of cookies and tracking technologies is voluntary, disabling them may result in the website not working properly, and certain advertisements may be less relevant to you.
We respect your privacy. Read our privacy policy here