Pages: [1] 2   Go Down
Author Topic: How to make wall/obstacle avoiding robot with arduino uno atmega 328  (Read 6100 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi genius  smiley
   I'm going to build (assemble) ultrasonic obstacle avoiding robot and I have Arduino Uno - Atmel Atmega 328-PU board and Arduino Compatible H-Bridge Motor Driver board (photo's attached) and Ultrasonic Module HC-SR04 Arduino. I'm looking for a way to attach cable from motor,ultrasonic module and within uno and motor control board and also suitable  program/code for it... smiley


* 23767(1).jpg (86.63 KB, 565x414 - viewed 101 times.)

* 37421.jpg (91.12 KB, 565x414 - viewed 79 times.)

* 37421s.jpg (84.73 KB, 565x414 - viewed 67 times.)

* 37892-2.jpg (58.43 KB, 565x414 - viewed 191 times.)
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50912
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and also suitable  program/code for it...
Gee, I don't think anyone has ever done that. You just night have to develop your own code.
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 559
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Gee, I don't think anyone has ever done that.
LOL.


Quote
Hi genius  
   I'm going to build (assemble) ultrasonic obstacle avoiding robot and I have Arduino Uno - Atmel Atmega 328-PU board and Arduino Compatible H-Bridge Motor Driver board (photo's attached) and Ultrasonic Module HC-SR04 Arduino. I'm looking for a way to attach cable from motor,ultrasonic module and within uno and motor control board and also suitable  program/code for it...

1st off pictures are of little value. Give us links to data sheet or the products page… I don't plan on hunting them down. You bought the stuff!

2. No body is going to wright your code for you… you would never learn. However, I will give you some examples.

Analog read example… chances are your sensor is analog… now way to tell with out data sheet.
Code:
/*
  AnalogReadSerial
  Reads an analog input on pin 0, prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 
 This example code is in the public domain.
 */

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(700);        // delay in between reads for stability
}



Thats it for now  until you post the data sheets or product page. No point wasting my time giving you code that might/might not apply.

Best of luck!
« Last Edit: September 13, 2013, 10:22:35 pm by Drew Davis » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50912
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
2. No body is going to right your code for you…
Not true. We'll right the code, if it's wrong. But, we won't write the code.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here are those links unfortunately there's no any data sheets.some data sheets are with sensor  smiley-sad

Uno board- http://hobbyking.com/hobbyking/store/__23767__Arduino_Uno_Atmel_Atmega_328_PU.html
motor drive - http://www.hobbyking.com/hobbyking/store/__37421__Arduino_Compatible_H_Bridge_Motor_Driver.html
sensor - http://www.hobbyking.com/hobbyking/store/__31136__Ultrasonic_Module_HC_SR04_Arduino.html
the project* -http://www.hobbyking.com/hobbyking/store/__37892__Arduino_2WD_Ultrasonic_Smart_Car_Kit.html

I'm bought bought items separately,not the whole project.so I haven't any data sheet or code smiley-sad that's why I'm trying to find the way to connect components and code



 
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 559
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Start with one thing at a time. Lets get the wheels rolling before we add in the obstacle avoidance.


I found this http://www.geekonfire.com/wiki/index.php?title=Dual_H-Bridge_Motor_Driver on the link you gave me. It pretty much explains how to get your motor driver up and running. It even gives you the code!


Once you have your car zipping around come back to this thread you started and we can help you with the object avoidance.

Best of luck!



Quote
Not true. We'll right the code, if it's wrong. But, we won't write the code.

Thanks. I fixed my bad grammar smiley
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2927
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.hobbyking.com/hobbyking/store/__37892__Arduino_2WD_Ultrasonic_Smart_Car_Kit.html

That's actually a pretty good kit for the price, includes all the "components" you need to build a basic robot. What's missing is some of the "glue" components, namely the wires to connect things together (see below). All the pieces are common, standard items, so you can easily find software and libraries for everything. It's very typical with CN companies that they will sell you things very cheaply, but provide little or no support whatsoever beyond that.

Like Drew said, you do one thing at a time, get it working in isolation from everything else, and then gradually bring the different pieces together. After a couple of iterations on this, you'll have learned a lot.

1. first, learn how to program the UNO, if you don't already know how.
2. pick one of the subsystems, and learn to program that.
3. go on to the next subsystem, etc.

If you do a google search on "arduino" and the part, you'll find links to follow up, eg the library for the HC-SR04,
https://www.google.com/webhp?source=search_app#psj=1&q=arduino+HC-SR04
http://forum.arduino.cc/index.php/topic,37712.0.html

Also, to connect things to the Arduino board is a bigger problem than the software. You can get jumpers like this, with male on one end and female on the other, to stick into the Arduino female headers, but the little round pins are really crappy and marginally reliable,
http://www.adafruit.com/products/826

What I would do instead is insert male headers into the Arduino female headers, and use the following type of female-female jumper. MUCH more reliable, and won't fall out as easily.
http://www.adafruit.com/products/400
http://www.adafruit.com/products/266

