Obstacle Avoidance Robot (Pinky) – Part 3

Part 1 | Part 2 | Part 3 | Part 4 | Part 5

Ultrasonic sensor (HC-SR04) is the most important part in an obstacle avoidance robot. Before we can used the HC-SR04, we need to include the library. To do so, go to the Arduino IDE and click Sketch > Include Library > Manage Libraries and then search SR04 from gamegine.

#include <PWMServo.h>
#include <HCSR04.h>

HCSR04 hc(4,7);    // initialisation class HCSR04 (trig pin , echo pin)

PWMServo myservo;  // create servo object to control a servo
float distance;

void setup() {
  Serial.begin(9600); 
  myservo.attach(SERVO_PIN_A);  // attaches the servo on pin 9 to the servo object
  Serial.println("Test Ultrasonic + Servo Fix 90 Degree");
  myservo.write(90);
  delay(500);
}

void loop() {
  distance = hc.dist();
  Serial.print(distance);
  Serial.println("CM");
  delay(1000);
}

Obstacle Avoidance Robot (Pinky) – Part 2

Part 1 | Part 2 | Part 3 | Part 4 | Part 5

For an obstacle avoidance robot using an ultrasonic sensor (one sensor only), we can use a servo motor to do a rotation in angle. To do the rotation, we need a servo library. In Arduino IDE, there is a built-in function for servo, however, for the first time used, the library always reset my Maker Uno (I do not why! 🙂 ). Therefore, I have installed a new library (PWMServo). To do so, go to the Arduino IDE and click Sketch > Include Library > Manage Libraries and then search PWMServo.

//   Board                     SERVO_PIN_A   SERVO_PIN_B   SERVO_PIN_C
//   -----                     -----------   -----------   -----------
//   Arduino Uno, Duemilanove       9            10          (none)
//   Arduino Mega                  11            12            13
//   Sanguino                      13            12          (none)
//   Teensy 1.0                    17            18            15
//   Teensy 2.0                    14            15             4
//   Teensy++ 1.0 or 2.0           25            26            27
//   Teensy LC & 3.x                 (all PWM pins are usable)
#include <PWMServo.h>
#include <HCSR04.h>

PWMServo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600); 
  myservo.attach(SERVO_PIN_A);  // attaches the servo on pin 9 to the servo object
  Serial.println("Test Servo");
  myservo.write(90);            // Initial Position
  delay(500);
}

void loop() {
  myservo.write(90);            //90 
  delay(500);
  myservo.write(45);            //45 
  delay(500);
  myservo.write(0);             //0 
  delay(500);
  myservo.write(45);            //45 
  delay(500);
  myservo.write(90);            //90 
  delay(500);
  myservo.write(135);           //135 
  delay(500);
  myservo.write(180);           //180 
  delay(500);
  myservo.write(135);           //135 
  delay(500);
}

Obstacle Avoidance Robot (Pinky) – Part 1

Part 1 | Part 2 | Part 3 | Part 4 | Part 5

In robotics, obstacle avoidance is the task of satisfying some control objective subject to non-intersection or non-collision position constraints or in other words, an Obstacle Avoidance Robot is an intelligent robot, which can automatically sense and overcome obstacles on its path.

Before we can do an obstacle avoidance robot, we need a brain (microcontroller), robot chassis, dc motor, dc motor driver and ultrasonic sensor/infrared. However, a few things we need is a jumper wire, toggle switch (to turn ON/OFF battery) and battery.

Microcontroller

Maker Uno, an Arduino UNO compatible board designed and developed specially for students/hobbyist to learn coding and microcontroller. The best part of Maker Uno is the built-in LEDs as an indicator, a buzzer (Pin 8) and onboard programmable button (Pin 2).

Maker Uno

Robot Chassis (Including dc motor and caster)

Aluminum Chassis in Blinka purple makes for an excellent robot body. It’s a single piece of bent 2mm thick aluminum, with a variety of holes, slots and cutouts for mounting boards, sensors, and servos. The sides are notched to fit two DC Gear ‘TT’ motors perfectly.

Motor Driver

Maker Drive is a simplifying H-Bridge motor driver for beginner.

Ultrasonic Sensor

HC-SR04 is a sensor for distance measurement and object detection.
Ultrasonic sensor is created based on the principle of echolocation used by animals like bats and dolphins. Since ultrasonic sensor uses sonar to determine the distance to an object, its operation is not affected by sunlight, spotlight and object’s surface color which will affect the readings of any infrared distance sensors. However acoustically soft materials such as clothes can be difficult to detect.

Lastly, for improvement for future development, we can add a servo motor (will be discussed in Part 2) for ultrasonic rotation. Tower Pro SG90 micro servo motor is a low-cost plastic gear RC servo with 1.80kg.cm holding torque (at 4.8V). It is a perfect solution for robotic projects.

Therefore, this is a common electronic and hardware parts for developing an obstacle avoidance robot. The name of the robot is Pinky! :).