A ₹1,474 robot that drives toward a torch. Two light-dependent resistors (LDRs) face left and right, the sketch compares their brightness, and the wheel speeds change so the robot turns toward the brighter side. The voltage-divider readings are worked out so you know what to expect on the serial monitor.
Scope: beginner. This is a design worksheet with illustrative costs. It has not been bench-tested by this site. The divider table below was computed by script. Light levels in a room vary a lot, so the thresholds in the sketch are starting values to be tuned. It is a good first robot because the whole control law is one subtraction.
How it works
Each LDR is wired in a voltage divider with a 10 kilohm resistor. With the LDR on the 5 V side, the analog pin sees 5 V × 10k / (10k + LDR). Bright light lowers the LDR resistance, which raises the voltage. For example 1 kilohm gives about 4.55 V (reading near 930), 10 kilohm gives 2.5 V (about 512) and 100 kilohm gives about 0.45 V (about 93). The exact LDR resistances depend on your part and on the light.
The sketch takes the difference between the left and right readings. If it is smaller than a dead band the robot goes straight. If it is larger, the brighter side’s wheel is slowed and the other is sped up, so the robot curves toward the light. If both sides are dark the robot stops.
Bill of materials
| Part | Qty | Unit | Total |
|---|---|---|---|
| Arduino Uno R3 (or compatible) | 1 | ₹550 | ₹550 |
| LDR (photoresistor) | 2 | ₹15 | ₹30 |
| 10 kilohm resistors | 2 | ₹2 | ₹4 |
| L298N motor driver board | 1 | ₹180 | ₹180 |
| 2WD chassis kit with two gear motors and wheels | 1 | ₹450 | ₹450 |
| Battery holder with two 18650 cells | 1 | ₹210 | ₹210 |
| Jumper wires | 1 | ₹50 | ₹50 |
| Parts total | ₹1,474 | ||
Scroll the table sideways to see every column.
Prices checked Nov 2026. Shipping and tools are not included.
Prices are illustrative figures for Indian sellers in November 2026, before shipping, and have not been checked against current listings.
The numbers
| LDR resistance | Analog pin voltage | Reading (0 to 1023) |
|---|---|---|
| 1 kΩ (bright) | 4.55 V | 930 |
| 5 kΩ | 3.33 V | 682 |
| 10 kΩ | 2.50 V | 512 |
| 50 kΩ | 0.83 V | 170 |
| 100 kΩ (dim) | 0.45 V | 93 |
With a dead band of 40 counts, a left reading of 600 against a right reading of 580 counts as equal, and the robot drives straight. A left of 700 against a right of 500 gives a difference of 200 and a steering correction of 100 PWM steps in the sketch below.
Power and wiring
| Part | Connects to | Note |
|---|---|---|
| Left LDR divider | A0 | LDR to 5V, 10k to GND, pin at the middle |
| Right LDR divider | A1 | Same arrangement |
| L298N ENA / IN1 / IN2 | D5 / D7 / D8 | Left motor |
| L298N ENB / IN3 / IN4 | D6 / D9 / D4 | Right motor |
| Battery | L298N 12V input and Uno VIN | Check your pack voltage against the board limits |
The sketch
// Light-following robot: Uno + 2 LDR dividers + L298N
// Design worksheet: thresholds are starting values.
const int LDR_L = A0, LDR_R = A1;
const int L_EN = 5, L_IN1 = 7, L_IN2 = 8;
const int R_EN = 6, R_IN3 = 9, R_IN4 = 4;
const int BASE = 130; // forward PWM
const int DEAD = 40; // counts of difference treated as equal
const int DARK = 150; // below this on both sides: stop
const float GAIN = 0.5; // PWM steps per count of difference
void drive(int left, int right) {
left = constrain(left, 0, 255);
right = constrain(right, 0, 255);
digitalWrite(L_IN1, HIGH); digitalWrite(L_IN2, LOW);
digitalWrite(R_IN3, HIGH); digitalWrite(R_IN4, LOW);
analogWrite(L_EN, left);
analogWrite(R_EN, right);
}
void setup() {
pinMode(L_EN, OUTPUT); pinMode(L_IN1, OUTPUT); pinMode(L_IN2, OUTPUT);
pinMode(R_EN, OUTPUT); pinMode(R_IN3, OUTPUT); pinMode(R_IN4, OUTPUT);
}
void loop() {
int l = analogRead(LDR_L);
int r = analogRead(LDR_R);
if (l < DARK && r < DARK) { drive(0, 0); delay(50); return; }
int diff = l - r; // positive: light is on the left
if (abs(diff) < DEAD) {
drive(BASE, BASE);
} else {
int steer = constrain((int)(diff * GAIN), -100, 100);
drive(BASE - steer, BASE + steer); // slow the side facing the light
}
delay(20);
}If the robot turns away from the light, swap the two LDR pins or flip the sign of the steering. Matching the two LDRs matters: if one reads higher in the same light, subtract an offset measured with both lit equally. The sketch has been proofread but not compiled on this site.
Test plan
- Read the sensors: print both readings and cover each LDR in turn to see which number falls.
- Equal light test: shine a torch from straight ahead and check the readings are close; note any offset between them.
- Direction test: move the torch left and right and see which wheel slows.
- Dead band: raise or lower DEAD until the robot drives straight toward a steady light.
- Room light: try it in a dim room and then with the lights on, and note when it stops or ignores the torch.
- Following: walk with the torch and see how closely it follows at slow speed.
What usually goes wrong
| Symptom | Likely cause | Fix |
|---|---|---|
| Turns away from the light | LDR pins or steering sign reversed | Swap the pins or flip the steer sign |
| Weaves from side to side | Gain too high or dead band too small | Lower GAIN, raise DEAD |
| Never moves | Both readings below DARK | Lower DARK or use a brighter torch |
| Drives past the light | No stop condition | Stop when both readings pass a bright threshold |
| Ignores the torch in a bright room | Room light swamps the torch | Shade the LDRs with short tubes |
Upgrades
- Stop at the light: halt when both readings are above a bright value.
- Shaded tubes: add tubes in front of each LDR for a narrower view.
- Light avoider: reverse the steering to run away from light.
- Light logger: print readings and plot how the beam looks from the robot.
Cost and parts notes
The ₹1,474 total is an illustration and does not include shipping. Use the cost calculator to compare sellers.
Common questions
What is an LDR?
A light-dependent resistor, a part whose resistance falls as more light hits it.
Why a voltage divider?
The Arduino reads voltage, not resistance, so the divider turns the changing resistance into a changing voltage.
Can it follow sunlight?
Sunlight is very bright and may saturate both sensors, so the robot will not steer. Shading tubes help.
How do I make it faster?
Raise BASE in small steps and retune GAIN.
Last reviewed: November 2026. This is a design worksheet with illustrative costs. It has not been bench-tested by this site; library names, pins and limits must be checked against your board and the current library versions, and measurements from your build are welcome.