Light chaser

This little vehicle is on an impossible, never ending mission to catch the light. You can make it follow you by pointing a flashlight at it, e.g., the one on your mobile phone. It will always turn towards the light.

Materials

  • 1 Arduino Uno board
  • 1 Education Shield
  • 2 LDRs
  • 2 continuous rotation servos
  • 2 1k ohm resistors
  • 1 100 µF capacitor
  • 2 black jumper wires
  • 6 colored jumper wires
  • 8 AA batteries
  • 1 AA battery holder
  • 1 power plug
  • Light Chaser kit
  • 1 ping pong ball

Instructions

  1. Attach the shield onto the top of the Arduino board.
  2. Connect a 1K ohm resistor across the breadboard gap. Connect one leg to analog pin A0 and the other to GND.
  3. Connect an LDR between analog pin A0 and 5V. Place it on the left side of the Light chaser.
  4. Connect another 1K resistor across the breadboard gap. Connect one leg to A2 and the other to GND.
  5. Connect a second LDR between A2 and 5V. Place it on the right side of the Light chaser.
  6. Connect the 100 µF capacitor between GND and 5V. Connect the short leg to GND and the long one to 5V.
  7. Connect the assembly to the computer and upload the example ‘LightChaser’.
  8. Assemble the Light chaser.
  9. Connect the left continuous rotation servo to D10.
  10. Connect the right continuous rotation servo to D9.
  11. Place the electronics in the Light chaser. Make the LDRs point outward from the vehicle.
  12. Place the batteries in the battery holder and use a power plug to connect it to the Arduino power socket.

Code

Find the code in File>Examples>EducationShield>Block4-Robots>Projects>LightChaser

How it works

  • The EducationShield and Servo libraries are included.
  • The Wheels and LDR objects are declared, wheels, sensorLeft and sensorRight
  • In setup(), the sensors and servo are configured and initialized.
  • In loop(), if sensorLeft.getState() is true, it means that the left sensor is detecting strong light so wheels is controlled to turn left.
  • Else if sensorRight.getState() is true, wheels is instead controlled to turn right.
  • If neither of the sensors are detecting strong light, wheels is controlled to move forward.
  • loop() continues to loop.

Troubleshooting

  • Refer to the illustration and double check your connections. Make sure the shield and jumper wires are firmly connected.
  • If the light chaser is not turning towards light, see LDR reference about how to debug LDRs.
  • If the motors are not working or the Light chaser is not going straight, see the reference about how to debug servo motors.

Learn by doing

  • You can turn it into a “Vampire Vehicle” so that it runs away from light.
  • Modify the example so the Light chaser only moves when there is a light pointed at it.