Hey Im new so be cool.
I uploaded the code for the obstacle avoiding robot it uploaded but nothing happened no movements, no error messages nothing. pls help me if u can
Hey Im new so be cool.
I uploaded the code for the obstacle avoiding robot it uploaded but nothing happened no movements, no error messages nothing. pls help me if u can
pls help me if u can
Give us something to work with... you say "the" obstacle avoiding robot, but what does that mean?
You should supply details: code, circuit diagram, links, photos...
ok here's the code:-
#include <AFMotor.h>
#include <NewPing.h>
#include <Servo.h>
#define TRIG_PIN A4
#define ECHO_PIN A5
#define MAX_DISTANCE 200
#define MAX_SPEED 190 // sets speed of DC motors
#define MAX_SPEED_OFFSET 20
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(3, MOTOR12_1KHZ);
Servo myservo;
boolean goesForward=false;
int distance = 100;
int speedSet = 0;
void setup() {
myservo.attach(9);
myservo.write(115);
delay(2000);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
}
void loop() {
int distanceR = 0;
int distanceL = 0;
delay(40);
if(distance<=15)
{
moveStop();
delay(100);
moveBackward();
delay(300);
moveStop();
delay(200);
distanceR = lookRight();
delay(200);
distanceL = lookLeft();
delay(200);
if(distanceR>=distanceL)
{
turnRight();
moveStop();
}else
{
turnLeft();
moveStop();
}
}else
{
moveForward();
}
distance = readPing();
}
int lookRight()
{
myservo.write(50);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
}
int lookLeft()
{
myservo.write(170);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
delay(100);
}
int readPing() {
delay(70);
int cm = sonar.ping_cm();
if(cm==0)
{
cm = 250;
}
return cm;
}
void moveStop() {
motor1.run(RELEASE);
motor2.run(RELEASE);
}
void moveForward() {
if(!goesForward)
{
goesForward=true;
motor1.run(FORWARD);
motor2.run(FORWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to avoid loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet+MAX_SPEED_OFFSET);
delay(5);
}
}
}
void moveBackward() {
goesForward=false;
motor1.run(BACKWARD);
motor2.run(BACKWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to avoid loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet+MAX_SPEED_OFFSET);
delay(5);
}
}
void turnRight() {
motor1.run(FORWARD);
motor2.run(BACKWARD);
delay(300);
motor1.run(FORWARD);
motor2.run(FORWARD);
}
void turnLeft() {
motor1.run(BACKWARD);
motor2.run(FORWARD);
delay(300);
motor1.run(FORWARD);
motor2.run(FORWARD);
}
project source:Arduino autonomous Robot Project: A DIY obstacle avoiding robot using an SG90 servo - YouTube
everything was done according to that video.
It is probably not problem with the bootloader. Maybe you should ask mods to move the topic to Project or Programming category if you want relevant help because not all people are reading here.
Please, use code tags for posting your code.
first I thought there is something wrong with my motor shield so I replaced it but still, it didn't work. I just want to build a ship so I guess I should work on the Bluetooth thing. I made the obstacle avoiding robot and it worked but then I didn't use it for like 3 months that's when the problem started.
hey I was making the obstacle avoiding robot and I uploaded the code and nothing happened no movements no error messages nothing. pls help me.
CODE:-
#include <AFMotor.h>
#include <NewPing.h>
#include <Servo.h>
#define TRIG_PIN A4
#define ECHO_PIN A5
#define MAX_DISTANCE 200
#define MAX_SPEED 190 // sets speed of DC motors
#define MAX_SPEED_OFFSET 20
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(3, MOTOR12_1KHZ);
Servo myservo;
boolean goesForward=false;
int distance = 100;
int speedSet = 0;
void setup() {
myservo.attach(9);
myservo.write(115);
delay(2000);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
}
void loop() {
int distanceR = 0;
int distanceL = 0;
delay(40);
if(distance<=15)
{
moveStop();
delay(100);
moveBackward();
delay(300);
moveStop();
delay(200);
distanceR = lookRight();
delay(200);
distanceL = lookLeft();
delay(200);
if(distanceR>=distanceL)
{
turnRight();
moveStop();
}else
{
turnLeft();
moveStop();
}
}else
{
moveForward();
}
distance = readPing();
}
int lookRight()
{
myservo.write(50);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
}
int lookLeft()
{
myservo.write(170);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
delay(100);
}
int readPing() {
delay(70);
int cm = sonar.ping_cm();
if(cm==0)
{
cm = 250;
}
return cm;
}
void moveStop() {
motor1.run(RELEASE);
motor2.run(RELEASE);
}
void moveForward() {
if(!goesForward)
{
goesForward=true;
motor1.run(FORWARD);
motor2.run(FORWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to avoid loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet+MAX_SPEED_OFFSET);
delay(5);
}
}
}
void moveBackward() {
goesForward=false;
motor1.run(BACKWARD);
motor2.run(BACKWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to avoid loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet+MAX_SPEED_OFFSET);
delay(5);
}
}
void turnRight() {
motor1.run(FORWARD);
motor2.run(BACKWARD);
delay(300);
motor1.run(FORWARD);
motor2.run(FORWARD);
}
void turnLeft() {
motor1.run(BACKWARD);
motor2.run(FORWARD);
delay(300);
motor1.run(FORWARD);
motor2.run(FORWARD);
}
OK, first things first.
You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.
In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code" it can easily be quite garbled and is always more difficult to read due to the font.
It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.
Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.
What was supposed to happen?
Hi,
Did you write the code?
If so did you write it in stages,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
What batteries are you using?
Thanks... Tom...
Paul sry about that dude as u can clearly see Im new to this. No, Tom, I didn't do my own coding I just don't know how to any suggestions to like a free site where I can learn to code? that would help a lot. I made it watching this:-Arduino autonomous Robot Project: A DIY obstacle avoiding robot using an SG90 servo - YouTube and the code was from his website.
Tectonic1900:
any suggestions to like a free site where I can learn to code? that would help a lot.
Work through the examples right here, which are also in the IDE at File > Examples.
Hmm ok what about the other problem is there anything you could do?
That code really needs some serial prints to print out the values of distance, distanceR and distanceL each time they are measured, else you have no idea a) if the ultrasonic sensor is even working and b) what decisions the robot is supposed to be making to move where.
... and also serial prints in all the functions like turnRight() etc so you can see if the logic is working, even if there's no outwards signs of movement. If it does go to (say) turnRight() when the mesurements indicate it should, but it doesn't move, that shows you one thing. If otoh it doesn't go there when it should, that shows something else.
It's really unusual to see such a relatively long sketch with many measurements and functions with no debug prints.
I've merged your other cross-post @Tectonic1900.
Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting will result in a suspension from the forum.
In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
pert:
I've merged your other cross-post @Tectonic1900.
I just saw this:
I made the obstacle avoiding robot and it worked but then I didn't use it for like 3 months that's when the problem started.
... which presumably was from the other thread.
So does that mean that the code you asked about (and which I said needs debug prints*) is actually known good?
Battery dead?
Tectonic1900:
Paul sry about that dude as u can clearly see I'm new to this.
OK, but I gave you clear instructions, so it would be sensible to correct each of the posts where you cite code in each of your threads which have now been collated by the moderator to make it easier.