Arduino autonomous robot - BennyStruktor 1 (a cat toy!)

The cat wants toys. Cool toys! A video of the toy!

 

 

How to do it:

Let´s print a robot chassi: http://www.thingiverse.com/thing:170724

And a holder for the ultransonic sensor: http://www.thingiverse.com/thing:1104187

Get some servos! https://www.kjell.com/se/sortiment/el-verktyg/elektronik/arduino/tillbeh... Futuba S3003. Nice ones! But they do not turn 360 degrees. Let´s modify it: https://www.youtube.com/watch?v=q7xL2aXacx0 (hack away the mechanical part that stops it from going around and disengage the internal potentiometer, set it to 50 %).

Mount the stuff! Connect to the Arduino board as shown in the image.

Add simple power from a 9 Volt battery. http://playground.arduino.cc/Learning/9VBatteryAdapter

Then some simple code. When something is too close, one wheel reverse direction and makes the robot turn. Do not forget to find the corredt libraries.

/*
 * BennyStruktor 1
 * A cat toy
 * */

#include <NewPing.h> // for the ultrasonic sensor
#include <Servo.h>  // for the servos

// Settings of the ultrasonic sensor
#define TRIGGER_PIN 11
#define ECHO_PIN 12
#define MAX_DISTANCE 200

// init some servos
Servo LeftServo; 
Servo RightServo;

// init the ultrasonic sensor 
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
 
void setup() 
{

   // hook up the servos
   LeftServo.attach(9);
   RightServo.attach(10);
}
 
void loop() 
{
  delay(200); // wait a little
  unsigned int uS = sonar.ping_cm(); // read the distance
  if(uS < 5) 
  {
    // Something is detected less than 5 cm in front of the robot. Turn!  
      LeftServo.write(170); // one wheel goes in opposite direction
      RightServo.write(170);
    
  }
  else
  {
    // No obstacles! Proceed forward
    LeftServo.write(170); // both wheels turn forward 
    RightServo.write(10);
    
    
  }
   
}

Tags: