We are trying to implement an Arduino with the HC-SR04 sensors that will transmit the values of the sensor to another Arduino using an NRF24L01 transceiver. We believe that there is no problem with the setup of our sensors and the transmitter. In order to receive the values from the sonar we are using the NewPing library. The problem that we run into is that, that the moment we turn on the transmitter using radio.begin() in the code, the sonar values are 0 but it can transmit a set data value. When we don't turn on the transmitter we get the proper sonar values. Here is our code for transmitting the data. Please reply as soon as possible we are on a time crunch.
#include <SPI.h> // Comes with Arduino IDE
#include "RF24.h"
#include <NewPing.h>
#include <RF24_config.h>
#define tRight 11
#define eRight 10
#define tLeft 5
#define eLeft 6
#define tBack 13
#define eBack 12
#define max_dist 150
RF24 myRadio (7, 8);
NewPing sonarR(tRight, eRight, max_dist);
NewPing sonarL(tLeft, eLeft, max_dist);
NewPing sonarB(tBack, eBack, max_dist);
byte addresses[][6] = {"1Node"};
int sensorValue = 100;
void setup(){
pinMode(tRight, OUTPUT);
pinMode(eRight, INPUT);
myRadio.begin();
myRadio.setChannel(110);
myRadio.setPALevel(RF24_PA_MAX);
myRadio.openWritingPipe( addresses[0]);
Serial.begin(9600);
// delay(1000);
}
void loop(){
myRadio.write( &sensorValue, sizeof(sensorValue) );
Serial.println("SENT");
int R = sonarR.ping_cm();
int L = sonarL.ping_cm();
int B = sonarB.ping_cm();
Serial.print("Right: ");
Serial.println(R);
Serial.print("Left: ");
Serial.println(L);
Serial.print("Back: ");
Serial.println(B);
if(R<= 15 && R != 0.00){
Serial.println("Object on RIGHT is too close!");
}
if(L<= 15 && L != 0.00){
Serial.println("Object on LEFT is too close!");
}
if(B<= 15 && B != 0.00){
Serial.println("Object in BACK is too close!");
}
Serial.println("____________________________");
delay(1000);
}
Manual_Ping_transmit.ino (1.28 KB)