Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY

MID-LA UNION CAMPUS


COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

Building
An
Arduino Robot

Prepared by

Comello, Elise Adrielle S.


Culbengan, Chester B.
Ramos, Bamby Warin B.
Rimando, Chrystal Mhaye G.

Submitted to

Mr. Joseph M. Patacsil

November 20, 2022


DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

Building an Arduino Robot: Introduction

Arduino is an open-source electronics creation platform, which is based on


free, flexible, and easy-to-use hardware and software for creators and
developers. This platform allows you to create different types of single-
board microcomputers to which the community of creators can give
different types of use.

The importance of Arduino can be seen in many everyday applications. Many


children and adults don’t realize that the Arduino is behind many things that
are used daily. Businesses that use Square, a device that can be plugged
into smartphones to accept payments with credit cards, may not realize
that it is made possible by Arduino. The Pebble watch falls into the same
category. For both of these products, the initial prototype was built with
Arduino.

The main component, which is the Arduino Board is a low-cost, flexible, and
easy-to-use programmable open-source microcontroller board that can be
integrated into a variety of electronic projects. One of the main advantages
of using Arduino is that we get to build our own projects. At the same time,
We get to see what works and what doesn’t work and how to problem-solve
in the process.

To conclude, Arduino Robots or Robotics, in general, are an important part


of one’s education because it fosters creativity and problem-solving. When
working in a robotics program, using Arduino and other technology, We need
to learn to be creative. We also need to learn how to fix problems that can
arise as we are creating new inventions. Which, these skills can be used in
the real world.
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

Building an Arduino Robot: Hardware Components

1. The Arduino board

The Arduino board will be the brain of the


robot, as it will be running the software
that will control all the other parts.

The Arduino board is connected to a


computer via USB, where it connects with
the Arduino development environment
(IDE). The user writes the Arduino code
in the IDE, then uploads it to the
microcontroller which executes the
code, interacting with inputs and
outputs such as sensors, motors, and
lights.

2. Motor Driver

The L298N is a dual H-Bridge motor driver


which allows speed and direction control of two
DC motors at the same time. The module can drive
DC motors that have voltages between 5 and 35V,
with a peak current up to 2A.

3. Distance Sensor
Distance sensors send an ultrasonic signal forward and then
wait to receive a bounced signal. Depending on how long
the signal takes to bounce back the approximated distance
to an obstacle can be calculated. I will use this little device
to prevent the robot from hitting walls or other obstacles
in its way.
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

4. The Bluetooth Slave

The easiest way to control the robot from a


smartphone is via the bluetooth serial interface
that all modern smartphones have. The phone
will act as a master, so I needed a bluetooth
slave for the robot.

5. Prototyping Cables and Board


A breadboard (sometimes called a
plugblock) is used for building temporary
circuits. It is useful to designers because
it allows components to be removed and
replaced easily. It is useful to the person
who wants to build a circuit to
demonstrate its action, then to reuse
the components in another circuit.

Jumper wires are used for making


connections between items on your
breadboard and your Arduino's header
pins.

6. USB Cable

The Arduino board is connected to a computer via a USB


port. The USB connection is used to upload software and
also can be used as a power source when testing.

7. The Vehicle Kit Transparent Car Chassis


 The chassis is the structural
component for the robot which
contains the drivetrain and allows the
robot to be mobile by using wheels,
tank treads, or another method. A
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

8. DC Gears Motors

A gear motor is an all-in-one combination of a motor


and gearbox. The addition of a gear head to a motor
reduces the speed while increasing the torque output.

9. Battery Pack

Serve as the battery case or house of several


batteries we are going to use in to power the
arduino robot. Make your Arduino projects portable
by using a battery for power. From the Uno and
Mega documentation pages: The board can operate
on an external supply of 6 to 20 volts.

10. Arduino Switch

Switches are used to turn ON/OFF devices and to connect


different parts of a circuit. The slide-switch in Arduino
moves the slider of the switch from the open position (ON) to
the closed position (OFF). It allows the flow of current in the
circuit without the need for splice wire.

Building an Arduino Robot: Assembly


DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

Step 1: Prepare the Components


In order to complete this project, make sure we have the following
items:
Arduino UNO, L298N Motor Driver or L293D Motor Shield,
Chassis(including motors and wheels), Wires, Battery Holder, Micro Servo
Motor SG90, HC-SR04 Ultrasonic Sensor, Sensor Mount. We also make used of
Wire cutter, Screw Driver and tape.

Step 2: Assembly All Components


Connect the wheel, circuit board, servo motor, sensor to the chassis.
Attached the swivel to the bottom of the base plate using the screws
and nuts and connect the wheels. Mount the Sensor Shield atop the Arduino
and line up the right edges of the boards. We make sure each pins goes in a
connector.
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

Step 3: Wiring
Connect the wires according to the circuit diagram.
Connect the power and motor wires as well as the Ultrasonic Sensor,
Servo, and L298N to the Arduino Sensor Shield to their designated part.
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

Step 4: Coding & Testing


Upload Sketch and Test it.
We installed and used Arduino IDE (Integrated Development
Environment) which allows us to draw the sketch and upload it to the
Arduino board. We program in C++ with the addition of methods and
functions. To power up the board, we connect the Arduino board to the pc
via a USB cable. The green color power LED should glow on the board.

Building an Arduino Robot: Wirings

The VCC of the Arduino shield is connected to the switch and its GND
is connected to the battery.
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

Building an Arduino Robot: Coding with Explanation

#include <Servo.h>          //Servo motor library. This is standard library


#include <NewPing.h>        //Ultrasonic sensor function library. You must install this library

#include <Servo.h> This library allows an Arduino board to control


RC (hobby) servo motors. Servo have integrated gears and a shaft that can
be precisely controlled. Standard servos allow the shaft to be positioned at
various angles, usually between 0 and 180 degrees.
#include<NewPing.h> This library allows an ultrasonic sensor to
receive and transmit obstacle signal.

//our L298N control pins


const int LeftMotorForward = 7;
const int LeftMotorBackward = 6;
const int RightMotorForward = 4;
const int RightMotorBackward = 5;

 
The above code shows the connection between the Arduino and
motor driver L298N control pins.

//sensor pins
#define trig_pin A0 //analog input 1
#define echo_pin A1 //analog input 2

This sensor includes four pins and the pin configuration of this sensor is
discussed below.
 Pin Vcc: This pin provides a +5V power supply to the sensor.
 Pin Trig: This is an input pin, used to initialize measurement by
transmitting ultrasonic waves by keeping this pin high for 10us.
 Pin Echo: This is an output pin, which goes high for a specific time
period and it will be equivalent to the duration of the time for the
wave to return back to the sensor.
 Pin GND: This is a ground pin used to connect to the GND of the
system.
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

#define maximum_distance 500


boolean goesForward = false;
int distance = 150;

NewPing sonar(trig_pin, echo_pin, maximum_distance); //sensor function


Servo servo_motor; //our servo name

goesForward is a Boolean variable that represents whether the robot


is going forwards. It is like a flag that says "Yes, the robot is moving
forwards". Maximum distance we want to ping for (in centimeters).
Maximum sensor distance is rated at 500cm.
The NewPing library allows you to use an ultrasonic sensor, which
measures distance, with your Arduino. 

