Jump to main content

Build a Solar-Tracking Robot

11 reviews


Light sensors are part of many devices that we use every day. For example, they help your phone know when to automatically brighten or dim the screen based on ambient light levels. They can also be used to help solar panels track the sun, which helps the panels generate more power. Many spacecraft and planetary rovers (like the Mars rovers Sojourner, Spirit, and Opportunity) are solar-powered. In this project you will build and program your own solar-tracking robot. Optionally, you can add solar panels and rechargeable batteries. Can your robot keep itself aimed at the Sun?


Areas of Science
Time Required
Short (2-5 days)
You will need to know how to use a breadboard to do this project. See the Science Buddies reference How to Use a Breadboard for Electronics and Circuits if you have not used a breadboard before.
Material Availability
A kit is available with the robot chassis and circuit parts. Arduino must be purchased separately. See materials list for details.
High ($100 - $150)
No issues
Ben Finio, PhD, Science Buddies

Recommended Project Supplies

Get the right supplies — selected and tested to work with this project. Arduino not included.

View Kit


Build and program a robot that can autonomously aim itself towards a light source.


A blue plastic robot chassis with two wheels, an Arduino, breadboard, and light sensors mounted on top

Many solar panels are mounted in a fixed position, for example on the roof of a house (Figure 1). With no moving parts, this approach is sturdy and simple to build/maintain. However, solar panels produce the most power when they are perpendicular to the Sun's rays. This means that fixed-mount panels will produce less power early in the morning and late in the evening, due to the Sun's daily east-west motion through the sky. The amount of power they produce will also vary throughout the year due to seasonal north/south variation of the Sun's position. To help solar panels produce more power, they can be mounted on poles with motorized trackers that make the panels tilt to follow the sun (Figure 2).

 An array of solar panels on the roof of a house.
Figure 1. Fixed solar panels on the roof of a house.

 Solar panels in a parking lot mounted on large poles.
Figure 2. Solar panels mounted on poles with trackers. (image credit Wikimedia Commons user Raysonho)

In addition to solar panels used to generate electricity on Earth, many space-faring vehicles also rely on solar power. The Mars rover Sojourner (Figure 3) could not tilt its solar panels to track the sun. The International Space Station (Figure 4) has large solar arrays that are automatically rotated to face the sun and provide maximum power to the station.

 The Mars rover Sojourner.
Figure 3. The Mars rover Sojourner, with solar panels visible on the top.

 the International Space Station
Figure 4. The International Space Station (ISS) with large solar arrays visible.

In this project you will build a programmable version of the Light Tracking Bluebot. The robot in that project is hard-wired with two light sensors that make the robot steer left and right in response to a light source. However, the robot cannot do things like drive in reverse, or stay in place while rotating to track a light source without driving forward. The robot kit does not include solar panels, but this still allows you to model the behavior of a solar-tracking vehicle.

Terms and Concepts


General electronics references:

References for using an Arduino:

References about space-faring vehicles and solar panels:

Datasheet for the L293D H-bridge motor driver:

Reference explaining how the part of the light-sensing circuit used in this project works (in a robot without an Arduino):

Materials and Equipment Buy Kit

Recommended Project Supplies

Get the right supplies — selected and tested to work with this project. Arduino not included.

View Kit

Notes about using an Arduino:

Disclaimer: Science Buddies participates in affiliate programs with Home Science Tools, Amazon.com, Carolina Biological, and Jameco Electronics. Proceeds from the affiliate programs help support Science Buddies, a 501(c)(3) public charity, and keep our resources free for everyone. Our top priority is student learning. If you have any comments (positive or negative) related to purchases you've made for science projects from recommendations on our site, please let us know. Write to us at scibuddy@sciencebuddies.org.

Experimental Procedure

