In this part of the lab, you'll adapt your BasicBot and code from Assignment 1 to build a PhotoBot that will turn to wherever there is more light. If you would rather work from solutions, download them from moodle.
Electronics and microcontroller
2 x continuous rotation servo motors
2 x photoresistors
2 x 10k ohm resistors
3 x LEDs (pick the same color)
1 x 200 ohm resistor
1 x Arduino Uno
1 x breadboard
jumper wires
Power supply and shell
1 x battery holder for 6 AA
6 x AA batteries (rechargeable is fine)
1 x snap attachment to DC power plug
1 x robot base (e.g., plate or vinyl record)
2 x wheels compatible with servo motor (e.g., thingiverse part)
2 x wheel treads (e.g., o-ring gaskets)
1 x stabilizer caster wheel
Tools
small philips head screwdriver
glue gun
Setup
Set up your project, but do not attach the USB cable.
Adapt the sketch from Assignment 1 by adding in code from your BasicBot to:
declare 2 variables of type Servo
leftServo
rightServo
declare 2 variables of type int for your stop values of each servo
leftServoStopValue
rightServoStopValue
declare 2 variables of type int for the pins to control your servos
leftServoPin (assign this the value 9)
rightServoPin (assign this the value 6)
declare and define four methods:
initServos should initialize both Servo objects
rotateLeft should rotate the bot left (counter clockwise)
rotateRight should rotate the bot right (clockwise)
stopMoving should stop moving the bot
modify your setup to invoke initServos
Additionally:
declare and define a new method rotateBot to
rotate the bot left if there is more light sensed on the left; or
rotate the bot right if there is more light sensed on the right; or
stop the bot if there is the same light on both sides
modify your loop to invoke rotateBot after invoking updateOutput
Test it out!
Being careful to manage your power supply, test out your code. Your bot should rotate according to the light. If it's brighter on the left, the bot should rotate left; on the right, and the bot should rotate right.
Upload your photoBot sketch to moodle's Lab 2 - servo motors.