Obstacle Avoiding Arduino Robot කෙනෙක් හදමු.

You are here:
Estimated reading time: 7 min

Overview

මේ රොබෝ කිට් එක Arduino සහ Motor Shield එකක් භාවිතා කරලා කරන්න යන්නේ. Arduino සහ රොබොටික් ගැන ඉගනගන්න පටන් ගන්න කෙනෙක්ට මේක ගොඩක් වැදගත් වෙයි කියල හිතනවා. මේක හදන්න ගොඩක් අඩු මුදලක් තමයි යන්නේ Rs 4000 කට අඩුවෙන් මේකට ඕන part සෙට් එක ඔයාලට හොයාගන්න පුළුවන් ලංකාවෙන්. ඕනි නම් chassis එක ඔයාලට හදාගන්නත් පුළුවන්. මේකට අපි භාවිත කරන්න යන්නේ Arduino Uno R3 බෝඩ් එකක්. Motor Shield එකට භාවිතා කරන්නේ L293d කියන එක

අපි දැන් මේ ටික භාවිතා කරලා Obstacle Avoiding Arduino Robot කෙනක් හදන විදිය බලමු. මේකට 6V බැටරියක් භාවිතා කරනවනම්  වඩාත් හොදයි. මේකෙදි වෙන්නේ ultrasonic distance sensor එකෙන් ඉදිරියේ තියෙන බාධක ditect කරගෙන ඒවා මගහැරලා ගමන් කරනවා. එකියන්නේ අපි ultrasonic distance sensor එකෙන් ඉදිරියේ තියෙන බාධක හදුනාගෙන motor හැරෙන්න හදන්න ඕන. ඒවගේම servo එකේ තාමයි ultrasonic distance sensor එක සවි කරන්නේ servo එකෙන් ultrasonic distance sensor එක ඉදිරි අංශක 100 වගේ කරකවල අපිට ඉදිරියේ තියෙන බාධක ditect  කරගන්න පුළුවන්.

දැන් අපි මේක හදන විදිය මුල ඉදල බලමු.

Robot Construction Steps | මේ තමයි මුලික පියවරවල් ටික

  • Check your kit contents list and ensure you have all components.
  • Install the Arduino IDE and, if necessary USB drivers.
  • Construct the chassis and the 6V power supply.
  • Install the Arduino Uno and the motor shield.
  • Add the servo and the ultrasonic distance sensor (there are separate sketches to test each step).
  • Load the final sketch and test your completed robot.

Kit Contents

මේවා තමයි අපට අවශ්‍ය වන මුලික බඩු ටික ඔයාල මුලින්ම මේ ටික හොයාගන්න. පහත ලින්ක් එකෙන් ඒ ටික මිලදී ගන්නත් පුළුවන්

Chassis
  • Paper-wrapped Acrylic Chassis Base
  • Motors with Leads
  • Wheels
  • 4 x AA Battery Case
  • Hardware Pack 1
  • Hardware Pack 2
  • ON/OFF Swich
Order Now
 Arduino Uno
  • Arduino Uno R3
  • USB cable
Order Now
 Motor Driver Board 
  • Motor Shield
  • Connecting Wire (2 colors)
  • Inline Terminal Block
Order Now
 Servo 
  •  Servo with Lead and Accessories
  • 20 way M-M Split-able Ribbon Cable
  • Breadboard (for testing purposes)
Order Now
 Ultrasonic Sensor
  •  Ultrasonic Distance Sensor Module HC-SR04
  • 0 pin header (break up with snips for the size you need)
  • Ultrasonic Distance Sensor Mount
  • 1 x 4 way ribbon cable F-F or 4 F-F wires
  • 20 way F-M Split-able Ribbon Cable
Order Now

Hardware Pack Contents | අවශ්‍ය දේවල්

Chassis

  • Paper-wrapped Acrylic Chassis Base x 1
  • Motors with Leads x 2
  • Wheels x 2
  • 4 x AA Battery Case x 1
  • Hardware Pack 1 x 1
  • Hardware Pack 2 x 1
  • On/off switch x 1

Arduino Uno

  • Arduino Uno R3 x1
  • USB cable x 1

Motor Driver Board

  • Motor Shield x 1
  • Connecting Wire (2 colors) x 1
  • Inline Terminal Block x 2

Servo

  • Servo with Lead and Accessories x 1
  • 20 way M-M Split-able Ribbon Cable (split off what you need for testing) x 1
  • Breadboard (for testing purposes) x 1

Ultrasonic Sensor

  • Ultrasonic Distance Sensor Module HC-SR04 x 1
  • 40 pin header (break up with snips for the size you need) x 1
  • Ultrasonic Distance Sensor Mount x 1
  • 1 x 4 way ribbon cable F-F or 4 F-F wires x 1
  • 20 way F-M Split-able Ribbon Cable (split off what you need for testing) x 1

Your First Arduino Sketch

මුලින්ම Arduino ගැන පොඩි උදාහරණයක් බලමු.  මේකේදී අපි කරලා බලන්න යන්නේ LED එකක් blink  වෙන්න හදන්න යන්නේ

Open the blink example

මේක අපිට Arduino IDE එකේම දීල තියෙනවා. ඔය පහත තියෙන path එකෙන් ඕපන් කරගන්න | Open the LED blink example sketch: File > Examples > 1.Basics > Blink.

Select your board

දැන් අපි  භාවිතා කරන බෝර්ඩ් එක තෝරාගන්න ඕන  එකත් ඔය පහත තියෙන path ගිහින් Uno කියන එක තෝරන්න | You’ll need to select the entry in the Tools > Board menu that corresponds to your Arduino.

Select your serial port

Arduino බෝර්ඩ් එක USB port එකට කනෙක්ට් කරාට පස්සේ අපි Arduino IDE එකේ port එක select කරගන්න ඕන. එකෙට IDE Tools > Serial Port menu මෙනු එකට යන්න දන් ඔයාට COM3 හරි වෙන COM4 විදියට PC එකේ active COM port ටික පෙන්නනවා. ගොඩක් තියෙනවනම් Arduino බෝර්ඩ් එක USB port එකෙන් ගලාවල අයේ කනෙක්ට් කරාන්න එතකකොට අලුතෙන් menu එකේ view වෙන port එක තෝරන්න.

Select the serial device of the Arduino board from the Tools | Serial Port menu. On Windows 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 Arduino board and re-open the menu; the entry that disappears should be the Arduino board. Reconnect the board and select that serial port. On the Mac, this should be something with /dev/tty.usbmodem (for the Uno).

Upload the program

Now, simply click the “Upload” button in the environment. Wait a few seconds – you should see the RX and
TX LEDs on the board flashing. If the upload is successful, the message “Done uploading.” will appear in
the status bar.

A few seconds after the upload finishes, you should see the pin 13 (L) LED on the board start to blink.
Congratulations! You’ve got Arduino up-and-running.
If you have problems, please see the troubleshooting suggestions
http://arduino.cc/en/Guide/Troubleshooting).

Sweeping the Servo by 180 Degrees

දැන් අපි බලන්න යන්නේ servo motor එකක් වැඩ කරන්නේ මොකොමද කියලා. servo motor එකක් අංශක 180 කරකවන්න පුළුවන් අපිට ඕන විදියට. ඉතින් අපි මේකට උදහනයකින් තේරුම් ගන්න බලමු.

මේකට අපිට මෙන්න මේ දේවල් ඕන වෙනවා

Hardware Required

• Arduino Board
• Servo Motor
• Jumper wire

Circuit

Servomotors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the six-volt power supply. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board AND the 6V power supply. It is essential that there is a common ground. The signal pin is typically yellow, orange or white and should be  connected to pin 9 on the Arduino board.

Code

// Sweep
// by Hasarinda <http://arduino.lk> 
// this example code is in the public domain.


#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  }  
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees  
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

HC-SR04 Ultrasonic Sensor

The HC-SR04 is an ultrasonic distance sensor. It detects the distance of the closest object in front
of the sensor (from 2 cm up to 3m). It works by sending out a burst of ultrasound and listening for
the echo when it bounces off of an object. The Arduino board sends a short pulse to trigger the
detection, then listens for a pulse on the echo pin. The duration of this second pulse is equal to the
time taken by the ultrasound to travel to the object and back to the sensor. Using the speed of
sound, this time can be converted to distance.

Hardware Required

Arduino Board
(1) HC-SR04 Ultrasonic Distance Sensor
Jumper wire

Circuit

The 5V pin of the HC-SR04 is connected to the 5V pin on the Arduino, the GND pin is connected to
the GND pin, and the Trigger pin is connected to pin 8 and the Echo pin is connected to pin 9 on
the Arduino.

Code

/*
HC-SR04 for Arduino

Original project from http://www.arduino.lk

This project demonstrates the HC-SR
The distance presented in the code is in mm, but you can uncomment the line
for distance in inches.
The schematics for this project can be found on http://www.www.arduino.lk

This example code is in the public domain.
*/

const int TriggerPin = 8;      //Trig pin
const int EchoPin = 9;         //Echo pin
long Duration = 0;

void setup(){
  pinMode(TriggerPin,OUTPUT);  // Trigger is an output pin
  pinMode(EchoPin,INPUT);      // Echo is an input pin 
  Serial.begin(9600);          // Serial Output
}

void loop(){ 
  digitalWrite(TriggerPin, LOW);                   
  delayMicroseconds(2);
  digitalWrite(TriggerPin, HIGH);          // Trigger pin to HIGH
  delayMicroseconds(10);                   // 10us high 
  digitalWrite(TriggerPin, LOW);           // Trigger pin to HIGH
 
  Duration = pulseIn(EchoPin,HIGH);        // Waits for the echo pin to get
high
                                           // returns the Duration in
microseconds
  long Distance_mm = Distance(Duration);   // Use function to calculate the
distance
 
  Serial.print("Distance = ");             // Output to serial
  Serial.print(Distance_mm);
  Serial.println(" mm");
 
  delay(1000);                             // Wait to do next measurement
}
 
long Distance(long time)
{
    // Calculates the Distance in mm
    // ((time)*(Speed of sound))/ toward and backward of object) * 10
   
    long DistanceCalc;                      // Calculation variable
    DistanceCalc = ((time /2.9) / 2);     // Actual calculation in mm
    //DistanceCalc = time / 74 / 2;         // Actual calculation in inches
    return DistanceCalc;                    // return calculated value
}

 

Constructing the Chassis

Identify the chassis components: මේ තමයි chassis component සෙට් එක

  • 1 x chassis plate
  • 2 x wheels
  • 2 x motors
  • 1 x castor wheel
  • 1 x hardware pack 1
මේක තමයි chassis එකේ plate එක මේකේ ගන්නකොට protective paper එකක් අලවල එන්නේ. එක remove කරාම මේ මේ වගේ තමයි දකින්න පුළුවන්
මේ තියෙන්නේ  motor එකයි, mounting plates දෙක
සහ දිග ඇන. රතු හා කළු වයර් දෙකක් මෝටර් එකට පස්ස ගන්න ඕන. එක මෝටර් දෙකේම එක පැත්තට එන විදිය පාස්ස ගන්න ඕන
පින්තුරේ තියෙන විදයට මෝටර් දෙක chassis plate එකට සවි කරන්න එන වල නට් තියෙන පට්ට ඇතුලට එන්න සවි කරන්න

 

සවි කරලා ඉවර උනාම මෙන්න මේ වගේ තමයි පෙන්නේ
castor සවි කිරීම

wheel requires:

  • 4 x 15 mm standoffs
  • 4 x pan-head screws to attach the standoffs to the base
  • 4 x pan-head screws to attach the
  • castor to the mounts
 
