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
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
andsensorRight
- In
setup()
, the sensors and servo are configured and initialized. - In
loop()
, ifsensorLeft.getState()
istrue
, it means that the left sensor is detecting strong light so wheels is controlled to turn left. - Else if
sensorRight.getState()
istrue
,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.