Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Flashlight Controlled Solar Powered Robot using Arduino

By Willie Watson September 8, 2024

 

This project is a light gradient-sensitive robot with solar charging capabilities. In other words, it seeks out the light to charge itself. It accomplishes this behavior with four light-sensitive photoresistors in voltage divider circuits; the Arduino unit reads the four values corresponding to the intensity of the light received by the sensors through its analog read pins. It then applies a high voltage across a reed switch, which completes a circuit between a 9v battery and two toy motors, resulting in turning or moving towards the light.

 

Prototype of Arduino based Solar Powered Light Controlled Robotic Tank

Fig. 1: Prototype of Arduino based Solar Powered Light Controlled Robotic Tank

These motors were not able to be activated directly with the Arduino, if you get small enough motors, the switching portion of this project may be omitted without loss of functionality.If any of the four photodiodes is registering much higher than the others, it detects which photodiode is receiving the heightened signal and turns or moves in that direction for as long as the heightened signal is being received. This light tracking algorithm can be used to program solar panels to track on the sun, or for control of robot via flashlight, as is demonstrated here. For this project reader needs knowledge of getting start with arduino.

Pictures and diagrams of the full circuit board would be a bit messy in this case, thus I have boxed the main components which are repeated 4 and 2 times respectively in the actual project. The first circuit subsystem is the voltage divider based on a photoresistor which is repeated four times, with each photoresistor being placed on a different side of your robot. Aphotoresistor varies resistance based on light signal received via the photoconductivity of the receiving semiconductor material. The variable resistance produces a variable current in the circuit according to Ohm’s law, V=iR where the voltage V is constant (5V). Be careful not to make the wires leading to any one photodiode excessively long, as you can lose signal due to the internal resistance of the wire and soldering connections. Voltage is supplied to this portion of the circuit directly from the Arduino UNO’s 5V / Gnd pins. The 5V line passes through a 10k Ohms resistor, through the photodiode, and back to ground. An analog in signal is read from between the resistor and the photodiode via Arduino analog in pins. An optional addition is the indicator LED shown going from the other side of the resistor (positive) to ground (negative), this LED will change intensity based on the signal received by the photodiode. If these LED’s are too close to one of the photodiodes, your machine can enter a kind of analog feedback loop in that direction, where it spins in the direction of its own LEDs. I believe I have coded against this possibility, but if you are seeing that behavior, try taking the LEDs out as they are useful only while debugging this portion of the circuit. Four analog in pins should be connected to four iterations of this circuit block. In principle you can increase the number of iterations for increased directional sensitivity, but this is not necessary for this application. The sketch that goes with this project is sensitive to a difference in received light intensity, if all the signals received are very similar, the robot will continue to sample its environment, but remain stationary. As soon as any of the signals is greater than the others by a threshold value, the program enters its motion loop. It determines which photoresistor is receiving the maximum signal and then applies current to the motor which moves the robot in the correct corresponding direction. This action continues as long as that photoresistor is receiving maximum intensity, and there is a great enough difference between the read values.

Image showing circuit connections of Photo resistor on Robotic Tank for detection of Flashlight

Fig. 2: Image showing circuit connections of Photo resistor on Robotic Tank for detection of Flashlight

The second blocked portion of the circuit is only necessary if you need more power to the motors then the Arduino can supply directly from its PWM output pins. My chassis / tracks / motor is from a Chinese toy, the Arduino was having trouble driving the motors with the tracks on, so I built in a switching block to the circuit that allows the PWM output to flip a reed relay that completes a circuit to a 9V battery. The reed relay works via an electromagnet which when activated by the lower current (Arduino) causes the contact points within the switch to become magnetized and close the circuit. In principle you can drive very large electric motors with this concept by selecting the correct reed relay. I did not need much more power, so a 9V battery was plenty, the switch I used is in the parts lest section. Since this component is operated via electromagnetic field, a transient protection diode is necessary, since the collapsing magnetic field (when the switch is turned off) can cause a current spike to travel back towards the Arduino as predicted by Maxwell’s equations. A good discussion on how to implement this particular reed relay switch without causing damage to your board can be found here.

Image showing circuit connections of Battery wires on Robotic Tank

Fig. 3: Image showing circuit connections of Battery wires on Robotic Tank

This portion of the circuit is repeated twice corresponding to two motors, and as stated, if you are able to power your motors directly with Arduino, you may omit this portion of the project without loss of functionality.

Circuit Diagrams & Components Used

Circuit Diagram

Voltage Divider

Circuit Diagram of Voltage Divider Network used for detection of Flashlight

Fig. 4: Circuit Diagram of Voltage Divider Network used for detection of Flashlight

Switching Circuit

Circuit Diagram of DC Motor Controller used for light guided navigation of Robotic Car

Fig. 5: Circuit Diagram of DC Motor Controller used for light guided navigation of Robotic Car

Please refer Circuit Diagram Tab for Complete Circuit used in the Project

Components Used

Arduino UNO

4x Resistor, 10 K Ohms

4x Photo Light Sensitive Resistor Photo Resistor, Opto Resistor 5mm GL5516 5516

4x  LED

RadioShack® 1.5W Solar Panel 9V

Toy tracks / platform / motors (2)

2x Reed Switches (OMR-C-105H)

You may also like:


  • What are the top development boards for AI and ML?

  • What are LoRa gateways and what types are available?

  • What battery chemistries are used in electric vehicles?

  • What are the different types of EV charging connectors?

  • What are the components of robotic arms and industrial robots?
  • battery selection low power design
    What are the battery-selection criteria for low-power design?

Project Source Code

###

constintfrontPin = A0;
constintleftPin = A1;
constintrightPin = A2;
constintbackPin = A3;
constintleftMotor = 9;
constintrightMotor = 10;
intthreshHold = 170;
int Direction;
int direction1;
int direction2;
int Delay = 25;
int Delay2 = 25;

void setup()
{

pinMode(frontPin, INPUT);
pinMode(leftPin, INPUT);
pinMode(rightPin, INPUT);
pinMode(backPin, INPUT);
pinMode(leftMotor, OUTPUT);
pinMode(rightMotor, OUTPUT);
digitalWrite(leftMotor, HIGH);
digitalWrite(rightMotor,HIGH);
delay(100);
digitalWrite(leftMotor, LOW);
digitalWrite(rightMotor, LOW);
delay(100);
digitalWrite(leftMotor, HIGH);
digitalWrite(rightMotor, HIGH);
delay(100);
digitalWrite(leftMotor, LOW);
digitalWrite(rightMotor, LOW);
delay(1500);
Serial.begin(9600);  
}

void loop()
{

int Direction;
int direction1;
int direction2;
intfrontSignal = 1023 - analogRead(frontPin);
intleftSignal = 1023 - analogRead(leftPin);
intrightSignal = 1023 - analogRead(rightPin);
intbackSignal = 1023 - analogRead(backPin);
Serial.println(frontSignal); 
Serial.println(leftSignal); 
Serial.println(rightSignal); 
Serial.println(backSignal);
// frontSignal + leftSignal + rightSignal + backSignal<= threshHold
if (abs(frontSignal-leftSignal)+abs(frontSignal-rightSignal)+abs(frontSignal-backSignal) >= threshHold )
{
Serial.println("motion loop");
                     direction1 = max(frontSignal, leftSignal);
                     direction2 = max(rightSignal, backSignal);
                      Direction = max(direction1, direction2);
//Loop here is entered only if the light received is not evenly distributed.
     if (frontSignal == Direction)
     {
                   do
                   {
                         digitalWrite(leftMotor, HIGH);
                         digitalWrite(rightMotor, HIGH);
                         delay(Delay2);
                         digitalWrite(leftMotor, LOW);
                         digitalWrite(rightMotor, LOW);
                         delay(Delay);
                         frontSignal = 1023 - analogRead(frontPin);
                         leftSignal = 1023 - analogRead(leftPin);
                         rightSignal = 1023 - analogRead(rightPin);
                         backSignal = 1023 - analogRead(backPin);
                         direction1 = max(frontSignal, leftSignal);
                         direction2 = max(rightSignal, backSignal);
                         Direction = max(direction1, direction2);
                         Serial.println("Forward");
          
                   } while(frontSignal == Direction && abs(frontSignal-leftSignal)+abs(frontSignal-rightSignal)+abs(frontSignal-backSignal) >= threshHold);
           digitalWrite(leftMotor, LOW);
           digitalWrite(rightMotor, LOW); 
     }
     else if (leftSignal == Direction)     //Signal is greatest on the left
     {
                             do
                 {
                       Serial.println("Left");
                       digitalWrite(rightMotor, HIGH);
                       delay(Delay2);
                       digitalWrite(rightMotor, LOW);
                       delay(Delay);
                       frontSignal = 1023 - analogRead(frontPin);
                       leftSignal = 1023 - analogRead(leftPin);
                       rightSignal = 1023 - analogRead(rightPin);
                       backSignal = 1023 - analogRead(backPin);
                       direction1 = max(frontSignal, leftSignal);
                       direction2 = max(rightSignal, backSignal);
                       Direction = max(direction1, direction2);
                 } while(leftSignal == Direction && abs(frontSignal-leftSignal)+abs(frontSignal-rightSignal)+abs(frontSignal-backSignal) >= threshHold);
          digitalWrite(rightMotor, LOW);
     }
     else if (rightSignal == Direction)        //Signal is greatest on the right.
     {
               do
               {
                     Serial.println("Right");
                     digitalWrite(leftMotor, HIGH);
                     delay(Delay2);
                     digitalWrite(leftMotor, LOW);
                     delay(Delay);             
                     frontSignal = 1023 - analogRead(frontPin);
                     leftSignal = 1023 - analogRead(leftPin);
                     rightSignal = 1023 - analogRead(rightPin);
                     backSignal = 1023 - analogRead(backPin);
                     direction1 = max(frontSignal, leftSignal);
                     direction2 = max(rightSignal, backSignal);
                     Direction = max(direction1, direction2);
                    
               } while(rightSignal == Direction && abs(frontSignal-leftSignal)+abs(frontSignal-rightSignal)+abs(frontSignal-backSignal) >= threshHold);
               digitalWrite(leftMotor, LOW);
     }
     else if (backSignal == Direction)      //Signal is greatest behind.
     {
               do
               {
                     Serial.println("Back");
                     digitalWrite(leftMotor, HIGH);
                     delay(Delay2);
                     digitalWrite(leftMotor, LOW);
                     delay(Delay);             
                     frontSignal = 1023 - analogRead(frontPin);
                     leftSignal = 1023 - analogRead(leftPin);
                     rightSignal = 1023 - analogRead(rightPin);
                     backSignal = 1023 - analogRead(backPin);
                     direction1 = max(frontSignal, leftSignal);
                     direction2 = max(rightSignal, backSignal);
                     Direction = max(direction1, direction2);
               } while(backSignal == Direction && abs(frontSignal-leftSignal)+abs(frontSignal-rightSignal)+abs(frontSignal-backSignal) >= threshHold);
               digitalWrite(leftMotor, LOW);
     }
}
else if(abs(frontSignal-leftSignal)+abs(frontSignal-rightSignal)+abs(frontSignal-backSignal) <= threshHold)
{
             int difference = abs(frontSignal-leftSignal)+abs(frontSignal-rightSignal)+abs(frontSignal-backSignal);
             Serial.println("Signal differential is equal to ");
             Serial.println(difference);
             digitalWrite(leftMotor, LOW);
             digitalWrite(rightMotor, LOW);
             delay(1000); // Else sample environment at a rate of 10 hz
}
else
{
             digitalWrite(leftMotor, LOW);
             digitalWrite(rightMotor, LOW);
}

} 

###

 


Circuit Diagrams

Circuit-Diagram-Arduino-Based-Solar-Powered-Flash-Light-Controlled-Robotic-Tank

Project Video


Filed Under: Electronic Projects
Tagged With: Arduino, robot, solar
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Disappearing clock
  • How to best test Electrolytic capacitors for premature failure reduced life?
  • 12VAC to 12VDC 5A on 250ft 12AWG
  • TMP117 > Can not read temperature on LCD
  • LDO simulation by pcb

RSS Electro-Tech-Online.com Discussions

  • Electronic board faulty?!?
  • Is there a Power Bank that can also be charged with electricity?
  • applying solder paste from a jar
  • Did a Buyer Kill My Amp?
  • An Update On Tarrifs

Featured – Designing of Audio Amplifiers part 9 series

  • Basics of Audio Amplifier – 1/9
  • Designing 250 Milli Watt Audio Power Amplifier – 2/9
  • Designing 1 Watt Audio Power Amplifier – 3/9
  • Designing a Bass Boost Amplifier – 4/9
  • Designing a 6 Watt Car Audio Amplifier – 5/9
  • Design a low power amplifier for headphones- 6/9

Recent Articles

  • Sienna Semiconductor data converters feature sample rates from 20 to 250 Msps
  • Delta’s 5,500 W power supplies achieve 97.5% energy efficiency for AI servers
  • Novosense Microelectronics releases digital isolators with capacitive-based design
  • MIPI C-PHY adds encoding option to support next-gen image sensor applications
  • Littelfuse gate driver delivers 1.9 A source and 2.3 A sink output current

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe