You are currently viewing Bunny Simple 2-axis Servo Robotic Arm

Bunny Simple 2-axis Servo Robotic Arm

Bunny Simple 2-axis Servo Robotic Arm

A Bunny is a robot that virtually intelligent capable of carrying out cute interactions on stimulus. In this project, we design a robotic arm which is very much similar to a robotic pet hand using an Arduino UNO, sg90 micro servo, and also an 0.96” OLED display. The servos are motors that rotate to a certain degree and we can program it to do certain movements to give the bunny robot a life-like feel. 
So here in this tutorial, you’ll be able to use and program servos and an OLED display.

Requirements :
● Computer with an internet connection
● Download and install Arduino IDE

Components

0.96 inch OLED display(SSD1306)

Micro Serov SG90

Arduino UNO

IR sensor

IR Proximity Sensor

mini breadboard

Breadboard

Jumper wires

Hardware

ARDUINO UNO

Although there are many types of boards from arduino . Here we are going to be using the Arduino UNO as it is the most commonly used one. The arudino UNO has :

  • The operating voltage is 5V
  • The recommended input voltage will range from 7v to 12V
  • Digital input/output pins are 14
  • Analog i/p pins are 6
  • DC Current for each input/output pin is 40 mA
  • Flash Memory is 32 KB
  • SRAM is 2 KB
  • EEPROM is 1 KB
  • CLK Speed is 16MHz

Another wonderful feature of the arduino is the option of using a add-on boards to the arduino which comes as a module and they are known as “Shields”

Pin out diagram
Arduino UNO

Micro Servo Motor

Micro servo motors provide precise control of linear and angular position, velocity, and acceleration. They are useful in many robotics projects, such as for turning the front wheels on an RC model for steering or pivoting a sensor to look around on a robotic vehicle.

Servo is a general term for a closed-loop control system which consists of a suitable motor, couple to a sensor for position feedback signal, in order to adjust the speed and direction of the motor and to achieve the desired result

RC servo motor works on the same principle. It contains a small DC motor connected to the output shaft through the gears.
A servo motor works with a small DC motor connected to the output shaft through the gears. The output shaft drives a servo arm which is connected to the potentiometer (pot). The potentiometer provides position feedback to the servo control unit where the current position of the motor compared to the target position.
According to the error, the control unit corrects the actual position of the motor so that it matches the target position.

How Servo Motors Work?

A servo motor can be controlled by sending a series of signal pulses to the signal. A conventional analog servo motor can receive a pulse roughly every 20 milliseconds (i.e. signal should be 50Hz). The position of the servo motor determines the length of the pulse.

  • If the pulse is high for 1ms, then the servo angle will be zero.
  • If the pulse is high for 1.5ms, then the servo will be in its center position.
  • If the pulse is high for 2ms, then the servo will be at 180 degrees.

In this servo motor, the pulses ranging between 1ms and 2ms will rotate the servo shaft to full 180 degrees of its travel.

 

0.96" inch OLED display (SSD1306)

Pin Wiring to Arduino Uno

Vin-5V     GND-GND    SCL-A5   SDA-A4

Introducing the 0.96 inch OLED display

This is a 0.96″ inch OLED display which we can use to connect to an arduino so we can display an output .We can interface using an SPI/I2C protocol. This is a very advanced module if you look in terms of features .It has HIGH brightness , HIGH viewing angles ,LOW power consumption , and a very THIN formfactor .It also has a very HIGH resolution (128*64 pixels) . It doesnt need a backlight like the LCD display .It takes around 0.06 W for a normal operations.

The module we are using here has 4 pins and we will be communicationg with it using I2C protocol with the arudino .
there are models which comes with an extra RESET pin /There are also ones which communicate with SPI protocol.

Circuit Diagram

Wire up the OLED, servo, IR proximity Sensor
With Arduino

 

STEP1:

Wire up the Servo Module (Pitch) 

  • Relay VCC -> Arduino Vcc
  • Reay GND -> Arduino GND
  • servo Signal -> Arduino Digital Pin 10

Wire up the Pitch Module (Pitch) 

  • Relay VCC -> Arduino Vcc
  • Reay GND -> Arduino GND
  • Servo Signal -> Arduino Digital Pin 9

STEP 2:

Wire up the IR Proximity Module Module  

  • Relay VCC -> Arduino Vcc
  • Reay GND -> Arduino GND
  • servo Signal -> Arduino Digital Pin 7

STEP3:

CONNECTING  0.96 inch OLED display 

