Cant add SRF02 library

Hello, i am building law mower from this site: https://www.open-electronics.org/a-robotic-lawn-mowers-powered-by-solar-energy-with-an-arduino-heart/

I have putted all hardware in and it is time for a code, but there is used custom library SRF02 for sensors and it doesnt work for me. Like i have added it, and i see it added in Arduino IDE but i still get error. Can you help me?

exit status 1

Compilation error: SRF02.h: No such file or directory

Welcome to the forum

How exactly did you add the library ?

Please post your full sketch using code tags (the </> icon) when you do

  SolarMower V1.0
  SolarMower use mowershield_FE
  2014 Mirco Segatello
  For hardware see www.elettronicain.it
  
  Press PEN during power-on for ESC test  
  Press PUP during power-on for test motor
  Press PDW during power-on for test sensor
 */

#include <EEPROM.h>
#include <SoftwareSerial.h>
#include <Servo.h> 
#include <Wire.h>
#include <SRF02.h>
#include <Configuration.h>

#define D22DIRA_pin (22)
#define D23DIRB_pin (23)

Servo ESC;

//variables
float VBat;               // Battery voltage [V]
int VBatPC;               // Battery voltage percentage
float VBatScale=0.054;    // Battery scale for Volt converter
float IPanel;             // Panel current [A]
float IPanelOffset;       // Panel current offset
float IPanelScale=0.185;  // Panel current scale V/A
float ICut;               // Motor cut current [A]
float ICutOffset;         // Motor cut current offset
float ICutScale=0.185;    // Motor cut current scale V/A
int i;
int cutPower=0;           // Cut Power from 0%=ESC_MIN_SIGNAL to 100%=ESC_MAX_SIGNAL
int cutPower_uSec=ESC_MIN_SIGNAL;      // Cut Power from ESC_MIN_SIGNAL to ESC_MAX_SIGNAL
int oldSpeed=0;           // Speed of mower (0-255)
float IPanelMax=0;           // IPanel max current
unsigned long BWFL_count;
unsigned long BWFR_count;
unsigned long previousMillis = 0;
unsigned long currentMillis; 
volatile int mowerStatus=0; // 0=oncharge (press pen for run)
                            // 1=run
                            // 2=stuck
                            // 3=search
                            // 4=batlow
                            // 5=charge and restart when full
                            // 6=cuterror
volatile unsigned long wheelTime=0;

// LCD does not send data back to the Arduino, only define the txPin
SoftwareSerial LCD = SoftwareSerial(0, LCD_pin);
int LCD_Page = 0;         // Page to display

SRF02 US_SX(US_SX_address, SRF02_CENTIMETERS);
SRF02 US_DX(US_DX_address, SRF02_CENTIMETERS);




