Camera robot

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

  1. Attach the shield onto the top of the Arduino board.
  2. Connect a TinkerKit wire to the joystick connector labeled as ‘Y’. Connect a red jumper wire to the red wire of the TinkerKit wire, and to 5V. Connect a black jumper wire to the black wire of the TinkerKit wire and to GND. Connect the last jumper wire to the TinkerKit wire and analog pin A0.
  3. Connect the second TinkerKit wire to the joystick connector labeled as X and to the analog TinkerKit connector, A1.
  4. Connect the assembly to a computer and upload example ‘CameraRobot’.
  5. Build the kit, do not forget to put the web camera inside!
  6. Turn the servo by hand until it reaches the end. Turn it by hand to a 90 degrees position. Fix the rod-shaped arm along the servo. Do the same with the other servo.
  7. Connect the side servo to D10.
  8. Connect the pan servo to D9.
  9. Connect the battery pack to the power socket.
  10. Connect the web camera to your computer. Open the Processing sketch called CameraRobot and run it.

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 and tiltAngle.
  • The variables to be used to store the joystick values in are declared, panJoystick and tiltJoystick.
  • In setup(), the servo objects are initialized.
  • In loop(), the joysticks x value is read and stored in panJoystick.
  • 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 and panAngle is less than 180, panAngle is increased with 1.
    • Else if panJoystick is equal to -1 and panAngle is more than 0, panAngle is decreased with 1.
  • The next if statement in loop() checks if tiltJoystick is not equal to 0. If that is true, the following happens.
    • If tiltJoystick is equal to 1 and tiltAngle is less than 180, tiltAngle is increased with 1.
    • Else if tiltJoystick is equal to -1 and tiltAngle is more than 0, tiltAngle is decreased with 1.
  • 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.