void setup(){

  Serial.begin(9600);

Serial. begin(9600)─ passes the value 9600 to the speed parameter.


This tells the Arduino to get ready to exchange messages with the Serial
Monitor at a data rate of 9600 bits per second. That's 9600 binary ones or
zeros per second, and is commonly called a baud rate.

  pinMode(RightMotorForward, OUTPUT);
  pinMode(LeftMotorForward, OUTPUT);
  pinMode(LeftMotorBackward, OUTPUT);
  pinMode(RightMotorBackward, OUTPUT);

The pinMode() function is used to configure a specific pin to behave


either as an input or an output.

servo_motor.attach(10); //our servo pin

 
  Attach a Servo variable to a pin. Note that in Arduino 0016 and
earlier, the Servo library supports only servos on only two pins: 9 and 10.

servo_motor.write(115);
  delay(2000);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

Writes a value to the servo, controlling the shaft accordingly. On a


standard servo, this will set the angle of the shaft (in degrees), moving the
shaft to that orientation. On a continuation rotation servo, this will set the
speed of the servo.

void loop(){

  int distanceRight = 0;
  int distanceLeft = 0;
  delay(50);

The int for right and left distance is set to 0 to loop the code
effectively.

  if (distance <= 20){


    moveStop();
    delay(300);
    moveBackward();
    delay(400);
    moveStop();
    delay(300);
    distanceRight = lookRight();
    delay(300);
    distanceLeft = lookLeft();
    delay(300);

The moveStop() instruction stops the robot when its ultrasonic sensor


detects a close object in front of it. Then, moveBackward() instruction
enables the robot to take backward when it detects a close object. The
lookRight() and lookLeft() instruction will be done once it stop and move
backward.

    if (distance >= distanceLeft){


      turnRight();
      moveStop();
  }
    else{
      turnLeft();
      moveStop();
  }
 }
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

If the sensor detects a close object in left side, the turnRight()


instruction will enable the robot to take right, else it will turn left then
moveStop() will stop the robot.

  else{
    moveForward();
 }
    distance = readPing();
}

moveForward() will enable the robot to take forward if it doesn’t detect a


close object.

int lookRight(){  
  servo_motor.write(50);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
}

lookRight() instruction will let the robot look right and go where it is clear.
Then we use write() function to update the servo's position to the angle
selected by the potentiometer.

int lookLeft(){
  servo_motor.write(170);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
  delay(100);
}
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

lookLeft() instruction will let the robot look left and go where it is clear.
Then we use write() function to update the servo's position to the angle
selected by the potentiometer.

int readPing(){
  delay(70);
  int cm = sonar.ping_cm();
  if (cm==0){
    cm=250;
 }
  return cm;
}

If the right and left side are clear it will go forward, then we used
sonar.ping_cm() it sends a ping, returns the distance in centimeters or 0
(zero) if no ping echo within set distance limit. There are other functions
(also called Methods in some cases) that return the distance in inches, or
the time it took for the eco to return.

void moveStop(){
 
  digitalWrite(RightMotorForward, LOW);
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorBackward, LOW);
  digitalWrite(LeftMotorBackward, LOW);
}

moveStop() function is for motor driver. The digitalWrite() function


serves the purpose of controlling the different digital devices connected to
the Arduino by assigning the states of either HIGH or LOW.
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

void moveForward(){

  if(!goesForward){

    Serial.println("==moveForward==");

    goesForward=true;
  
    digitalWrite(LeftMotorForward, HIGH);
    digitalWrite(RightMotorForward, HIGH);
 
    digitalWrite(LeftMotorBackward, LOW);
    digitalWrite(RightMotorBackward, LOW);
 }
}

The moveForward() function begins by declaring a variable named


distance. This enables the programmer to program
the moveForward() function to go any distance. IF the robot moves
forward, digitalWrite() function for left and right forward are set to HIGH.

void moveBackward(){

  goesForward=false;

  Serial.println("==moveBackward==");

  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorBackward, HIGH);
 
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorForward, LOW);
 
}

The moveBackward() function begins by declaring a variable named


distance. This enables the programmer to program
the moveBackward() function to go any distance. IF the robot moves
backward, digitalWrite() function for left and right backward are set to
HIGH.
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

void turnRight(){

  Serial.println("==turnRight==");

  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorBackward, HIGH);
 
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorForward, LOW);
 
  delay(500);
 
  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
 
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorBackward, LOW);
 
 
}

The turnRight() function begins by declaring a variable named distance.


This enables the programmer to program the turnRight() function to go any
distance. IF the robot turn right, digitalWrite() function for left motor
forward and the right motor backward is set to HIGH and left motor
backward and the right motor forward is set to LOW. Then it will pause for
about a milliseconds, then it digitalWrite() function to go any distance
forward and the right and left motor are set to HIGH.
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

void turnLeft(){

  Serial.println("==turnLeft==");

  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
 
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorBackward, LOW);

  delay(500);
 
  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
 
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorBackward, LOW);
}

The turnLeft() function begins by declaring a variable named distance. This


enables the programmer to program the turnLeft() function to go any
distance. IF the robot turn right, digitalWrite() function for left motor
backward and the right motor forward is set to HIGH and left motor forward
and the right motor backward is set to LOW. Then it will pause for about a
milliseconds, then it digitalWrite() function to go any distance forward and
the right and left motor are set to HIGH.
DON MARIANO MARCOS MEMORIAL STATE UNIVERSITY
MID-LA UNION CAMPUS
COLLEGE OF INFORMATION TECHNOLOGY
ITPE 101-DIGITAL ELECTRONICS

Building an Arduino Robot: Testing

As shown in the pictures below, the robot has displayed the necessary
function of obstacle avoiding that was programmed into the Arduino. It can
detect object a centimeter away from robot itself and finds another way to
avoid it.

You might also like