Note: This engineering project is best described by the engineering design process, as opposed to the scientific method. You might want to ask your teacher whether it's acceptable to follow the engineering design process for your project before you begin. You can learn more about the engineering design process in the Science Buddies Engineering Design Process Guide.
  1. Assemble your Bluebot chassis as shown in this video. However, instead of mounting the 4xAA battery pack on top of the robot, mount it on the lower plate. Then mount your Arduino next to the breadboard on the top plate.
    How to Assemble Your BlueBot Chassis
  2. To control your robot's motors, you will use the L293D H-bridge motor driver chip, included in your Bluebot kit. This chip allows you to control the speed and direction of two motors. Figure 5 shows the pinout from the chip's datasheet and Table 1 describes the functions of the pins. When one of the input pins ("A") for a motor is high and the other one is low, the motor will spin. Reversing which pin is high/low reverses the motor's direction (Table 2). If both input pins are high or both input pins are low, the motor will stop. Do not worry if that does not make sense yet. You will wire the circuit and see example code in the next few steps.
 pinout for L293D H-bridge chip

Pinout for the L293D H-bridge chip. Pins are in two columns of 8, labeled one through 16, counter-clockwise from the top left, as follows: 1,2EN 1A 1Y 'HEAT SINK AND GROUND' 'HEAT SINK AND GROUND' 2Y 2A VCC2 3,4EN 3A 3Y 'HEAT SINK AND GROUND' 'HEAT SINK AND GROUND' 4Y 4A VCC1

Figure 5. L293D H-bridge chip pinout.

Name Pin number(s) Description
VCC1 16 Digital logic voltage supply (5V from Arduino)
VCC2 8 Motor power voltage supply (6V from 4xAA battery pack)
GROUND 4, 5, 12, 13 Electrical ground
1,2EN 1 Speed control for motor 1 using pulse width modulation (PWM) signal from Arduino
3,4EN 9 Speed control for motor 2 using pulse width modulation (PWM) signal from Arduino
1A, 2A 2, 7 Inputs to control motor 1 using Arduino digital pins
3A, 4A 10, 15 Inputs to control motor 2 using Arduino digital pins
1Y, 2Y 3, 6 Outputs to drive motor 1
3Y, 4Y 11, 14 Outputs to drive motor 2
Table 1. Description of L293D H-bridge pins.

1A 2A Motor 1 behavior
Low Low Stop
Low High Spin
High Low Spin the other way
High High Stop
Table 2. How setting the input pins high and low controls motor behavior.
  1. Before you worry about connecting the light sensor, you should make sure your robot's motors work and that it can drive around. Connect your motors, batteries, and the L293D as shown in Figure 6 (note: there is more than one correct way to wire the circuit, this is just an example). The colors shown in the picture are for readability purposes only, your wire colors do not need to match. If you are not sure how to wire a circuit on a breadboard, see the How to Use a Breadboard resource. A few things to look out for when building the circuit:
    1. Make sure the L293D is oriented with the notch facing "up" on the breadboard.
    2. Important: all the components in your circuit should have a "common ground." This means the Arduino's ground pin, the L293D's ground pins, and the 4xAA battery pack's negative wire should all be connected to the ground bus on the breadboard, and the ground buses on opposite sides of the breadboard should be connected.
    3. However, make sure you do not short-circuit the 5V Arduino supply to the 6V battery supply. In the diagram, notice how the left and right power buses on the breadboard are not connected with a jumper wire. The left-side bus provides 6V from the battery pack, and the right-side bus provides 5V from the Arduino. The H-bridge makes use of both power supplies: one for internal logic (5V from the Arduino) and one to power the motors (6V from the batteries). The external 4xAA battery pack is required because the Arduino cannot provide enough current to drive the motors directly.
 Wiring diagram for connecting the Arduino to the L293D

Circuit diagram with the following connections: 9V battery to Arduino barrel jack; Arduino 5V pin to breadboard right-side power bus; Arduino GND pin to breadboard ground bus; 4xAA battery pack positive wire to breadboard A1; 4xAA battery pack ground wire to breadboard ground bus; Jumper wire connecting breadboard left and right ground buses; Do NOT connect the breadboard left and right power buses, this will short the Arduino 5V supply to the 6V from the battery pack; Power switch in breadboard C1, C2, C3; Jumper wire from left side power bus to A2; L293D chip straddling middle gap in breadboard from rows 10-17, with notch facing up (towards row 1); Jumper wire from breadboard A10 to Arduino pin 10; Jumper wire from breadboard B11 to Arduino pin 9; Motor negative lead to breadboard A12; Jumper wire from breadboard A13 to ground bus; Jumper wire from breadboard A14 to ground bus; Motor positive lead to breadboard A15; Jumper wire from breadboard C16 to Arduino pin 8; Jumper wire from breadboard A17 to left side power bus; Jumper wire from breadboard J10 to right side power bus; Jumper wire from breadboard G11 to Arduino pin 13; Motor negative lead to breadboard J12; Jumper wire from breadboard J13 to ground bus; Jumper wire from breadboard J14 to ground bus; Motor positive lead to breadboard J15; Jumper wire from breadboard H16 to Arduino pin 12; Jumper wire from breadboard H17 to Arduino pin 11;

Figure 6. Wiring diagram for connecting the Arduino to the L293D, your robot's motors, and batteries. A bigger version of the image is available.
  1. Make sure the power switch for the 4xAA battery pack is off. Enter the code shown in Figure 7 and upload it to your Arduino. If you are unsure how to do this, refer to the How to Use an Arduino guide.
 Example code to control robot's motors using H-bridge.

// declare variables for motor control pins int Motor1Speed = 10; int Motor1Control1 = 9; int Motor1Control2 = 8; int Motor2Speed = 11; int Motor2Control1 = 13; int Motor2Control2 = 12; // declare variable for motor speed (0-255) int speed = 255; // declare variable for delay time in milliseconds int delayTime = 1000; void setup() { // setup code that only runs once // set motor control pins as outputs pinMode(Motor1Speed, OUTPUT); pinMode(Motor1Control1, OUTPUT); pinMode(Motor1Control2, OUTPUT); pinMode(Motor2Speed, OUTPUT); pinMode(Motor2Control1, OUTPUT); pinMode(Motor2Control2, OUTPUT); // set speed for both motors analogWrite(Motor1Speed, speed); analogWrite(Motor2Speed, speed); } void loop() { // code that loops forever // set both wheels to spin forward for delayTime milliseconds digitalWrite(Motor1Control1, HIGH); digitalWrite(Motor1Control2, LOW); digitalWrite(Motor2Control1, HIGH); digitalWrite(Motor2Control2, LOW); delay(delayTime); // stop for delayTime milliseconds digitalWrite(Motor1Control1, LOW); digitalWrite(Motor1Control2, LOW); digitalWrite(Motor2Control1, LOW); digitalWrite(Motor2Control2, LOW); delay(delayTime); }

Figure 7. Example code to control the robot's motors using the H-bridge.
  1. Put your robot on the ground and turn the power switch on. If everything is working correctly, the robot should repeatedly drive forward for one second, then pause for one second. If it does not, here are some common troubleshooting steps:
    1. Instead of changing your code, you can just switch the red and black wires for a motor to change the direction it spins. You can do this if your robot goes backwards or spins in circles instead of driving forward.
    2. If your motors do not spin at all, double check all of your wiring. If your H-bridge is not wired properly, your motors will not spin.
    3. If your motors still do not spin, use a multimeter to debug your circuit. Refer to the How to Use a Multimeter guide if needed. Try the following:
      1. Make sure you have 5V coming from the Arduino.
      2. Make sure you have 6V coming from the 4xAA battery pack.
      3. Measure the voltages on the Arduino output pins to make sure they are what you expect (e.g. based on the code, pin 9 should toggle between 5V and 0V).
    4. To confirm that your motors work, disconnect them from the H-bridge and connect them directly to 6V and ground on the breadboard.
    5. To confirm that your H-bridge works, disconnect it from the Arduino's digital pins. Use jumper wires to manually connect the H-bridge's input pins to 5V or 0V on the breadboard. (Make sure you reconnect the motors to the H-bridge first.)
  2. Practice steering your robot. Can you modify the program in Figure 7 to make your robot drive in a square? This is called "open loop" navigation, or "dead reckoning." The robot is hard-coded to follow a pre-determined path, without responding to any sensor input. This type of navigation is generally not a good idea, because small errors will accumulate over time, and eventually the robot will drift off course. However, it is a good way to practice programming and make sure your circuit works.
  3. Now it is time to connect a photoresistor (light sensor). A photoresistor is a resistor whose resistance changes depending on the amount of light hitting it. Its resistance goes down when it is exposed to more light. Connect a photoresistor and potentiometer to your Arduino as shown in Figure 8. When connected this way, the photoresistor and potentiometer form something called a voltage divider. The voltage divider sends a voltage to your Arduino that depends on the amount of light hitting the sensor. Note that the H-bridge, motors, and batteries are omitted from this diagram to avoid clutter, but you can leave them connected in your circuit.
 Photoresistor and potentiometer connected to Arduino analog input

Circuit diagram with the following connections: Arduino 5V pin to breadboard right side power bus; Arduino GND pin to breadboard ground bus; Jumper wire connecting breadboard left and right ground buses; Arduino analog in pin A0 to breadboard C22; Potentiometer in breadboard B22, B23, B24; Jumper wire from breadboard E23 to ground bus; Photoresistor from breadboard E22 to F22; Jumper wire from breadboard J22 to right side power bus;

Figure 8. Photoresistor and potentiometer connected to Arduino's analog input.
  1. Start a new Arduino sketch and enter the code shown in Figure 9.
 Example code for light sensor

int lightSensor; // declare variable for light sensor reading void setup() { // setup code that only runs once Serial.begin(9600); // initialize serial communication } void loop() { // code that loops forever lightSensor = analogRead(A0); // read the analog pin Serial.println(lightSensor); // print the reading to serial monitor }

Figure 9. Example code to take a light sensor reading using the Arduino's analog input.
  1. Upload the code to your Arduino, and leave the Arduino plugged into the USB cable. Select Tools→Serial Monitor from the top menu in your Arduino window. Make sure you select "9600 baud" from the drop-down menu in the lower right. This will give you a window that prints the readings from the analog input pin (Figure 10). Each reading should be a number between 0 (dark) and 1023 (bright).
    1. If the numbers in your serial monitor do not change, use a multimeter to measure the voltage where the photoresistor connects to the potentiometer (breadboard hole D22 in Figure 8). This voltage should vary between 0–5V as you expose the photoresistor to different amounts of light. If it does not, double check your wiring and make sure you have 5V from the Arduino.
 The Arduino serial monitor showing analog input readings, with 9600 baud selected.
Figure 10. The Arduino serial monitor showing analog input readings.
  1. Try exposing your photoresistor to different amounts of light. For example, try covering it with your finger, aiming a flashlight at it, or putting it in direct sunlight. Adjusting the potentiometer will change the range of values that you see in the serial monitor. Try to adjust it such that you can get close to the full range of values (0–1023) over the range of light intensity that you expect your robot to encounter.
  2. You now have all the pieces that you need to build an autonomous light-tracking robot! Can you program your robot to navigate based on readings from one or more light sensors? For example, try programming these different behaviors (see the next step for hints). Which behavior do you think would be best for a robot that needs to charge its batteries with solar panels?
    1. Make the robot drive towards a light source.
    2. Make the robot point itself towards a light source without driving forward.
    3. Make the robot drive around until it encounters a bright light, then stop.
  3. Depending on your level of programming experience, you may need to read more in the Arduino Language Reference. You can also ask for help in the Science Buddies Ask an Expert forums. Here are some hints and suggestions:
    1. It is bad practice to repeatedly copy and paste the same lines or sections of code. If you find yourself doing so, it is better to put that code in a function. It may be useful to make functions for basic robot movements like "driveForward" or "turnRight." Can you simplify the code you wrote to make your robot driving in a square using functions?
    2. "IF/ELSE" statements allow your program to do different things depending on whether or not certain conditions are true (for example, if a variable is above or below a certain value). Can you make your robot's motion depend on the sensor input, instead of hard-coding a certain behavior?
    3. You can change the motors' speed using the analogWrite() command (see Figure 7). In the example program the motors are set to "full speed," or 255. It might be easier to control your robot if it is not going full speed at all times.
    4. Your Bluebot kit comes with male-female jumper wires. You can use these like miniature "extension cords" for your photoresistors. This allows you to mount them at different locations on your robot's chassis instead of putting them on the breadboard (Figure 11).

