I have soil moisture sensor 1.2v , arduino nano and nRF24L01 with other arduino

I have soil moisture sensor 1.2v , arduino nano and nRF24L01 with other arduino nano and oled screens on both arduinos. The one with the sensor works fine shows the valu from ther sensor on the oled screen, but my secound arduino nano with nrf24l01 and oled screen typees only soil moisture 0 or blur screen. Please hlep me.

sender code.txt (1.9 KB)

reciver code.txt (1.97 KB)

Sender

// SENDER CODE:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 10); // CE, CSN on Blue Pill
const uint64_t address = 0xF0F0F0F0E1LL;
 
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
//const int AirValue = 660;   //you need to replace this value with Value_1
//const int WaterValue = 290;  //you need to replace this value with Value_2
const int SensorPin = A0;
int soilMoistureValue = 0;
//int soilmoisturepercent=0;
void setup() {
  Serial.begin(115200); // open serial port, set the baud rate to 9600 bps
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)
  display.clearDisplay();
  radio.begin();                  //Starting the Wireless communication
  radio.openWritingPipe(address); //Setting the address where we will send the data
  radio.stopListening();
}
 
 
void loop() 
{
soilMoistureValue = analogRead(SensorPin);  //put Sensor insert into soil
Serial.println(soilMoistureValue);
//soilmoisturepercent = map(soilMoistureValue 0, 100);
{
  Serial.println("soilMoistureValue");
  
  display.setCursor(45,0);  //oled display
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.println("Soil");
  display.setCursor(20,15);  
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.println("Moisture");
  
  display.setCursor(30,40);  //oled display
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.println(soilMoistureValue);
  display.display();
  radio.write(&soilMoistureValue, sizeof(soilMoistureValue));
              
  
  delay(2000);
  display.clearDisplay();
}
}

Receiver

// RESIEVER CODE:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 10); // CE, CSN on Blue Pill
const uint64_t address = 0xF0F0F0F0E1LL;
 
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
//const int AirValue = 625;   //you need to replace this value with Value_1
//const int WaterValue = 290;  //you need to replace this value with Value_2
//int SensorPin = A0;
int soilMoistureValue = 0;
//int soilmoisturepercent=0;
void setup() {
  Serial.begin(115200); // open serial port, set the baud rate to 9600 bps
  radio.begin();                  //Starting the Wireless communication
  radio.openWritingPipe(address); //Setting the address where we will send the data
  radio.startListening();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)
  display.clearDisplay();
  delay (2000);
}
 
 
void loop() 
{
if ( radio.available() )
{
bool done = false;
while (!done)
{
radio.read (&soilMoistureValue, sizeof(soilMoistureValue));
Serial.println(soilMoistureValue);
//soilmoisturepercent = map(soilMoistureValue 0, 100);
{
  Serial.println("soilMoistureValue");
  
  display.setCursor(45,0);  //oled display
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.println("Soil");
  display.setCursor(20,15);  
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.println("Moisture");
  
  display.setCursor(30,40);  //oled display
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.println(soilMoistureValue);
  display.display();
  delay(2000);
  display.clearDisplay();
}
}
}
else
{
display.setCursor(0, 0);
display.print("No radio available");
}
}

Did you verify your first Nano can successfully read the sensor?
Did you verify that your Nanos can successfully communicate over NRF24?
Did you verify that the first Nano actually transmits data, and the second receives it correctly, before trying to display it on the OLED display?

well i tried the hello world example on the serial monitor it showed (???????????????????????????????) question marks and repeat them on the delay i am giving..
yes th seensor works great on the transmiter and data is send to the reciever but it shows 0 or smaller random number, and the Nrf24l01 with antena (1000m).

Make sure the baud rate of the Serial monitor (set in the right bottom) matches the baud rate set in Serial.begin().

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.