top of page

Light Following 
Robot

A light-following robot is an autonomous system that uses light sensors to detect and move toward a bright light source. This project involves using photoresistors (light-dependent resistors, or LDRs) to sense light intensity, which the Arduino Uno processes to control the movement of motors. The robot can be used for educational purposes, showcasing how sensors and actuators can interact in robotics.

Materials Anchor

Materials

Light Following
Robot

1) Arduino UNO:

  • A central microcontroller that processes sensor signals and controls the motor driver and supplies power to the peripherals.

​​

2) L9110 Motor Driver Module:

  • A compact, low-voltage dual-channel motor driver that controls the speed and direction of the motors while seamlessly interfacing with small DC motors.

​​

3) Photoresistor Modules (LDRs) (x3):

  • Cost-effective analog light sensors that detect light intensity changes, providing reliable input to guide the robot's movement.

​​

4) 5 AA Battery Pack (2):

  • A portable 7.5V power source for the Arduino, motors, and sensors, with an integrated switch for convenient power management.

​​

5) TT DC Motors (2x):

  • Lightweight, low-voltage motors that drive the robot’s wheels, ideal for small robotics projects and compatible with the motor driver.

​​

6) Wheels (2x):

  • Lightweight, durable wheels with stable grip for smooth movement, designed to attach easily to motor shafts.

​​

7) Castor Wheel:

  • A low-friction, free-rotating wheel that balances the chassis, enabling smooth directional changes and weight support.

​​

8) Jumper Wires:

  • Durable, reusable wires in various lengths for flexible electrical connections between components.

​​​​​

9) Breadboard:

  • A reusable platform for prototyping circuits, allowing easy connection and rearrangement of components without soldering.

​​

10) Chassis:

  • A lightweight yet durable frame made of plastic, designed to hold and support all robot components securely.

​​

111) ON/OFF Switch:

  • A toggle switch for managing the robot’s power, enabling quick and easy activation or shutdown.

​​

12) Screws, Nuts, and Bolts:

  • Small hardware pieces that securely mount components onto the chassis, ensuring stable and durable assembly.

​​

13) USB Cable:

  • A standard USB Type A to Type B cable for programming the Arduino and providing temporary power during testing.

Setup Anchor

Basic Setup

1) Light Sensors (LDRs):
Light-dependent resistors (LDRs) detect light intensity and are paired with resistors to form voltage divider circuits. This setup converts light levels into measurable voltages for the Arduino.

​

Circuit Details:

  • VCC pin ( '+' ): Connect to Arduino Uno 5v pin. 

  • GND pin ( '-' ): Connect to Arduino Uno GND pin

  • Left LDR signal pin ( 'S' ): Connect to Analog pin 0

  • Middle LDR signal pin ( 'S' ): Connect to Analog pin 1

  • Right LDR signal pin ( 'S' ): Connect to Analog pin 2

​

Placement:

  • Mount the LDRs on opposite sides of the robot, near the front, with one in the middle.

  • Angle the outer LDRs slightly outward to better detect light from different directions.

​

2) Motor Driver Module (L9110):
The L9110 motor driver interfaces the Arduino Uno with the DC motors, controlling speed and direction while isolating the motors to protect the Arduino from excessive current draw.

​

Connections to Arduino Uno:

​

Power Supply:

  • GND Pin: Connect to the Arduino Uno GND pin for a common ground.

  • B-1 Pin (Motor A Direction 1): Connect to Digital Pin 3.

  • B-2 Pin (Motor A Direction 2): Connect to Digital Pin 4.

  • A-1 Pin (Motor B Direction 1): Connect to Digital Pin 5.

  • A-2 Pin (Motor B Direction 2): Connect to Digital Pin 6.

​

Connections to Motors:

  • Connect the terminals of Motor A to the Motor A output terminals on the motor driver board (e.g., A-1 and A-2).

  • Connect the terminals of Motor B to the Motor B output terminals on the motor driver board (e.g., B-1 and B-2).

  • Connect the motor driver’s power input pins (VCC and GND) to the battery pack to power the motors.

​

3) DC Motors:
The motors drive the robot's wheels, with one motor controlling each side for independent movement and turning capability.

​

Motor Placement:

  • Attach one motor on each side of the chassis using brackets or screws.

  • Securely fix wheels to the motor shafts to ensure they spin freely without wobble.

