Jump to content

Arduino exit status 1 Err

Symbolls
Go to solution Solved by RandleMcmurphy,
3 hours ago, Symbolls said:

So i was building a sumo robot and i have not finis scholl yet so i dont now how to program that well.So i foud this website https://www.14core.com/14core-mini-sumo-robot-with-multi-senors-on-arduino-microcontroller/ witch gave me the codee wit a diagram to comlit the programing of my robot.And wen i wana compile it it shows me this ereo 'ecit status 1' "

Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

(.text+0x0): multiple definition of `__vector_7'

libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Nano.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences. "

pls help me

 

the code can be downloaded

sorry for my English but i am not a native speaker

<snip>

 

@colonel_mortis hit the nail on the head, tone and new_ping don't play nice together, get rid of the buzzer.

 

Compiles, working? idk, didn't test it.

Spoiler

//Note: You can customize the pin configuration as you want
//Note: Some code below is not yet calibrated.
//--------------------------------------------------------------
/*ENA - 11
  ENB - 9
  IN1- D8
  IN2- D10
  IN3- D12
  IN4- D13
  LED- D6
  BUZ- D7 - remove!
  A0 - Front Left Sensor
  A1 - Front Right Sensor
  A2 - Rear Left Sensor
  A3 - Rear Right Sensor
  Front Ultrasonic - ECHO - D3
  Front Ultrasonic - TRIG - D2
  Rear Ultrasonic - ECHO - D5
  Rear Ultrasonic - TRIG - D4
  ==============================================================
*/

//#include <NewPing.h>
#include "NewPing.h" //https://www.14core.com/wp-content/uploads/2017/02/NewPing.zip
//#include <Automaton.h>
//#include <timeObj.h>
//#include <pidDriver.h>

#define PulseA 11 //Optional
#define IN1 8
#define IN2 10

#define PulseB 9 //Optional
#define IN3 12
#define IN4 13

#define RTrigger 4
#define REcho 5

#define FTrigger 2
#define FEcho 3

//timeObj monTime (3000);
//boolean monMtr = false;

#define Front_Maximum_Distance  200
#define FrontMinimum_Distance  0

#define Rear_Maximum_Distance 180
#define Rear_Minimum_Diatance  0

int LineVal = 128;
int ReturnPath;
int Ping;

//const int SoundFX = 7;
const int OutLedPin = 6;
int FxCounter = 0;

int LSFrontLeft;
int LSFrontRight;
int LSBackLeft;
int LSBackRight;

/*SOUND-FX
  const int c = 261;
  const int d = 294;
  const int e = 329;
  const int f = 349;
  const int g = 391;
  const int gS = 415;
  const int a = 440;
  const int aS = 455;
  const int b = 466;
  const int cH = 523;
  const int cSH = 554;
  const int dH = 587;
  const int dSH = 622;
  const int eH = 659;
  const int fH = 698;
  const int fSH = 740;
  const int gH = 784;
  const int gSH = 830;
  const int aH = 880;
  END OF SOUND FX*/

//int ObstacleAvoidance_Left; //Optional
//int ObstacleAvoidance_Right; //Optional

NewPing FrontSonic (FTrigger, FEcho, Front_Maximum_Distance);
NewPing BackSonic (RTrigger, REcho, Rear_Maximum_Distance);

void setup() {
  Serial.begin(115200);
  //pinMode(SoundFX, OUTPUT);
  pinMode(OutLedPin, OUTPUT);

  pinMode(PulseA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);

  pinMode(PulseB, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
}

void loop() {

  int front_distance = FrontSonic.ping_cm();
  int rear_distance = BackSonic.ping_cm();

  //SoundFX1();
  /*
    beep(f, 250);
    beep(gS, 500);
    beep(f, 350);
    beep(a, 125);
    beep(cH, 500);
    beep(a, 375);
    beep(cH, 125);
    beep(eH, 650);
    delay(200);
  */

  //SoundFX2();
  /*
    beep(f, 250);
    beep(gS, 500);
    beep(f, 375);
    beep(cH, 125);
    beep(a, 500);
    beep(f, 375);
    beep(cH, 125);
    beep(a, 650);
    delay(200);
  */

  if (LSFrontRight || LSFrontLeft > 100 ) 
  {
    Serial.println("Starting......");
    Serial.println("--------------------------");
    Serial.println("Front Sensor");
    Serial.println("==========================");
    Serial.println("Front Ping Value:");
    Serial.println(front_distance);
    Serial.println("CM:");
    Serial.println();
    Serial.println("Rear Sensor");
    Serial.println("==========================");
    Serial.println("Rear Ping Value:");
    Serial.println(rear_distance);
    Serial.println("CM:");

    if (front_distance > 25)
    {
      searchMode();
      delay(100);
    }

    if (front_distance <= 25)
    {
      MoveForward();
      delay(300);
    }
    else
    {
      ScapeRotateLeft();
    }
    if (rear_distance <= 20)
    {
      ScapeRotateRight();
      delay(500);
      MoveForward();
      delay(100);
      FullStop();
    }
    else
    {
      MoveLeft();
      delay(300);
      MoveForward();
      delay(200);
      FullStop();
    }
  }

  // FRONT LINE SENSOR
  while (1)
  {
    LSFrontLeft = analogRead(14);
    LSFrontRight = analogRead(15);
    LSBackLeft = analogRead(16);
    LSBackRight = analogRead(17);
    if (LSFrontLeft < LineVal && LSFrontRight < LineVal)
    {
      MoveBackward();
      delay(300);

      if (LSFrontLeft < LineVal)
      {
        ScapeRotateRight();
        delay(300);
      }
      if (LSFrontRight < LineVal)
      {
        ScapeRotateLeft();
        delay(300);
      }
    }

    //REAR LINE SENSOR
    if ( LSBackLeft < LineVal && LSBackRight < LineVal)
    {
      MoveForward();
      delay(300);
    }
    if ( LSBackLeft < LineVal)
    {
      MoveRight();
      delay(300);
    }
    if (LSBackRight < LineVal)
    {
      MoveLeft();
      delay(300);
    }
  }
}

//START H-BRIDGE
void MoveForward()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 0);
  digitalWrite(IN2, 1);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 0);
}
void MoveBackward()
{
  analogWrite(PulseA, 150);
  digitalWrite(IN1, 0);
  digitalWrite(IN2, 1);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
}
//Turn 180*
void MoveRight()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
}
//Turn 180*
void MoveLeft()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
}
void ScapeRotateRight()
{
  analogWrite(PulseA, 150);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
}
void ScapeRotateLeft()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 150);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 0);
}

void FullStop()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 1);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 1);
}

void chargeOpt()
{
  analogWrite(PulseA, 250);
  digitalWrite(IN1, 0);
  digitalWrite(IN2, 1);
  analogWrite(PulseB, 250);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 0);
}
void defenseOpt()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
  delay(500);
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
}

void searchMode()
{
  analogWrite(PulseA, 150);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
  delay(500);
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 1);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 1);
  delay(500);
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 150);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 0);
}

// START SOUND FX & LIGHT INDICATOR

void beep(int note, int duration) {
  //tone(SoundFX, note, duration);
  if (FxCounter % 2 == 0) {
    digitalWrite(OutLedPin, 1);
    delay(duration);
    digitalWrite(OutLedPin, 0);
  }
  //noTone(SoundFX);
  delay(50);
  FxCounter++;
}

/*
  void SoundFX1()
  {
  beep(a, 500);
  beep(a, 500);
  beep(a, 500);
  beep(f, 350);
  beep(cH, 150);
  beep(a, 500);
  beep(f, 350);
  beep(cH, 150);
  beep(a, 650);

  delay(500);

  beep(eH, 500);
  beep(eH, 500);
  beep(eH, 500);
  beep(fH, 350);
  beep(cH, 150);
  beep(gS, 500);
  beep(f, 350);
  beep(cH, 150);
  beep(a, 650);

  delay(500);
  }
*/

/*
  void SoundFX2()
  {
  beep(aH, 500);
  beep(a, 300);
  beep(a, 150);
  beep(aH, 500);
  beep(gSH, 325);
  beep(gH, 175);
  beep(fSH, 125);
  beep(fH, 125);
  beep(fSH, 250);

  delay(325);

  beep(aS, 250);
  beep(dSH, 500);
  beep(dH, 325);
  beep(cSH, 175);
  beep(cH, 125);
  beep(b, 125);
  beep(cH, 250);

  delay(350);
  }
*/

 

 

/*ENA - 11
ENB - 9
IN1- D8
IN2- D10
IN3- D12
IN4- D13
LED- D6
BUZ- D7
A0 - Front Left Sensor
A1 - Front Right Sensor
A2 - Rear Left Sensor
A3 - Rear Right Sensor
Front Ultrasonic - ECHO - D3
Front Ultrasonic - TRIG - D2
Rear Ultrasonic - ECHO - D5
Rear Ultrasonic - TRIG - D4
==============================================================
*/
 
#include <NewPing.h>
//#include <Automaton.h>
//#include <timeObj.h>
//#include <pidDriver.h>
 
#define PulseA 11 //Optional
#define IN1 8
#define IN2 10
 
#define PulseB 9 //Optional
#define IN3 12
#define IN4 13
 
#define RTrigger 4
#define REcho 5
 
#define FTrigger 2
#define FEcho 3
 
//timeObj monTime (3000);
//boolean monMtr = false;
 
#define Front_Maximum_Distance  200
#define FrontMinimum_Distance  0
 
#define Rear_Maximum_Distance 180
#define Rear_Minimum_Diatance  0
 
int LineVal = 128;
int ReturnPath;
int Ping;
 
const int SoundFX = 7;
const int OutLedPin = 6;
int FxCounter = 0;
 
int LSFrontLeft;
int LSFrontRight;
int LSBackLeft;
int LSBackRight;
 
/*SOUND-FX*/
const int c = 261;
const int d = 294;
const int e = 329;
const int f = 349;
const int g = 391;
const int gS = 415;
const int a = 440;
const int aS = 455;
const int b = 466;
const int cH = 523;
const int cSH = 554;
const int dH = 587;
const int dSH = 622;
const int eH = 659;
const int fH = 698;
const int fSH = 740;
const int gH = 784;
const int gSH = 830;
const int aH = 880;
/*END OF SOUND FX*/
 
//int ObstacleAvoidance_Left; //Optional
//int ObstacleAvoidance_Right; //Optional
 
NewPing FrontSonic (FTrigger,FEcho, Front_Maximum_Distance);
NewPing BackSonic (RTrigger, REcho, Rear_Maximum_Distance);
 
void setup(){
 
    Serial.begin(115200);
    pinMode(SoundFX, OUTPUT);
    pinMode(OutLedPin, OUTPUT);
 
    pinMode(PulseA, OUTPUT);
    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);
 
    pinMode(PulseB, OUTPUT);
    pinMode(IN3, OUTPUT);
    pinMode(IN4, OUTPUT);
 
}
 
void loop(){
 
   int front_distance = FrontSonic.ping_cm();
   int rear_distance = BackSonic.ping_cm();
 
   SoundFX1();
   beep(f, 250);  
   beep(gS, 500);  
   beep(f, 350);  
   beep(a, 125);
   beep(cH, 500);
   beep(a, 375);  
   beep(cH, 125);
   beep(eH, 650);
   delay(200);
 
   SoundFX2();
   beep(f, 250);  
   beep(gS, 500);  
   beep(f, 375);  
   beep(cH, 125);
   beep(a, 500);  
   beep(f, 375);  
   beep(cH, 125);
   beep(a, 650);  
   delay(200);
 
   if (LSFrontRight || LSFrontLeft > 100 ) {
  
   Serial.println("Starting......");
   Serial.println("--------------------------");
   Serial.println("Front Sensor");
   Serial.println("==========================");
   Serial.println("Front Ping Value:");
   Serial.println(front_distance);
   Serial.println("CM:");
   Serial.println();
   Serial.println("Rear Sensor");
   Serial.println("==========================");
   Serial.println("Rear Ping Value:");
   Serial.println(rear_distance);
   Serial.println("CM:");
 
   if (front_distance > 25){
       searchMode();
       delay(100);
   }
 
   if (front_distance <= 25){
       MoveForward();
       delay(300);
   }
   else {
       ScapeRotateLeft();
   }
   if (rear_distance <= 20){
      ScapeRotateRight();
       delay(500);
       MoveForward();
       delay(100);
       FullStop();
   }
   else {
       MoveLeft();
       delay(300);
       MoveForward();
       delay(200);
       FullStop();
   }
 
   }
 
   while(1)
 
   // FRONT LINE SENSOR
   {
     LSFrontLeft = analogRead(14);
     LSFrontRight = analogRead(15);
     LSBackLeft = analogRead(16);
     LSBackRight = analogRead(17);
     if (LSFrontLeft < LineVal && LSFrontRight < LineVal){
            MoveBackward();
            delay(300);
 
     if (LSFrontLeft < LineVal){
             ScapeRotateRight();
             delay(300);
     }
 
     if (LSFrontRight < LineVal){
             ScapeRotateLeft();
             delay(300);
         }
     }
 
   //REAR LINE SENSOR
     if ( LSBackLeft < LineVal && LSBackRight < LineVal){
          MoveForward();
          delay(300);
 
     } if ( LSBackLeft < LineVal){
        MoveRight();
        delay(300);
 
     } if(LSBackRight < LineVal){
         MoveLeft();
         delay(300);
     }
   }
}
 
//START H-BRIDGE
void MoveForward(){
analogWrite(PulseA, 200);
digitalWrite(IN1, 0);
digitalWrite(IN2, 1);
analogWrite(PulseB, 200);
digitalWrite(IN3, 1);
digitalWrite(IN4, 0);
}
void MoveBackward(){
analogWrite(PulseA, 150);
digitalWrite(IN1, 0);
digitalWrite(IN2, 1);
analogWrite(PulseB, 200);
digitalWrite(IN3, 0);
digitalWrite(IN4, 1);
}
//Turn 180*
void MoveRight(){
analogWrite(PulseA, 200);
digitalWrite(IN1, 1);
digitalWrite(IN2, 0);
analogWrite(PulseB, 200);
digitalWrite(IN3, 0);
digitalWrite(IN4, 1);
}
//Turn 180*
void MoveLeft(){
analogWrite(PulseA, 200);
digitalWrite(IN1, 1);
digitalWrite(IN2, 0);
analogWrite(PulseB, 200);
digitalWrite(IN3, 0);
digitalWrite(IN4, 1);
}
void ScapeRotateRight(){
analogWrite(PulseA, 150);
digitalWrite(IN1, 1);
digitalWrite(IN2, 0);
analogWrite(PulseB, 200);
digitalWrite(IN3, 0);
digitalWrite(IN4, 1);
}
void ScapeRotateLeft(){
analogWrite(PulseA, 200);
digitalWrite(IN1, 1);
digitalWrite(IN2, 0);
analogWrite(PulseB, 150);
digitalWrite(IN3, 1);
digitalWrite(IN4, 0);
}
 
void FullStop(){
analogWrite(PulseA, 200);
digitalWrite(IN1, 1);
digitalWrite(IN2, 1);
analogWrite(PulseB, 200);
digitalWrite(IN3, 1);
digitalWrite(IN4, 1);
}
 
void chargeOpt(){
analogWrite(PulseA, 250);
digitalWrite(IN1, 0);
digitalWrite(IN2, 1);
analogWrite(PulseB, 250);
digitalWrite(IN3, 1);
digitalWrite(IN4, 0);
}
void defenseOpt(){
analogWrite(PulseA, 200);
digitalWrite(IN1, 1);
digitalWrite(IN2, 0);
analogWrite(PulseB, 200);
digitalWrite(IN3, 0);
digitalWrite(IN4, 1);
delay(500);
analogWrite(PulseA, 200);
digitalWrite(IN1, 1);
digitalWrite(IN2, 0);
analogWrite(PulseB, 200);
digitalWrite(IN3, 0);
digitalWrite(IN4, 1);
}
 
void searchMode(){
analogWrite(PulseA, 150);
digitalWrite(IN1, 1);
digitalWrite(IN2, 0);
analogWrite(PulseB, 200);
digitalWrite(IN3, 0);
digitalWrite(IN4, 1);
delay(500);
analogWrite(PulseA, 200);
digitalWrite(IN1, 1);
digitalWrite(IN2, 1);
analogWrite(PulseB, 200);
digitalWrite(IN3, 1);
digitalWrite(IN4, 1);
delay(500);
analogWrite(PulseA, 200);
digitalWrite(IN1, 1);
digitalWrite(IN2, 0);
analogWrite(PulseB, 150);
digitalWrite(IN3, 1);
digitalWrite(IN4, 0);
}
 
// START SOUND FX & LIGHT INDICATOR
 
void beep(int note, int duration){
    tone(SoundFX, note, duration);
    if(FxCounter % 2 == 0){
        digitalWrite(OutLedPin, 1);
        delay(duration);
        digitalWrite(OutLedPin, 0);
    }
    noTone(SoundFX);
    delay(50);
    FxCounter++;
}
 
void SoundFX1()
{
  beep(a, 500);
  beep(a, 500);    
  beep(a, 500);
  beep(f, 350);
  beep(cH, 150);  
  beep(a, 500);
  beep(f, 350);
  beep(cH, 150);
  beep(a, 650);
 
  delay(500);
 
  beep(eH, 500);
  beep(eH, 500);
  beep(eH, 500);  
  beep(fH, 350);
  beep(cH, 150);
  beep(gS, 500);
  beep(f, 350);
  beep(cH, 150);
  beep(a, 650);
 
  delay(500);
}
 
void SoundFX2()
{
  beep(aH, 500);
  beep(a, 300);
  beep(a, 150);
  beep(aH, 500);
  beep(gSH, 325);
  beep(gH, 175);
  beep(fSH, 125);
  beep(fH, 125);    
  beep(fSH, 250);
 
  delay(325);
 
  beep(aS, 250);
  beep(dSH, 500);
  beep(dH, 325);  
  beep(cSH, 175);  
  beep(cH, 125);  
  beep(b, 125);  
  beep(cH, 250);  
 
  delay(350);
}

So i was building a sumo robot and i have not finis scholl yet so i dont now how to program that well.So i foud this website https://www.14core.com/14core-mini-sumo-robot-with-multi-senors-on-arduino-microcontroller/ witch gave me the codee wit a diagram to comlit the programing of my robot.And wen i wana compile it it shows me this ereo 'ecit status 1' "

Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

(.text+0x0): multiple definition of `__vector_7'

libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Nano.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences. "

pls help me

 

the code can be downloaded

sorry for my English but i am not a native speaker

 

Udzdzdzdzntitled-1.png

SUMO_CODE.ino

Link to comment
Share on other sites

Link to post
Share on other sites

From the error that you posted

2 hours ago, Symbolls said:

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

(.text+0x0): multiple definition of `__vector_7'

libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here

it looks like a couple of the libraries that are being used are conflicting. The NewPing library is used directly by your code (you have #include <NewPing.h>, but there is nothing that is explicitly including Tone. Because the code is in C, that doesn't mean that the libraries aren't both required though, because dependencies can be brought in transitively.

 

I don't know how Arduino handles compile time dependencies, but there should be a settings somewhere for "libraries" or "dependencies" that may let you turn off Tone. However, there's no guarantee that it will allow your code to compile.

 

Do you have exactly the same robot as the authors of that guide? If yours is different, that code won't work.

HTTP/2 203

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Symbolls said:

So i was building a sumo robot and i have not finis scholl yet so i dont now how to program that well.So i foud this website https://www.14core.com/14core-mini-sumo-robot-with-multi-senors-on-arduino-microcontroller/ witch gave me the codee wit a diagram to comlit the programing of my robot.And wen i wana compile it it shows me this ereo 'ecit status 1' "

Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

(.text+0x0): multiple definition of `__vector_7'

libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Nano.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences. "

pls help me

 

the code can be downloaded

sorry for my English but i am not a native speaker

<snip>

 

@colonel_mortis hit the nail on the head, tone and new_ping don't play nice together, get rid of the buzzer.

 

Compiles, working? idk, didn't test it.

Spoiler

//Note: You can customize the pin configuration as you want
//Note: Some code below is not yet calibrated.
//--------------------------------------------------------------
/*ENA - 11
  ENB - 9
  IN1- D8
  IN2- D10
  IN3- D12
  IN4- D13
  LED- D6
  BUZ- D7 - remove!
  A0 - Front Left Sensor
  A1 - Front Right Sensor
  A2 - Rear Left Sensor
  A3 - Rear Right Sensor
  Front Ultrasonic - ECHO - D3
  Front Ultrasonic - TRIG - D2
  Rear Ultrasonic - ECHO - D5
  Rear Ultrasonic - TRIG - D4
  ==============================================================
*/

//#include <NewPing.h>
#include "NewPing.h" //https://www.14core.com/wp-content/uploads/2017/02/NewPing.zip
//#include <Automaton.h>
//#include <timeObj.h>
//#include <pidDriver.h>

#define PulseA 11 //Optional
#define IN1 8
#define IN2 10

#define PulseB 9 //Optional
#define IN3 12
#define IN4 13

