Self Navigating Arduino Robot

Dear: LMR

I am hoping to build a self navigating robot. Right now it only obstacle avoids. It uses arduino mega, 12 volt motor driver, Ping sensor, and a 2s lipo battery. I used arduino and programmed it mostly in one day. Here is the code. I will post a video shortly. 

The chassis is made from an old excavator toy I found at the dump. I took the excavator part off of it since it was only used for decoration and striped it's electronics. Then I screwed onto it a two by four piece of wood to help mount electronics and then screwed a pencil case on top of it. While the pencil case was on top of it I then drilled some necessary holes to help out with the electronics and motor reach the arduino and motor driver. Thanks!!! Wish me good luck!!!

From: Noah

#include <NewPing.h>
NewPing sonar(3, 5, 200);
void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);
 pinMode(13, OUTPUT);
 pinMode(12, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(8, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(6, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(sonar.ping_cm() <= 30)
  {
    CCW(255);
  }
  if(sonar.ping_cm() > 30)
  {
    Forward(255);
  }

}
void Forward(int Speed)
{
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  analogWrite(9, Speed);
  digitalWrite(8, LOW);
  analogWrite(7, Speed);
  digitalWrite(6, LOW);
 
}
void Backward(int Speed)
{
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(9, LOW);
  analogWrite(8, Speed);
  digitalWrite(7, LOW);
  analogWrite(6, Speed);
}
void CCW(int Speed)
{
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  analogWrite(9, Speed);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  analogWrite(6, Speed);
}
void CW(int Speed)
{
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(9, LOW);
  analogWrite(8, Speed);
  analogWrite(7, Speed);
  digitalWrite(6, LOW);
}
void Stop()
{
  digitalWrite(13, LOW);
  digitalWrite(12, LOW);
}

UPDATE: 8/21/2017

Dear: LMR

I managed to get the robot to obstacle avoid better. Enjoy the new video and thanks to all those who had helped me. It means a lot.

From: Noah

#include <NewPing.h>
NewPing sonar(3, 5, 200);
void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);
 pinMode(13, OUTPUT);
 pinMode(12, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(8, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(6, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  Forward(255);
  if(sonar.ping_cm() <= 30)
  {
    Backward(255);
    delay(1000);
    CCW(255);
    delay(250);
    Stop();
    delay(1000);
  }
}
void Forward(int Speed)
{
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  analogWrite(9, Speed);
  digitalWrite(8, LOW);
  analogWrite(7, Speed);
  digitalWrite(6, LOW);
 
}
void Backward(int Speed)
{
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(9, LOW);
  analogWrite(8, Speed);
  digitalWrite(7, LOW);
  analogWrite(6, Speed);
}
void CCW(int Speed)
{
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  analogWrite(9, Speed);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  analogWrite(6, Speed);
}
void CW(int Speed)
{
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(9, LOW);
  analogWrite(8, Speed);
  analogWrite(7, Speed);
  digitalWrite(6, LOW);
}
void Stop()
{
  digitalWrite(13, LOW);
  digitalWrite(12, LOW);
}

Obstacle Avoids at the moment

  • Actuators / output devices: Gear DC motors
  • Control method: autonomous
  • CPU: Arduino Mega 2560
  • Operating system: none
  • Power source: Lipo 2s
  • Programming language: Arduino
  • Sensors / input devices: PING
  • Target environment: Indoors is best

This is a companion discussion topic for the original entry at https://community.robotshop.com/robots/show/self-navigating-arduino-robot

Looks really great! Looks

Looks really great! Looks like maybe the sonar doesn’t kick in everytime, meaning you might need to mount it a bit further forward closer to the front of the tracks, but it works really well!

Thanks!!!

Actually the problem is that sometimes the sonar sensor can’t get a signal because the obstacle has to be completely perpendicular to it otherwise it has trouble seeing it. That is why I am going to add an IMU to the project so at least it will know where it is going and when it is stuck. Thanks though!!!

Hi,Nice to see a robot from

Hi,

Nice to see a robot from you ! As dwrobotics already mentioned the ping sensor semms to have some problems sometimes. Maybe it helps if you put a 10ms delay in you main loop, since it’s not really necessary to run it that often and moreover the sensor can calm down a little. Also for readability you might declare some constants for your pins like : const int ML = 10;

I hope we can see some further development soon !

opidopi

Thanks!!!

Thanks!!! Will do!!!

Sonar

if(sonar.ping_cm() <= 30)

  {

    CCW(255);

  }

  if(sonar.ping_cm() > 30)

  {

    Forward(255);

  }

 

Here you are doing an ping measuring 2 times after each other. Which can both have different results. Try this instead:

 

if(sonar.ping_cm() <= 30)

  {

   CCW(255);

  }

  else

  {

    Forward(255);

  }

 

And as Opidopi mentioned, add a delay.

 

Keep up the good work!

 

Thanks I actually know why the robot has those problems.

Thanks I was going to try to change the code so that the robot will move backwards then have a delay then move CCW then delay. I talked to someone at my makerspace who had the same problem. Thanks!!!

hi noah

why didn’t you add more sonar ? or use a servo to move your sonar left and right ?

the other 2 sonars can be placed at left and right

or 45 degree and 135 degree .

here’s mine with 3 sonars at left and right :

https://www.youtube.com/watch?v=GT0x0AXqajo

I didn’t because long story short it was easier.

Dear: Sw0rdm4n

I just simply did it because it was the easiest thing I could think of and it worked. Thanks!!!

From: Noah

Cool new video. Looks like

Cool new video. Looks like you altered the behaviour of the robot to make it do a different action when it get a positive.

Thanks!!!

Now the robot is no longer getting stuck repeatedly. Thanks!!!