Error while interfacing ultrasonic sensor with Arduino Promini

Hi all. I’m trying to interface an ultrasonic sensor with an Arudino Pro Mini. The goal is to develop a blind spot detection system prototype. I’m using a robot chassis with 4 ultrasonic sensors at 4 blind-spots of the chassis. I got the code online from someone who has done a similar project. The code is as follows,

#include <NewPing.h>
#define TRIGGER_PIN 5
#define ECHO_PIN 4
#define MAX_DISTANCE 300.
#include <SPI.h>
#include <nRF24L01.h>
char mypacket[3]; //int sendingByte;
NewPing sonar_LB (TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup()
{
Serial.begin(115200);
Serial.begin(9600);
Mirf.spi = &MirfHardwareSpi;
Mirf.csnPin = 8; // define CSN pin
Mirf.cePin = 9; // define CE pin
Mirf.init();
Mirf.setRADDR((byte *)"00010"); // receiving address
Mirf.setTADDR((byte *)"00010"); // transmitting address
Mirf.payload = sizeof(mypacket); // up to 32 byte only
Mirf.channel = 50; // pipeline channel
Mirf.config();
}
void loop() {
delay(50)
unsigned int uS_LB = sonar_LB.ping();
Serial.print("\n Ping: ");
Serial.print(uS_LB / US_ROUNDTRIP_CM);
Serial.println("cm");
if((uS_LB / US_ROUNDTRIP_CM) > 10)
{
mypacket[0]='L';
mypacket[1]='B';
mypacket[2]='O';
Mirf.send((byte *) &mypacket);
while(Mirf.isSending()){}
Serial.print("\n sending LB detected");
//delay (100);
}

else if((uS_LB / US_ROUNDTRIP_CM) >0 && (uS_LB / US_ROUNDTRIP_CM) < 10)
{
mypacket[0]='L';
mypacket[1]='B';
mypacket[2]='F';
Mirf.send((byte *) &mypacket);
while(Mirf.isSending()){}
Serial.print("\n sending LB not detected");
delay (100);
}

I have got the NewPing.h library from the Arduino Playground. The SPI library seems to be a part of Arduino IDE’s standard libraries as well. However, the nRF24L01.h library that he has used seems to be confusing me. I’ve tried using a few nrf24 libraries. I’m posting the error messages that I got below,

Arduino: 1.8.1 (Windows 10), Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

C:\Users\Kaushik\Documents\Arduino\ultrasonic_rear_left\ultrasonic_rear_left.ino: In function 'void setup()':

ultrasonic_rear_left:13: error: 'Mirf' was not declared in this scope

 Mirf.spi = &MirfHardwareSpi;

 ^

ultrasonic_rear_left:13: error: 'MirfHardwareSpi' was not declared in this scope

 Mirf.spi = &MirfHardwareSpi;

             ^

C:\Users\Kaushik\Documents\Arduino\ultrasonic_rear_left\ultrasonic_rear_left.ino: In function 'void loop()':

ultrasonic_rear_left:25: error: expected ';' before 'unsigned'

 unsigned int uS_LB = sonar_LB.ping();

 ^

ultrasonic_rear_left:27: error: 'uS_LB' was not declared in this scope

 Serial.print(uS_LB / US_ROUNDTRIP_CM);

              ^

ultrasonic_rear_left:34: error: 'Mirf' was not declared in this scope

 Mirf.send((byte *) &mypacket);

 ^

ultrasonic_rear_left:40: error: expected ';' before 'else'

 else if((uS_LB / US_ROUNDTRIP_CM) >0 && (uS_LB / US_ROUNDTRIP_CM) < 10)

 ^

ultrasonic_rear_left:49: error: expected '}' at end of input

 }

 ^

exit status 1
'Mirf' was not declared in this scope

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

I have downloaded a NRF24 library from airspayce. Similarly I changed the header file on the program to NRF24.h. This results in the above error.

Kindly help me out.

56?

I'm sorry. That was a typo while copy pasting the code.

Hi,
Welcome to the forum.

Did you write this code in stages?
Sorry misread, you didn't write it.

Can you tell us your electronics, programming, Arduino, hardware experience?

That is;

Get the PING library code working?

Get the nRF24l01 code working?

So that you had a number of codes for each aspect of your code that works, then combine them, one at a time.

You have more than just a sonar unit connected, please tell us what it does in full.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Hi Tom. Thank you for taking the time out to reply and assist me in this situation. I’m a newbie in this domain completely. I stumbled upon an interesting blind spot detection system proposed by someone else online and have decided to try to make it work.

https://goo.gl/neUskZ This link is to the pdf that I am working out of of. I have attached an image of the schematic diagram of my proposed system.

What the system should do is, the ultrasonic sensors attached to the promini must send the distance between the objects and the sensor to an Arduino Duemilanove. The Arduino Duemilanove powers a series of LEDs based on the threshold values to indicate the presence of objects in the blind spot to the driver. The codes for the promini and the duemilanove are present in the link that I have attached above.

The codes for the promini and the duemilanove are present in the link that I have attached above.

You are asking for help here, not there. Post your code HERE, in code tags, if you want help here. If you want help there, why are you here?