Hi, Can anyone help me. Im trying to transmit distance readings from an ultrasonic sensor from one arduino nano to the next using NRF - 24 modules. The modules work and so does the ultrasonic sensor. I merged the two and I have the transmitter and receiver code below. The readings are find on the end with the ultrasonic sensor but when they get transmitted over to the other arduino nano they dont show any readings. HOWEVER the reciever starts to pick up readings and displaying them perfectly when and only when the distance reading of the ultrasonic sensor is below 6 cm. Any thoughts?
transmitter
#include<SPI.h>
#include "RF24.h"
int msg[1];
RF24 radio(7,8);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int val;
int trig = 4;
const int & echo = 5;
int travel_time;
int distance;
int cm = 0;
void setup(void) {
radio.begin();
radio.openWritingPipe(pipe);
Serial.begin(9600);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
}
void loop(void) {
digitalWrite(trig, LOW);
delay (1);
digitalWrite(trig, HIGH);
delay (5);
digitalWrite(trig, LOW);
travel_time = pulseIn(echo, HIGH);
distance = (travel_time*0.034)/2;
msg[0] = distance;
Serial.println(msg[0]);
radio.write(msg, 1);
}
I made all those changes and got the same results which showed me that a few lines of code where unnecessary. I am still getting the same results now except instead of only displaying readings onece it gets down to 6 cm it displays them once it gets down to 9 cm. I don think that means much though. Also what do you mean by a int consisting of two bytes? I dont really understand that.
hert:
Im really sorry Im trying a bunch of stuff on my end but I dont exactly understand what you want me to do with the code. Can you be more descriptive.
You have to post the latest version of your programs (Tx and Rx) so we can see exactly what you have done. The devil is in the detail.