OLED display uses the I2C communication protocol. Connect the OLED to the Arduino Uno I2C pins as below

Pin Wiring to Arduino Uno

OLED Vin         5V

OLED GND      GND

OLED SCL        A5

OLED SDA       A4

Getting started with Arduino

Before starting any project, we need to interface Arduino with computer. So we have to write and compile code for the Arduino to execute, as well as providing Arduino to function with computer.

Installing The Arduino Software Package On Windows

Download a version of Arduino software suitable for your version of Windows from Arduino website / superkitzs.com. After downloading, check the instructions below to install the Arduino Integrated Development Environment(IDE).

Download Arduino IDE

 

 

Connect your Arduino Uno board with an A B USB cable; sometimes this cable is called a USB printer cable.

 

Install the board drivers if you experience any trouble else continue with rest of steps:

If you used the Installer, as soon as you connect your board the Windows – from XP up to 10 – will install drivers automatically

If the board is not properly recognized when the zip package is downloaded and expanded, please follow the procedure below.

  • START menu> CONTROL PANEL MENU
  • From the control panel, check for System and Security
  • Select system
  • Select Device Manager from the System window
  • Select open port named “Arduino UNO (COMxx)”, under Ports (COM & LPT). If there is no COM & LPT section, check “Other Devices” for “Unknown Device”.
  • Choose the “Update Driver Software” option by right-clicking on the “Arduino UNO (COmxx)” port
  • Navigate to the “Browse my computer for Driver software” option.
  • Choose the driver file named “arduino. inf”, located in the “Drivers” folder of the Arduino Software download (not the “FTDI USB Drivers” sub-directory). If you are using an old version of the IDE (1.0.3 or older), Choose the Uno driver file named “Arduino UNO.inf”, If an old version of the IDE (1.0.3 or older) is used
  • Thus the windows driver installation is completed

 1.Install u8glib as ZIP file in Arduino IDE

Repeat the above process for the u8glib  library is available as a downloadable ZIP .

  1. Download the u8glib Library by clicking the button: Download u8glib Library.
  2. In the Arduino IDE, select to Sketch > Include Library > Add .ZIP Library from the drop-down list in menu
  3. Choose the library zip file you have already downloaded.
  4. Return to the Sketch > Include Library menu at the bottom of the drop-down menu. Now it’s ready to be used in your sketch. In your Arduino sketches directory, the zip file will already have been expanded in the libraries folder.

Select your board type Arduino Uno and select the  port

 Choose  Tools | Serial Port menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port.

Press CNTRL + A & press DELETE to clear the Arduino IDE page

Upload the program

After that click on the “Upload” button. Then we can see the RX and TX LEDS on the board flashing. The message “Done uploading.” will appear  if the uploading is success

 

Sketch Code

#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0);  // I2C / TWI
#include <Wire.h>
#include <Servo.h>
Servo myservo1;  // create servo object to control a servo
Servo myservo2;  // create servo object to control a servo
int flagpitch = 0;
int flagroll = 0;
int steprate = 1;
int flag = 0;
int inPin = 7;
unsigned long timer = 0; // Timers
unsigned long timer1 = 0;
float timeStep = 0.01;


