Spy on your cat with this robot camera. Mount the camera robot and control it with a small joystick. You can watch the camera image on the computer and when you see your cat doing something suspicious, take a picture!
Materials
- 1 Arduino Uno board
- 1 Education Shield
- 1 web camera
- 1 TinkerKit joystick
- 2 standard servos
- 2 TinkerKit wires
- 3 jumper wires
- 8 AA batteries
- 1 AA battery holder
- 1 power plug
- Robot camera kit
Instructions
Code
Find the code in File>Examples>EducationShield>Block4-Robots>Projects>CameraRobot
Find the Processing code in File>Examples>EducationShield>Block4-Robots>Projects>CameraRobot>Processing>CameraRobot
How it works
- The EducationShield and Servo libraries are included.
- The Joystsick and Servo objects are declared.
- The variables to be used to set the servo positions are declared,
panAngle
andtiltAngle
. - The variables to be used to store the joystick values in are declared,
panJoystick
andtiltJoystick
. - In
setup()
, the servo objects are initialized. - In
loop()
, the joysticks x value is read and stored inpanJoystick
. - The joysticks y value is read and stored in
tiltJoystick
. - If
panJoystick
is not equal to 0, it means that the joystick is moved in the x axis and the following will happen.- If
panJoystick
is equal to 1 andpanAngle
is less than 180,panAngle
is increased with 1. - Else if
panJoystick
is equal to -1 andpanAngle
is more than 0,panAngle
is decreased with 1.
- If
- The next if statement in
loop()
checks iftiltJoystick
is not equal to 0. If that is true, the following happens.- If
tiltJoystick
is equal to 1 andtiltAngle
is less than 180,tiltAngle
is increased with 1. - Else if
tiltJoystick
is equal to -1 andtiltAngle
is more than 0,tiltAngle
is decreased with 1.
- If
- The position of the pan servo is set with
panAngle
. - The position of the tilt servo is set with
tiltAngle
. - The program pauses for 5 milliseconds to give the servos some time to move into place.
loop()
continues to loop.
Troubleshooting
- Refer to the illustration and double check your connections. Make sure the shield and jumper wires are firmly connected.
- Make sure you connected the servos correctly. See the reference to make sure the servos work.
- Make sure you have connected the joystick correctly. See the reference to make sure it works.
Learn by doing
- The servos might be moving too slow or too fast. Change the delay in the end of loop or change the increasing and decreasing steps of the angles.
- The servos might be moving too far to the sides, or too far up and down. Limit the angles allowed.
- Build something else with the same pan tilt structure that you control with the joystick.