A blue plastic robot chassis with two wheels, an Arduino, breadboard, and light sensors mounted on top

Figure 11. Robot chassis with light sensors mounted on the front, using male-female jumper wires as extension cords.
icon scientific method

Ask an Expert

Do you have specific questions about your science project? Our team of volunteer scientists can help. Our Experts won't do the work for you, but they will make suggestions, offer guidance, and help you troubleshoot.

Global Connections

The United Nation's Sustainable Development Goals (UNSDGs) are a blueprint to achieve a better and more sustainable future for all.
This project explores topics key to Industry, Innovation and Infrastructure: Build resilient infrastructure, promote sustainable industrialization and foster innovation.


  • Can you add solar panels and rechargeable batteries to your robot? Pre-packaged kits as well as instructions for many do-it-yourself solar charging circuits are available online. Does solar tracking behavior help your robot charge its batteries more quickly?
  • Can you use the other sensors in your Bluebot kit to program other navigation behaviors for your robot? See this autonomous robot project for ideas.


If you like this project, you might enjoy exploring these related careers:

Career Profile
Have you watched "The Transformers" cartoon series or seen the "Transformers" movies? Both shows are about how good and evil robots fight each other and the humans who get in the middle. Many TV shows and movies show robots and humans interacting with each other. While this is, at present, fantasy, in real life robots play a helpful role. Robots do jobs that can be dangerous for humans. For example, some robots defuse landmines in war-stricken countries; others work in harsh environments like… Read more
Career Profile
Just as a potter forms clay, or a steel worker molds molten steel, electrical and electronics engineers gather and shape electricity and use it to make products that transmit power or transmit information. Electrical and electronics engineers may specialize in one of the millions of products that make or use electricity, like cell phones, electric motors, microwaves, medical instruments, airline navigation system, or handheld games. Read more
Career Profile
Does the idea of harvesting the enormous power of the sun interest you? If you find this exciting, then you should think about installing solar photovoltaic panels on your house to collect free electricity from the sun. But how energy efficient is your home already? Can it get better? How many panels would your house need? What would the system look like? You can get the answers to these questions and more from your local solar energy systems engineer. These engineers help their residential and… Read more

Contact Us

If you have purchased a kit for this project from Science Buddies, we are pleased to answer your questions.

In your email, please follow these instructions:
  1. What is your Science Buddies kit order number?
  2. Please describe how you need help as thoroughly as possible:


    Good Question I'm trying to do Experimental Procedure step #5, "Scrape the insulation from the wire. . ." How do I know when I've scraped enough?
    Good Question I'm at Experimental Procedure step #7, "Move the magnet back and forth . . ." and the LED is not lighting up.
    Bad Question I don't understand the instructions. Help!
    Good Question I am purchasing my materials. Can I substitute a 1N34 diode for the 1N25 diode called for in the material list?
    Bad Question Can I use a different part?

Contact Us

News Feed on This Topic

, ,

Cite This Page

General citation information is provided here. Be sure to check the formatting, including capitalization, for the method you are using and update your citation, as needed.

MLA Style

Finio, Ben. "Build a Solar-Tracking Robot." Science Buddies, 19 Nov. 2022, https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p032/robotics/solar-tracking-robot?from=Blog. Accessed 21 Sep. 2023.

APA Style

Finio, B. (2022, November 19). Build a Solar-Tracking Robot. Retrieved from https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p032/robotics/solar-tracking-robot?from=Blog

Last edit date: 2022-11-19
Free science fair projects.