Good luck, :-).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have all the connectors smiley
I'm check ultrasonic sensor by this code-
http://www.tautvidas.com/blog/2012/08/distance-sensing-with-ultrasonic-sensor-and-arduino/
and motors with
int ENA=5;//connected to arduino's port 5 (output pwm)
int IN1=2;//connected to arduino's port 2
int IN2=3;//connected to arduino's port 3
int ENB=6;//connected to arduino's port 5 (output pwm)
int IN3=4;//connected to arduino's port 4
int IN4=7;//connected to arduino's port 7
void setup ()
{
  pinMode(ENA,OUTPUT);//output
  pinMode(ENB,OUTPUT);
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);
  pinMode(IN3,OUTPUT);
  pinMode(IN4,OUTPUT);
  digitalWrite(ENA,LOW);
  digitalWrite(ENB,LOW);//stop driving
  digitalWrite(IN1,LOW);
  digitalWrite(IN2,HIGH);//setting motorA's direction
  digitalWrite(IN3,HIGH);
  digitalWrite(IN4,LOW);//setting motorB's direction
}
void loop ()
{
  analogWrite (ENA,255);//start driving motorA
  analogWrite (ENB,255);//start driving motorB
}

both are working well and I'm very happy  smiley-grin

now I'm looking for how to combine those 2 codes....I think now you can directly help me smiley
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50912
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I think now you can directly help me
Code A does something that you like. Code B does something that you like. The combined program, Code C, has some requirements. They are?

If you UNDERSTOOD the code, you'd know that combining them is both easy and hard. Getting all the code into one sketch is easy. Making the parts do something useful is hard.

Knowing what they should do is more than half the battle.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2927
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

manju, three things:

1. wrap your code using the "#" icon on the edit screen,
Code:
code goes here

2. go research the concepts of "modular programming", so your program isn't one long jumble of code.

3. at your point in this project, the best thing you can probably do is go do a search on similar projects, and adapt code from them for your own use. This is how everybody does it at the beginning, :-).

https://www.google.com/#psj=1&q=arduino+obstacle+avoidance
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 559
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That code should make your robot turn when something gets closer then 10 inches. Try it and see if it works. Also please do what oric_dan said.

Quote
1. wrap your code using the "#" icon on the edit screen,


Code:

 
 
 int ENA=5;//connected to arduino's port 5 (output pwm)
int IN1=2;//connected to arduino's port 2
int IN2=3;//connected to arduino's port 3
int ENB=6;//connected to arduino's port 5 (output pwm)
int IN3=4;//connected to arduino's port 4
int IN4=7;//connected to arduino's port 7

const int trigPin = 13;
const int echoPin = 12;
 
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}
 
void loop()
{

 analogWrite (ENA,200);//start driving motorA
  analogWrite (ENB,200);//start driving motorB

  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, inches, cm;
 
  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
 
  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  
if ( inches < 10) {
  
  
  analogWrite (ENA,255);//start driving motorA
  analogWrite (ENB,1);//start driving motorB
  
  delay (500);
  
}



}
 
long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}
 
long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}
« Last Edit: September 16, 2013, 09:29:20 am by Drew Davis » Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2927
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, item #4 was supposed to be the following, but I forgot to include it.

4. "if...else" is the single most important construct for this sort of thing.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

dear drew davis, smiley

as you say I have connect motor control's pins then where's to connect sensor?  smiley-sad

in your code
int ENA=5;//connected to arduino's port 5 (output pwm)
int IN1=2;//connected to arduino's port 2
int IN2=3;//connected to arduino's port 3
int ENB=6;//connected to arduino's port 5 (output pwm)
int IN3=4;//connected to arduino's port 4
int IN4=7;//connected to arduino's port 7

const int trigPin = 2;
const int echoPin = 4;

as I highlight in red is it ok when I connect ENA & ENB to digital port 5

in sensors connection ( highlight in blue ) where's to connect them motor control board's pins are almost there in 2 and 4 or do I want to connect sensor's trig & echo wires to analog's 2 & 4

please explain me where's to connect wires

I'm add pic how I connected motor control's wires to arduino


* the-arduino-uno-atmega328p-pu-2011-version - Copy.jpg (96.66 KB, 465x489 - viewed 73 times.)
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 559
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry I did not notice. I put the code together a little to fast. smiley I will update my post soon.

I'm a little confused. That is how your code was. I just copied it in. Does it work like that...

Code:
int ENA=5;//connected to arduino's port 5 (output pwm)
int IN1=2;//connected to arduino's port 2
int IN2=3;//connected to arduino's port 3
int ENB=6;//connected to arduino's port 5 (output pwm)
« Last Edit: September 15, 2013, 11:43:54 am by Drew Davis » Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2927
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Where it says port 5 the 2nd time is just a copy typo, pin 6 is actually being assigned.

Also, you cannot use pins 2,4 for the sonar, as they are already assigned as IN1,IN3. You can use 12,13 as shown earlier.

Also, since you're trying to do both sensors and motors in one initial sketch, put the robot up on a book,etc, so the wheels can spin freely during program development.
Logged

Pages: [1] 2   Go Up
Jump to: