Anip Shah
Published © MIT

Light Tracker Bot

Arduino interfaced with a couple of photo resistors (LDR), mounted over servo motor tracks light and makes an angular motion toward it.

BeginnerFull instructions provided1 hour278
Light Tracker Bot

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
LDR, 5 Mohm
LDR, 5 Mohm
×2
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Resistor 10k ohm
Resistor 10k ohm
×2

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematics

Note the LDRs are mounted on the top of servo motor.

Code

Servo & LDRs

C/C++
#include <Servo.h>
#define LDR1 A0
#define LDR2 A1

#define error 10
int Spoint = 0;

Servo servo;

void setup() {
  servo.attach(11);
  Spoint = constrain(Spoint, 0, 180);
  servo.write(Spoint);
  delay(1000);
}

void loop() {
  int ldr1 = analogRead(LDR1);
  int ldr2 = analogRead(LDR2);
  int servoPosition1 = map(ldr1, 0, 1023, 0, 180);
  int servoPosition2 = map(ldr2, 0, 1023, 0, 180);
  
  if (abs(ldr1 - ldr2) <= error) {
    
  } else {
    
    if (ldr1 > ldr2) {
      Spoint = constrain(Spoint - 3, 0, 180); 
      
    } else {
      Spoint = constrain(Spoint + 3, 0, 180); 
    }
  }

  servo.write(Spoint);
  delay(40); 
}

Credits

Anip Shah

Anip Shah

9 projects • 4 followers
Tech enthusiast and programmer who also happens to be a Biomedical Engineer.

Comments