Screw මෙන්න මේ වීදියට chassis plate එකට සවි කරගන්න
ඊට පස්සේ එක screws උඩ castor wheel එක තියල අණ වලින් සවි කරගන්න
ඔක්කොම සවි කරාම මේ විදියට තමයි තියෙන්න ඕන
ඉදිරිපසින් බැලුවම
Battery box  එක යටි පැත්තට මේ විදියට සවි කරගන්න

Installing the Arduino Uno

Insert two of the smaller standoffs from
Hardware Pack 2 in the position
shown in the photo and fix with a
couple of 6mm M3 screws.
Add a standoff to the Uno in the
position shown.
Then fix the Uno into position using
another two M3 screws.
Solder two red wires cut from the
supplied connecting wire to the switch.
Snap the switch into place just in front of the Uno.

 

Installing the Motor Shield

Snip off 3 x 6 pin strips from the 40 pin header (tip: hold onto the small piece when you snip so it doesn’t go flying off).  Solder the three strips to the bottom right hand corner of the shield where the rows are labeled A0-A5, GND & 5V. You could simply solder the connecting wires later but this way you get to easily
use these pins.
Here’s the motor shield installed on top of the Un. Ensure you leave the shield evenly positioned. The USB & Power connections are a different height; fully inserting can stress the motor shield board.

Very important: do NOT connect the power to the motor shield incorrectly or you could damage the
board.

  1. Connect Motor 1 to M1_A & M1_B. Connect the Red from first motor to M1_A & the Black to
    M1_B.
  2. Connect Motor 2 to M2. Connect the Red from second motor to M2_B & the Black to M2_A. Note the reversal – each motor must run the opposite to the other otherwise the robot will go arund in circles. 
  3. Connect GND (black wire) of battery box to GND of Power Terminals (EXT_PWR) on Motor Shield.
  4. Install on/off switch using inline connector (battery box red wire to on switch, other red wire from switch to +M on shield).
  5. Connect Servo to SER1 (Brown to -, Red to +, Yellow to S
  6. Connect Ultrasonic Sensor to the A4, A5 +5V, and GND on the motor shield. You will need to solder header pins into these holes to be able to connect the ultrasonic pins to the motor shield.

 

Installing the Servo

Servo attachment. Note the nut below the standoff as a spacer.
Servo connected to Servo 1.
  • Brown  – GND
  • Red  – Power
  • Orange – Signal

Installing the Ultrasonic Distance Sensor

Use the female-female connecting wires to connect the Ultrasonic sensor as follows:

Sensor Arduino
Vcc Arduino +5V
Trig Arduino Pin A4
Echo Arduino Pin A5
GND Arduino GND

 

The ultrasonic distance
sensor mount is attached to
the servo mount and the
mount is connected to the
servo using double-sided
tape – you can use contact
cement or superglue for
more permanence.
Here are the connections
from the HC-SR04
Ultrasonic Distance Sensor
to the Motor Shield.

Final Construction and Testing

There are several sketches supplied that may be helpful in testing. In addition, there is a completed sketch. You will be able to enhance this sketch as you develop your robot car further. You can find the download on the Arduino.lk for the kit.

Note: Remember to download the AFMotor and NewPing libraries. These are used in the supplied sketch and you will get a lot of error message have not installed these libraries!

Ideas for Extending your Robot

Here are a few ideas for extending your Arduino-based robot.
LDR (moth)

Use a Light Dependent Resistor as part of a voltage divider to sense the light. Read the values from an
Arduino analog pin and move the robot to the source of light.

PIR Sensor (movement sensor)

Use a PIR sensor to detect movement. Have it chase a person moving around the room.

IR Remote Control

Use a TSOP3848 IR receiver in conjunction with a remote control (or build your own with a TSAL7400 IR
LED and an Arduino) to remotely control your robot.

Download “Obstacle Avoiding Arduino Robot Code” Arduino.lk_RoboticsKit_Basic.ino_.zip – Downloaded 124 times – 2 KB

Was this article helpful?
Dislike 0
Views: 878

Leave a Reply

Your email address will not be published. Required fields are marked *