const uint8_t heart []  PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x3F, 0xC0, 0x03, 0xFC, 0x00, 0x00, 0xFF, 0xF0, 0x0F, 0xFF, 0x00, 0x03, 0xFF,
  0xF8, 0x1F, 0xFF, 0xC0, 0x07, 0xFF, 0xFE, 0x7F, 0xFF, 0xE0, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0,
  0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x3F, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFC, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
  0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC,
  0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x0F, 0xFF, 0xFF, 0xFF,
  0xFF, 0xF0, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x03, 0xFF,
  0xFF, 0xFF, 0xFF, 0xC0, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x80,
  0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x7F, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x3F, 0xFF, 0xFF,
  0xFC, 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x07,
  0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
  0x00, 0x00, 0x7F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF0,
  0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t spiral [] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xF8,
  0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0x00, 0x00, 0x00, 0x03, 0xFE, 0x1F, 0xE0, 0x00, 0x00, 0x07,
  0xC0, 0x00, 0xF8, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x78, 0x1F, 0xFE, 0x0E, 0x00,
  0x00, 0xF0, 0xFF, 0xFF, 0x87, 0x00, 0x01, 0xC3, 0xF0, 0x03, 0xE3, 0x80, 0x03, 0x87, 0x80, 0x00,
  0xF1, 0xC0, 0x07, 0x1E, 0x07, 0xF8, 0x38, 0xE0, 0x06, 0x3C, 0x3F, 0xFE, 0x1C, 0x60, 0x0E, 0x70,
  0xF8, 0x0F, 0x8E, 0x30, 0x1C, 0x61, 0xE0, 0x03, 0xC7, 0x38, 0x18, 0xE3, 0x81, 0xE0, 0xE3, 0x18,
  0x39, 0xC7, 0x0F, 0xF8, 0x73, 0x9C, 0x31, 0x8E, 0x3F, 0x3E, 0x31, 0x8C, 0x33, 0x9C, 0x70, 0x0F,
  0x39, 0xCC, 0x73, 0x18, 0xE0, 0x03, 0x18, 0xCE, 0x63, 0x39, 0xC7, 0xE3, 0x9C, 0xC6, 0x67, 0x31,
  0x8F, 0xF1, 0x8C, 0xC6, 0x66, 0x33, 0x9C, 0x39, 0xCC, 0xE6, 0x66, 0x33, 0x18, 0x18, 0xCC, 0x66,
  0x66, 0x33, 0x39, 0x98, 0xCC, 0x66, 0x06, 0x73, 0x39, 0x98, 0xCC, 0x66, 0x06, 0x33, 0x39, 0xF8,
  0xCC, 0x66, 0x06, 0x33, 0x19, 0xF1, 0x8C, 0xE6, 0x07, 0x33, 0x9C, 0x03, 0x8C, 0xC6, 0x03, 0x31,
  0x8C, 0x07, 0x18, 0xC6, 0x03, 0x39, 0xCF, 0x3E, 0x39, 0xCC, 0x03, 0x18, 0xC7, 0xFC, 0x71, 0x8C,
  0x03, 0x9C, 0xE1, 0xE0, 0xF3, 0x9C, 0x01, 0x8C, 0x70, 0x01, 0xE3, 0x18, 0x01, 0xCE, 0x3C, 0x0F,
  0x87, 0x38, 0x00, 0xC7, 0x1F, 0xFF, 0x0E, 0x30, 0x00, 0xE3, 0x87, 0xF8, 0x3C, 0x70, 0x00, 0x71,
  0xC0, 0x00, 0x78, 0xE0, 0x00, 0x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xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};


int cmd = 0;

void draw(byte d) {

  if (d == 0)  {
    u8g.drawBitmapP( 0, 0, 6, 48, normal);
    u8g.drawBitmapP(  60, 0, 6, 48, normal);
  }
  if (d == 1)  {
    u8g.drawBitmapP( 0, 0, 6, 48, spiral);
    u8g.drawBitmapP( 60, 0, 6, 48, spiral);
  }
  if (d == 2)  {
    u8g.drawBitmapP( 0, 0, 6, 48, heart);
    u8g.drawBitmapP( 60, 0, 6, 48, heart);
  }
  if (d == 3)  {
    u8g.drawBitmapP( 0, 0, 6, 48, LOL);
    u8g.drawBitmapP( 60, 0, 6, 48, LOL);
  }

}

void setup(void) {

  Serial.begin(9600);
  myservo1.attach(9, 600, 2300); // (pin, min, max) servo
  myservo2.attach(10, 600, 2300); // (pin, min, max) servo
  pinMode(inPin, INPUT);    // sets the digital pin 7 as input
  myservo1.write(0);
  myservo2.write(0);
}

void loop(void) {
  timer = millis();
  int val = digitalRead(inPin);   // read the input pin
  if (val == LOW) {
    cmd = 2;
    dancefunc1() ;
    flag++;
  } else {
    cmd = 0;
    myservo1.write(0);
  }
  if (flag >= 5) {
    cmd = 1;
    madfunc() ;
    flag = 0;
  }
  timer1 = millis();
  if ((timer1 - timer) >= 300000) {
    cmd = 3;
    madfunc();
  }
  u8g.firstPage();
  do {
    draw(cmd);
    
  } while ( u8g.nextPage() );
}

void dancefunc1() {
  for (int i = 0; i < 3; i++) {
    myservo1.write(-10);
    myservo1.write(10);
  }
}
void madfunc() {
  for (int i = 0; i < 5; i++) {
    myservo2.write(-50);
    delay(300);
    myservo2.write(90);
    delay(300);
  }
  myservo1.write(0);
  myservo2.write(0);
} 

Output

You can see our robot bunny come to life 
The best thing is you can always change the code to control the bunny to all your creative robotic needs 🙂

Leave a Reply