#define RTrigger 4
#define REcho 5

#define FTrigger 2
#define FEcho 3

//timeObj monTime (3000);
//boolean monMtr = false;

#define Front_Maximum_Distance  200
#define FrontMinimum_Distance  0

#define Rear_Maximum_Distance 180
#define Rear_Minimum_Diatance  0

int LineVal = 128;
int ReturnPath;
int Ping;

//const int SoundFX = 7;
const int OutLedPin = 6;
int FxCounter = 0;

int LSFrontLeft;
int LSFrontRight;
int LSBackLeft;
int LSBackRight;

/*SOUND-FX
  const int c = 261;
  const int d = 294;
  const int e = 329;
  const int f = 349;
  const int g = 391;
  const int gS = 415;
  const int a = 440;
  const int aS = 455;
  const int b = 466;
  const int cH = 523;
  const int cSH = 554;
  const int dH = 587;
  const int dSH = 622;
  const int eH = 659;
  const int fH = 698;
  const int fSH = 740;
  const int gH = 784;
  const int gSH = 830;
  const int aH = 880;
  END OF SOUND FX*/

//int ObstacleAvoidance_Left; //Optional
//int ObstacleAvoidance_Right; //Optional

NewPing FrontSonic (FTrigger, FEcho, Front_Maximum_Distance);
NewPing BackSonic (RTrigger, REcho, Rear_Maximum_Distance);

void setup() {
  Serial.begin(115200);
  //pinMode(SoundFX, OUTPUT);
  pinMode(OutLedPin, OUTPUT);

  pinMode(PulseA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);

  pinMode(PulseB, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
}

void loop() {

  int front_distance = FrontSonic.ping_cm();
  int rear_distance = BackSonic.ping_cm();

  //SoundFX1();
  /*
    beep(f, 250);
    beep(gS, 500);
    beep(f, 350);
    beep(a, 125);
    beep(cH, 500);
    beep(a, 375);
    beep(cH, 125);
    beep(eH, 650);
    delay(200);
  */

  //SoundFX2();
  /*
    beep(f, 250);
    beep(gS, 500);
    beep(f, 375);
    beep(cH, 125);
    beep(a, 500);
    beep(f, 375);
    beep(cH, 125);
    beep(a, 650);
    delay(200);
  */

  if (LSFrontRight || LSFrontLeft > 100 ) 
  {
    Serial.println("Starting......");
    Serial.println("--------------------------");
    Serial.println("Front Sensor");
    Serial.println("==========================");
    Serial.println("Front Ping Value:");
    Serial.println(front_distance);
    Serial.println("CM:");
    Serial.println();
    Serial.println("Rear Sensor");
    Serial.println("==========================");
    Serial.println("Rear Ping Value:");
    Serial.println(rear_distance);
    Serial.println("CM:");

    if (front_distance > 25)
    {
      searchMode();
      delay(100);
    }

    if (front_distance <= 25)
    {
      MoveForward();
      delay(300);
    }
    else
    {
      ScapeRotateLeft();
    }
    if (rear_distance <= 20)
    {
      ScapeRotateRight();
      delay(500);
      MoveForward();
      delay(100);
      FullStop();
    }
    else
    {
      MoveLeft();
      delay(300);
      MoveForward();
      delay(200);
      FullStop();
    }
  }

  // FRONT LINE SENSOR
  while (1)
  {
    LSFrontLeft = analogRead(14);
    LSFrontRight = analogRead(15);
    LSBackLeft = analogRead(16);
    LSBackRight = analogRead(17);
    if (LSFrontLeft < LineVal && LSFrontRight < LineVal)
    {
      MoveBackward();
      delay(300);

      if (LSFrontLeft < LineVal)
      {
        ScapeRotateRight();
        delay(300);
      }
      if (LSFrontRight < LineVal)
      {
        ScapeRotateLeft();
        delay(300);
      }
    }

    //REAR LINE SENSOR
    if ( LSBackLeft < LineVal && LSBackRight < LineVal)
    {
      MoveForward();
      delay(300);
    }
    if ( LSBackLeft < LineVal)
    {
      MoveRight();
      delay(300);
    }
    if (LSBackRight < LineVal)
    {
      MoveLeft();
      delay(300);
    }
  }
}

//START H-BRIDGE
void MoveForward()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 0);
  digitalWrite(IN2, 1);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 0);
}
void MoveBackward()
{
  analogWrite(PulseA, 150);
  digitalWrite(IN1, 0);
  digitalWrite(IN2, 1);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
}
//Turn 180*
void MoveRight()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
}
//Turn 180*
void MoveLeft()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
}
void ScapeRotateRight()
{
  analogWrite(PulseA, 150);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
}
void ScapeRotateLeft()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 150);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 0);
}

void FullStop()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 1);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 1);
}

void chargeOpt()
{
  analogWrite(PulseA, 250);
  digitalWrite(IN1, 0);
  digitalWrite(IN2, 1);
  analogWrite(PulseB, 250);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 0);
}
void defenseOpt()
{
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
  delay(500);
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
}

void searchMode()
{
  analogWrite(PulseA, 150);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 0);
  digitalWrite(IN4, 1);
  delay(500);
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 1);
  analogWrite(PulseB, 200);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 1);
  delay(500);
  analogWrite(PulseA, 200);
  digitalWrite(IN1, 1);
  digitalWrite(IN2, 0);
  analogWrite(PulseB, 150);
  digitalWrite(IN3, 1);
  digitalWrite(IN4, 0);
}

// START SOUND FX & LIGHT INDICATOR

void beep(int note, int duration) {
  //tone(SoundFX, note, duration);
  if (FxCounter % 2 == 0) {
    digitalWrite(OutLedPin, 1);
    delay(duration);
    digitalWrite(OutLedPin, 0);
  }
  //noTone(SoundFX);
  delay(50);
  FxCounter++;
}

/*
  void SoundFX1()
  {
  beep(a, 500);
  beep(a, 500);
  beep(a, 500);
  beep(f, 350);
  beep(cH, 150);
  beep(a, 500);
  beep(f, 350);
  beep(cH, 150);
  beep(a, 650);

  delay(500);

  beep(eH, 500);
  beep(eH, 500);
  beep(eH, 500);
  beep(fH, 350);
  beep(cH, 150);
  beep(gS, 500);
  beep(f, 350);
  beep(cH, 150);
  beep(a, 650);

  delay(500);
  }
*/

/*
  void SoundFX2()
  {
  beep(aH, 500);
  beep(a, 300);
  beep(a, 150);
  beep(aH, 500);
  beep(gSH, 325);
  beep(gH, 175);
  beep(fSH, 125);
  beep(fH, 125);
  beep(fSH, 250);

  delay(325);

  beep(aS, 250);
  beep(dSH, 500);
  beep(dH, 325);
  beep(cSH, 175);
  beep(cH, 125);
  beep(b, 125);
  beep(cH, 250);

  delay(350);
  }
*/

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

18 hours ago, colonel_mortis said:

From the error that you posted

it looks like a couple of the libraries that are being used are conflicting. The NewPing library is used directly by your code (you have #include <NewPing.h>, but there is nothing that is explicitly including Tone. Because the code is in C, that doesn't mean that the libraries aren't both required though, because dependencies can be brought in transitively.

 

I don't know how Arduino handles compile time dependencies, but there should be a settings somewhere for "libraries" or "dependencies" that may let you turn off Tone. However, there's no guarantee that it will allow your code to compile.

 

Do you have exactly the same robot as the authors of that guide? If yours is different, that code won't work.

yes i have the exact same configuration of sensors

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×