void setup() 
{
  Serial.begin(9600);
  Wire.begin();
  pinMode(Encoder_Pin, INPUT_PULLUP);
  pinMode(PWMA_pin, OUTPUT);
  pinMode(DIRA_pin, OUTPUT);  
  pinMode(BWFR_pin, INPUT);
  pinMode(BWFL_pin, INPUT);    
  pinMode(Panel_pin, OUTPUT);  
  pinMode(ESC_pin, OUTPUT);  
  pinMode(SWOR_pin, INPUT_PULLUP);
  pinMode(SWOL_pin, INPUT_PULLUP);       
  pinMode(PWMB_pin, OUTPUT);
  pinMode(DIRB_pin, OUTPUT);   
  pinMode(LCD_pin, OUTPUT); 

  pinMode(D22DIRA_pin, OUTPUT);
  pinMode(D23DIRB_pin, OUTPUT);

  digitalWrite(D22DIRA_pin, LOW); 
  digitalWrite(D23DIRB_pin, LOW);

  digitalWrite(DIRA_pin, LOW); 
  digitalWrite(DIRB_pin, LOW);   
  analogWrite(PWMA_pin, 0);
  analogWrite(PWMB_pin, 0);  
  digitalWrite(Panel_pin, LOW);   

 
  // For SerialMonitor diagnostic 
  Serial.println("Solar Mower V1.0\n"); 
  Serial.println("Init ESC..."); 
  ESC.attach(ESC_pin);
  cutOFF(); 
  
  Serial.println("Init SerLCD...");       
  serLCDInit();   
  clearLCD();
  lcdPosition(0,0);
  LCD.print("Solar Mower v1.0");
  lcdPosition(1,0);
  LCD.print("Init...");      
  

  Serial.println("Init Sensor");  
  sensorInit();  
  Serial.print("IPanelOffset= ");
  Serial.println(IPanelOffset);
  Serial.print("ICutOffset= ");
  Serial.println(ICutOffset);  
  Serial.println(); 


  // TEST MOTOR
  if (Button(Button_pin)==PUP) 
  {
    while(1)
    {
      clearLCD();
      lcdPosition(0,0);
      LCD.print("Test motor");
      lcdPosition(1,0);  
      LCD.print("PEN begin test  ");  
      Serial.println("Press PEN for begin motor test"); 
      while (Button(Button_pin)!=3) { }
      testMotor();
    }   
  }   
  
  //TEST SENSOR
  if (Button(Button_pin)==PDW) 
  { 
      clearLCD();
      lcdPosition(0,0);
      LCD.print("Test sensor");    
      Serial.println("Test sensor");
      delay(1000);
    while(1)
    {
      sensorReading();
      
      clearLCD();
      lcdPosition(0,0);
      LCD.print("VB=");
      LCD.print(VBat);
      
      lcdPosition(0,9); 
      if ((US_DX.read()>0) && (US_DX.read()<USdistance))   {
            LCD.print("UsDX ");
            Serial.println("UsDX");
      }      
      if ((US_SX.read()>0) && (US_SX.read()<USdistance)) {
            LCD.print("UsSX ");   
            Serial.println("UsSX");            
      }      
      if ( (BWFL_count>3000) && (BWFL_count<4000) ) {
            LCD.print("BWFL");
            Serial.println("BWFL");
      }      
      if ( (BWFR_count>2000) && (BWFR_count<4000) ) {
            LCD.print("BWFR");    
            Serial.println("BWFR");            
      }      
      if (digitalRead(Encoder_Pin)==0) {
            LCD.print("Encoder");
            Serial.println("Encoder");            
      }      
      if (digitalRead(SWOR_pin)==0) {
            LCD.print("SWOR");
            Serial.println("SWOR");            
      }      
      if (digitalRead(SWOL_pin)==0) {
            LCD.print("SWOL");       
            Serial.println("SWOL");            
      }      
      if (Button(Button_pin)==1) {
            LCD.print("PUP");
            Serial.println("PUP");            
      }      
      if (Button(Button_pin)==2) {
            LCD.print("PDW");  
            Serial.println("PDW");            
      }            
      if (Button(Button_pin)==3) {
            LCD.print("PEN");
            Serial.println("PEN");            
      }      
      
      lcdPosition(1,0);
      LCD.print("IC=");
      LCD.print(ICut);  
      Serial.print("IC=");     
      Serial.println(ICut);       
      lcdPosition(1,9);
      LCD.print("IP=");
      LCD.print(IPanel);  
      Serial.print("IP=");     
      Serial.println(IPanel);        

      delay(250);  
    }
  }    
  
  //TEST ESC
  if (Button(Button_pin)==PEN)   
  {
    Serial.println("Test ESC...");   
    clearLCD();
    lcdPosition(0,0);
    LCD.print("Test ESC");
    while(1)
    {
        sensorReading();
        cutPower = map(cutPower_uSec, ESC_MIN_SIGNAL, ESC_MAX_SIGNAL, 0, 100);
        lcdPosition(0,9);
        LCD.print("IC=");
        LCD.print(ICut);          
        lcdPosition(1,0);  
        LCD.print("cutPower="); 
        LCD.print(cutPower);
        LCD.print("%  ");
        Serial.print("cutPower=");
        Serial.print(cutPower);
        Serial.print("%   usec=");
        Serial.println(cutPower_uSec);
        
        if (Button(Button_pin)==2) 
           if (cutPower_uSec<ESC_MAX_SIGNAL) cutPower_uSec += 20;
        if (Button(Button_pin)==1) 
           if (cutPower_uSec>ESC_MIN_SIGNAL) cutPower_uSec -= 20;      
           
        ESC.writeMicroseconds(cutPower_uSec);
        delay(200);   
    } 
  } 
  attachInterrupt(0, rotate, FALLING);
}


void loop() 
{
  //main program
  digitalWrite(Panel_pin, HIGH);  

  main: 
  //wait for PEN press
  /*while(Button(Button_pin)!=3) 
  { 
    currentMillis = millis();
    if(currentMillis - previousMillis > timeClock) 
    {    
        sensorReading(); 
        LCDdebug();
    }  
  }  */
  
  Serial.println("GO!");      
  mowerStatus=1;
  IPanelMax=0;
  LCDdebug();  
  cutON();
  setMowerSpeed(255);


  //main loop    
  while(1)
  { 
    
    //ferma tutto
    if (Button(Button_pin)==PUP || Button(Button_pin)==PDW)
    {
      cutOFF();  
      setMowerSpeed(0);
      mowerStatus=0;
      goto main; 
    }

    //if not an interrupt wheels occurs within 10 seconds, the robot is blocked
    if (millis()>wheelTime+10000)
    {
      cutOFF();  
      setMowerSpeed(0);
      mowerStatus=2;
      goto main;       
    }
    
    // gestione sensori ostacolo
    if (digitalRead(SWOL_pin)==LOW) obstacleAvoidSX();   
    if (digitalRead(SWOR_pin)==LOW) obstacleAvoidDX();       
       
    
    // reads the sensors every timeClock
    currentMillis = millis();
    if(currentMillis - previousMillis > timeClock) 
    {
      previousMillis = currentMillis; 

      sensorReading(); 
        
      if ((US_DX.read()>0) && (US_DX.read()<USdistance)) 
      {
            obstacleAvoidSX();  
            resetEncoder();
      }      
      if ((US_SX.read()>0) && (US_SX.read()<USdistance)) 
      {
            obstacleAvoidDX();      
            resetEncoder();
      }      
      if ((BWFL_count>3000) && (BWFL_count<4000))
      {
            obstacleAvoidSX();  
            resetEncoder();
      }      
      if ((BWFR_count>2000) && (BWFR_count<4000)) 
      {       
            obstacleAvoidDX();     
            resetEncoder();
      }      
      
      
      //**********************************************************************
      if (IPanel>IPanelMax) IPanelMax=IPanel; //memory to max current on panel
      
      //battery lower then 10% then searching the point to charge
      if (VBatPC<10) 
      {                
        mowerStatus=3;
        cutOFF();  //stop cut
      }  
      
      //continues to advance until it finds a light source at least 80% of the previous maximum.
      if (mowerStatus==3)
      {     
        if  (IPanel>IPanelMax*0.8) 
        {
          setMowerSpeed(0);
          mowerStatus=5; //charge with restart
        }    
      }
      //**********************************************************************
      
      if (mowerStatus==5)
      {
        resetEncoder();
        // full charge then restart
        if (VBatPC>=100)
        {
            mowerStatus=1;
            IPanelMax=0;
            cutON();
            setMowerSpeed(255);         
        }    
      }  
        
      if (VBat > VBat_Level_Max)
      {
         //lead battery never stop charge 
         //disable charge only for lipo battery
         //digitalWrite(Panel_pin, LOW); 
      } 
      
      //battery is completely discharged      
      if (VBat < VBat_Level_Min) 
      {
        cutOFF();  
        setMowerSpeed(0);
        digitalWrite(Panel_pin, HIGH); 
        mowerStatus=4;
        goto main;       
      } 
      
      // ICut too high 
      if (ICut > ICut_Max) 
      {
        cutOFF();  
        setMowerSpeed(0);
        digitalWrite(Panel_pin, HIGH); 
        mowerStatus=6;
        goto main;       
      }       
      
      serialDebug();      
      LCDdebug();    
      }
  }  
}

void rotate()
{
  wheelTime=millis();   
}

void resetEncoder()  //reset value for block wheels
{
  wheelTime=millis();   
}

void obstacleAvoidSX()
{
      // obstacle avoid
      setMowerSpeed(-PWMSpeed);
      delay(timeReverse);
      setMowerRotate(-PWMSpeed); //gira a sinistra
      delay(timeRotate);
      setMowerSpeed(PWMSpeed);
}

void obstacleAvoidDX()
{
      // obstacle avoid     
      setMowerSpeed(-PWMSpeed);
      delay(timeReverse);
      setMowerRotate(PWMSpeed);
      delay(timeRotate);
      setMowerSpeed(PWMSpeed);   
}


void setMowerRotate(int newSpeed)
{ 
  //rotate mower (first set speed at zero) 
  constrain(newSpeed, -255, 255);
    for (i=oldSpeed; i>=0; i--)
    {
       analogWrite(PWMA_pin, i);
       analogWrite(PWMB_pin, i);
       delay(accelerateTime);
    }      
    oldSpeed=0;
    
  if (newSpeed<0) 
  {  
    digitalWrite(DIRA_pin, HIGH);
    digitalWrite(D22DIRA_pin, LOW);
    digitalWrite(DIRB_pin, LOW);
    digitalWrite(D23DIRB_pin, LOW);   
    newSpeed=-newSpeed;    
  }
  else
  {
    digitalWrite(DIRA_pin, LOW); 
    digitalWrite(D22DIRA_pin, LOW);
    digitalWrite(DIRB_pin, HIGH); 
    digitalWrite(D23DIRB_pin, LOW);   
  }  
  
  for (i=0; i<=newSpeed; i++)
  {
       analogWrite(PWMA_pin, i);
       analogWrite(PWMB_pin, i);
       delay(accelerateTime);
  }  
  oldSpeed=newSpeed;
}


void setMowerSpeed(int newSpeed)
{
  //set new speed for mower (first set speed at zero) 
  constrain(newSpeed, -255, 255);
    for (i=oldSpeed; i>=0; i--)
    {
       analogWrite(PWMA_pin, i);
       analogWrite(PWMB_pin, i);
       delay(accelerateTime);
    }    
    oldSpeed=0; 
  
  if (newSpeed<0)
  {  
    digitalWrite(DIRA_pin, HIGH); 
    digitalWrite(D22DIRA_pin, LOW);
    digitalWrite(DIRB_pin, HIGH);  
    digitalWrite(D23DIRB_pin, LOW);  
    newSpeed=-newSpeed;
  }
  else
  {
    digitalWrite(DIRA_pin, LOW);
    digitalWrite(D22DIRA_pin, HIGH); 
    digitalWrite(DIRB_pin, LOW); 
    digitalWrite(D23DIRB_pin, HIGH);   
  }
  
  if (newSpeed > oldSpeed)
  {
    for (i=oldSpeed; i<=newSpeed; i++)
    {
       analogWrite(PWMA_pin, i);
       analogWrite(PWMB_pin, i);
       delay(accelerateTime);
    }   
  }
  else
  {
    for (i=oldSpeed; i>=newSpeed; i--)
    {
       analogWrite(PWMA_pin, i);
       analogWrite(PWMB_pin, i);
       delay(accelerateTime);
    }        
  } 
  oldSpeed=newSpeed; 
}

 
void cutON()
{
  //cutter ON
  for (cutPower_uSec=ESC_MIN_SIGNAL; cutPower_uSec<=ESC_MAX_SIGNAL; cutPower_uSec += 10)
  {
    ESC.writeMicroseconds(cutPower_uSec);
    delay(50); 
  }
  wheelTime=millis(); 
}

void cutOFF()
{
  //cutter OFF
  ESC.writeMicroseconds(ESC_MIN_SIGNAL);      
}  

I am adding library by going into sketch and include library and then add zip library

Actually i have tried to add SRF05 library from Arduino Manage Library and changing my SRF02 to SRF05 and still it has error with no SRF05 library

What is the full path to your Sketchbook folder ?

You mean where my project is? Then it is C:\Users\Myusername\OneDrive\Desktop\lawnmower

Using OneDrive has been known to cause problems and could be the culprit here

The rest of the path looks odd too. Is there a libraries folder on your Desktop ?

If you go into File/Preferences in the IDE what is the Sketchbook location ?

I dont rly know, i think there is, like somewhere IDE needs to hold them. I am not using Arduino to much and when i was using it i used default libraries so i never had such problems.
Sketchbook location in IDE is c:\Users\Myusername\OneDrive\Documents\Arduino

I have tried to make folder in C: program files, still same error

My advice would be to create a new sketchbook folder, not a OneDrive folder, move all of your sketches to it and change the sketchbook setting in File/Preferences to the new folder. Then install the library that you want from its zip file using the IDE and it should be installed in a folder in the libraries folder which is in your sketchbook folder

When the IDE compiles a sketch it looks in fixed locations for libraries and one of these is the libraries folder in the sketchbook folder. You cannot install libraries in some arbitrary location and expect the IDE to find them

As an alternative, put the library files in the same folder as your sketch and use #include with quotation marks around the name of the library .h file and the compiler will look for it first in the local directory

? marks dont work. Okay i changed sketchbook settings in File/Preferences, now it is c:\Program Files\LawnMower\MowerRP but now i have error that i have access denied when i am trying to install library.

And i just accidentaly found folder with Arduino libraries, it is located in C:\Users\Myusername\OneDrive\Documents\Arduino

Windows places extra security restrictions on the c:\Program Files\ folder. This might be the cause of the error.

Try setting the "Sketchbook location" preference to some location that is not under c:\Program Files\ and then let us know whether the "Access denied" error still occurs when you attempt to install a library.

fells like srf02 is working now, but now i have problems with configuration.h
C:\Arduino sketchbooks\MowerRP\MowerRP.ino:17:10: fatal error: Configuration.h: No such file or directory
#include <Configuration.h>
^~~~~~~~~~~~~~~~~
compilation terminated.

exit status 1

Compilation error: Configuration.h: No such file or directory

Where on the PC is Configuration.h located ?

it is in the same location with mowerrp.ino so it is file C:\Arduino sketchbooks\MowerRP, but i kind a made code working, i checked configuration.h file and there was such code:

</* SolarMower Arduino */
/* configuration file */

#define ESC_MAX_SIGNAL 2000
#define ESC_MIN_SIGNAL 1000
#define VBat_Level_Min    0 //9.0
#define VBat_Level_Max    0 //13.8
#define ICut_Min 0.4      // not used on version 1.0
#define ICut_Max 2.0      // defines the maximum permissible current to the cut motor
#define accelerateTime 2  //total time accelerate = accelerationtime*255 [msec]
#define USdistance 30     //obstacle distance for ultrasonic sensor
#define timeReverse 3000  // duration reverse motor when obstacle detect
#define timeRotate  2000  // duration rotate motor when obstacle detect
#define PWMSpeed    255   // PWM value for thrust motor
#define timeClock   500   // time reading sensor
int PUP=1;
int PDW=2;
int PEN=3;

//Analog Pin
#define Button_pin     0  // Push button pin
#define ICut_pin       1  // Motor cut current
#define IPanel_pin     2  // Panel current
#define VBat_pin       3  // Battery voltage
#define SDA_pin        4  // SDA for I2C
#define SCL_pin        5  // SCL for I2C

//Digital pin
#define RXD_pin        0  // Arduino serial hardware RX
#define TXD_pin        1  // Arduino serial hardware TX
#define Encoder_Pin    2  // Wheels encoder
#define PWMA_pin       3  // PWM for motor A
#define DIRA_pin       4  // motor DIRA
#define BWFR_pin       5  // BWFR signal
#define BWFL_pin       6  // BWFL signal
#define Panel_pin      7  // Panel on/off
#define ESC_pin        8  // ESC for motor cut
#define SWOL_pin       9  // switch for right obstacle
#define SWOR_pin      10  // switch for lift obstacle
#define PWMB_pin      11  // PWM for motor B
#define DIRB_pin      12  // motor DIRB
#define LCD_pin       13  // LCD data signal

#define US_SX_address 0x70 //ultrasonic sensor SX address
#define US_DX_address 0x79 //ultrasonic sensor DX address/>

So i just copy pasted it in main sketch and then code in compiling, i think it doesnt affect anything. Tell me if i am wrong and i need to use exacly this part of code as configuration.h

That is why

#include <Configuration.h>

can't find it. If you want a sketch to look for a library file in the sketch directory before looking anywhere else then use

#include "Configuration.h"

If you are going to post code then please use code tags when you do

Yes, now everything is working properly, thanks for helping. I am trying to use tags, probably i dont understand something.

Edit your post
Select the code
Click the </> icon and the code tags will be added
Save the revised post
See how much easier the code tags make it to scroll and copy the code for examination

Ah, i think i got it. Now looks like everything is done right