​

Powering Motors:

  • The motors receive power from the motor driver, which is connected to the external battery pack.

  • Ensure the motor driver’s GND pin is connected to the Arduino’s GND pin for consistent operation.

​

4) Chassis and Wheels:
The chassis forms the base of the robot, holding all components in place, while the wheels provide movement and stability.

​

Chassis:

  • Use a sturdy, flat platform with sufficient space for mounting the Arduino, motor driver, battery pack, and LDRs.

  • Arrange components to distribute weight evenly for balanced movement.

​

Wheels:

  • Attach two wheels to the DC motors for propulsion.

  • Install a castor wheel or ball caster at the rear of the chassis to stabilize the robot and allow smooth directional changes.

​

5) Power Supply (2 x 5xAA battery packs):

Using two 5x AA battery packs is an effective way to power the robot because it separates the power supply for the motors and the Arduino, ensuring stable operation. The motor driver and motors can draw significant current, causing voltage drops that could destabilize the Arduino if they share the same supply. By using one battery pack for the motor driver and another for the Arduino, we can extend runtime, maintain consistent voltage levels for each component, and reduce the risk of overheating or performance issues caused by fluctuating power demands.

​

Motor Driver:

  • Use a 5 AA battery pack (7.5V) to power the motor driver and motors.

  • Connect the positive and negative terminals of the battery pack to the VCC and GND pins on the motor driver.

​

Arduino Power:

  • Use a 5 AA battery pack (7.5V) to power the Arduino which will run the peripherals

  • Connect the positive and negative terminals of the battery pack to the Vin and GND pins on the Arduino.

​

6) Wiring Check:
Ensure:

  • All GND connections (motor driver, Arduino, LDRs, and motors) are linked to a common ground.

  • Connections are tight and secure to avoid inconsistent operation.

  • Wires have enough slack to prevent strain but are not so loose as to interfere with moving parts.

Code
code.png

CODE BREAK-DOWN

Code Break Down

#include <Servo.h>

  • Includes the Servo library, which provides functions to control servo motors.

​

Servo panServo;

  • Creates a Servo object named panServo to control the pan (horizontal) motion.

​

Servo tiltServo;

  • Creates a Servo object named tiltServo to control the tilt (vertical) motion.

​

const int joystickX = A0;

  • Defines the analog pin A0 as joystickX for reading the joystick's X-axis input.

​

const int joystickY = A1;

  • Defines the analog pin A1 as joystickY for reading the joystick's Y-axis input.

​

void setup() {

  • Defines the setup() function, which runs once when the program starts.

​

panServo.attach(9);

  • Attaches the pan servo motor to digital pin 9 on the Arduino Uno.

​

tiltServo.attach(10);

  • Attaches the tilt servo motor to digital pin 10 on the Arduino Uno.

​

pinMode(joystickX, INPUT);

  • Configures the joystick's X-axis pin as an input to read analog signals.

​

pinMode(joystickY, INPUT);

  • Configures the joystick's Y-axis pin as an input to read analog signals.

​

}
Ends the setup() function.

​

void loop() {

  • Defines the loop() function, which runs repeatedly after the setup() function.

​

int xVal = analogRead(joystickX);

  • Reads the analog value from the joystick's X-axis (0–1023) and stores it in xVal.

​

int yVal = analogRead(joystickY);

  • Reads the analog value from the joystick's Y-axis (0–1023) and stores it in yVal.

​

int panAngle = map(xVal, 0, 1023, 0, 180);

  • Maps the joystick's X-axis value from its range (0–1023) to a servo angle range (0–180 degrees) and stores it in panAngle.

​

int tiltAngle = map(yVal, 0, 1023, 0, 180);

  • Maps the joystick's Y-axis value from its range (0–1023) to a servo angle range (0–180 degrees) and stores it in tiltAngle.

​

panServo.write(panAngle);

  • Moves the pan servo motor to the angle specified by panAngle.

​

tiltServo.write(tiltAngle);

  • Moves the tilt servo motor to the angle specified by tiltAngle.

​

delay(15);

  • Introduces a short delay of 15 milliseconds to allow the servo motors to reach their target positions smoothly.

​

}
Ends the loop() function.

bottom of page