I Have a Liquid Level Project that Currently uses an Oled display. I have just discovered the existence of the nRF24L01 wireless communication module; and it is exactly what I need to make my project more user friendly.
Eventually I want to have a dashboard that brings all my info together in one place, but for now I just want to figure out how to get my Liquid Level Project transmitting, and receive the data on another Arduino and view it on the Serial monitor. As is all it does is print out "?" in the Serial monitor.
I have this Sketch on the Liquid Level Project Arduino:
#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"
SSD1306AsciiAvrI2c oled;
#define I2C_ADDRESS 0x3C
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
double SensorAnalogValue;
uint8_t calculation=1;
String Show_value;
//create an RF24 object
RF24 radio(9, 8); // CE, CSN
//address through which two modules communicate.
const byte address[6] = "00001";
void setup()
{
Serial.begin(9600);
oled.begin(&Adafruit128x64, I2C_ADDRESS);
oled.setFont(CalLite24);
oled.clear();
radio.begin();
//set the address
radio.openWritingPipe(address);
//Set module as transmitter
radio.stopListening();
}
void loop()
{
SensorAnalogValue = analogRead(A0) * 5.0 / 1023.0;
if (SensorAnalogValue < 1.726) {
calculation=0;
Show_value="Low";
}
if (SensorAnalogValue > 4.04) {
calculation=0;
Show_value="High";
}
if(calculation!=0){
// Serial.println(SensorAnalogValue);
Show_value=(String)Liquid_Volume(SensorAnalogValue);
}
Serial.println(SensorAnalogValue);
oled.setCursor(20, 0);
oled.print(Show_value);
oled.print(" L");
oled.println(" ");
oled.print(Show_value);
oled.print("L");
oled.println(" ");
delay(500);
oled.clear();
radio.write(&Show_value, sizeof(Show_value));
delay(1000);
calculation=1;
}
int Liquid_Volume(double Volt) {
double A = 2.81842;
double B = -11.00151 ;
double C = 14.4765 ;
double D = 28.73579 ;
return A * Volt * Volt * Volt + B * Volt * Volt + C * Volt + D;
}
And the Receiver has this:
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//create an RF24 object
RF24 radio(9, 8); // CE, CSN
//address through which two modules communicate.
const byte address[6] = "00001";
void setup()
{
while (!Serial);
Serial.begin(9600);
radio.begin();
//set the address
radio.openReadingPipe(0, address);
//Set module as receiver
radio.startListening();
}
void loop()
{
//Read the data if available in buffer
if (radio.available())
{
char Show_value[32] = {0};
radio.read(&Show_value, sizeof(Show_value));
Serial.println(Show_value);
}
}
I think the problem is in:
radio.write(&Show_value, sizeof(Show_value));
I believe "radio.write" is used kinda like Serial.print, or oled.print, But I don't really understand the "sizeof" part, maybe that is the problem?