BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk, NRF24l01 and esp handling multiple sensors

I am working on a wireless network using Arduinos connected to NRF24 modules, these are communicating with a esp8266 which is sending the sensor data to the Blynk server.
I can get the data on the Blynk app to work perfectly with only one sensor reading represented by a virtual pin, if I add a second then the signials occasionally get mixed up and I will get values from V0 on the V1 wiget in the app, if I add a third then things get really messed up.

I am wondering the best way to take multiple analog readings on a virtual pin and send them to the app.

The problem may be between the NRF24l01 modules, any input would be great thank you.

Here is the Transmitter code:

 #include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte addresses [][6] = {"00001", "00002"};    //Setting the two addresses. One for transmitting and one for receiving


int led = 3;
int moisture = A3;
int gTemp = A0;
int gTempON = 5;
 
void setup() 
{
  pinMode(led, OUTPUT);
  pinMode(gTempON, OUTPUT);
  
  Serial.begin(9600);
  radio.begin();                            //Starting the radio communication
  radio.openWritingPipe(addresses[0]);      //Setting the address at which we will send the data
  radio.openReadingPipe(1, addresses[1]);   //Setting the address at which we will receive the data
  radio.setPALevel(RF24_PA_MAX);            //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
}
void loop() 
{

      int V = readVcc();
      
     digitalWrite(gTempON, HIGH); 
      int gTempRAW = analogRead(gTemp);
      int gTempC = map(gTempRAW,266 ,591 ,0 ,36);
       float gTempF  = (gTempC * 1.8) +32;
      
      digitalWrite(gTempON, LOW);


       int value = analogRead(moisture);
       int val = map(value, 460, 860, 100, 0);
     
   radio.stopListening();

    radio.write(&gTempF, sizeof(gTempF));

    radio.write(&val, sizeof(val));

     radio.write(&V,sizeof(V));


       
}
 long readVcc() 
    { 
    long result; // Read 1.1V reference against AVcc 
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); delay(2); // Wait for Vref to settle 
    ADCSRA |= _BV(ADSC); // Convert 
    while (bit_is_set(ADCSRA,ADSC)); 
    result = ADCL; 
    result |= ADCH<<8; 
    result = 1126400L / result; // Back-calculate AVcc in mV 
    
    return result; 
    
    }

Here is the Reciever:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte addresses [][6] = {"00001", "00002"};    //Setting the two addresses. One for transmitting and one for receiving


int led = 3;
int moisture = A3;
int gTemp = A0;
int gTempON = 5;

 
 
void setup() 
{
  pinMode(led, OUTPUT);
  pinMode(gTempON, OUTPUT);
  
  Serial.begin(9600);
  radio.begin();                            //Starting the radio communication
  radio.openWritingPipe(addresses[0]);      //Setting the address at which we will send the data
  radio.openReadingPipe(1, addresses[1]);   //Setting the address at which we will receive the data
  radio.setPALevel(RF24_PA_MAX);            //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
}
void loop() 
{

      int V = readVcc();
      
     digitalWrite(gTempON, HIGH); 
      int gTempRAW = analogRead(gTemp);
      int gTempC = map(gTempRAW,266 ,591 ,0 ,36);
       float gTempF  = (gTempC * 1.8) +32;
      
      digitalWrite(gTempON, LOW);


       int value = analogRead(moisture);
       int val = map(value, 460, 860, 100, 0);
     
   radio.stopListening();

    radio.write(&gTempF, sizeof(gTempF));

    radio.write(&val, sizeof(val));

     radio.write(&V,sizeof(V));


       
}
 long readVcc() 
    { 
    long result; // Read 1.1V reference against AVcc 
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); delay(2); // Wait for Vref to settle 
    ADCSRA |= _BV(ADSC); // Convert 
    while (bit_is_set(ADCSRA,ADSC)); 
    result = ADCL; 
    result |= ADCH<<8; 
    result = 1126400L / result; // Back-calculate AVcc in mV 
    
    return result; 
    
    }

Have you posted the correct code?
Where is your Blynk related code?

How are you identifying which transmitter the received data is coming from?

Pete.

Sorry I posted the transmitter code twice

Here is the receiver with the Blynk portion

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "";
char ssid[] = "";
char pass[] = "";

BlynkTimer timer; // Announcing the timer
#define PIN_UPTIME V5


RF24 radio(D2, D8); // CE, CSN
const byte addresses [][6] = {"00001", "00002"};  //Setting the two addresses. One for transmitting and one for receiving

int led_pin = D4;

int V ;
int val;
float gTempF ;

// This function tells Arduino what to do if there is a Widget
// which is requesting data for Virtual Pin (5)
BLYNK_READ(PIN_UPTIME)
{
  // This command writes Arduino's uptime in seconds to Virtual Pin (5) 
Blynk.virtualWrite(PIN_UPTIME, millis() / 1000); 


  
}
  



void setup() 
{

  Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, TimerV); 

  
Serial.begin(9600);
  pinMode(led_pin, OUTPUT);
  radio.begin();                           //Starting the radio communication
  radio.openWritingPipe(addresses[1]);     //Setting the address at which we will send the data
  radio.openReadingPipe(1, addresses[0]);  //Setting the address at which we will receive the data
  radio.setPALevel(RF24_PA_MAX); //You can set it as minimum or maximum depending on the distance between the transmitter and receiver. 
}

void TimerV()
{ 
    int V =0 ; 
  
 radio.startListening(); //This sets the module as receiver
  if(!radio.available());
  {
   
radio.read(&gTempF,sizeof(gTempF));
Serial.print("gTempF  "); Serial.println(gTempF);
   
   radio.read(&V,sizeof(V));
Serial.print("V  "); Serial.println(V);

radio.read(&val,sizeof(val));
Serial.print("val  "); Serial.println(val);

      
 
  
  Blynk.virtualWrite(V2, gTempF);
  Blynk.virtualWrite(V0, val);
 Blynk.virtualWrite(V1, V);


  
  
  
}
}

void loop() 
{ 

  Blynk.run();
  timer.run();
  
}

For now I only have one transmitter, they are identified by the address from the radio. I can get the Voltage (V) and the Temp (gTempF) to work fine, the issue seems with the sensor value (val)?

Okay, so when you were talking about multiple sensors I thought you were meaning that these were connected to multiple transmitters.

I think your Tx code is missing a txStandBy() after each radio.write()

Pete.

Great! that helped thank you. After implementing I noticed that the values were alternating with a zero value on the receiver side so I just set some conditions to not write to Blynk if it was a zero. Now the timer is determined by the frequency of the transmission instead of the Blynk timer but I have it displaying 4 different sensor readings through one radio channel to the Blynk server.

Thank you Pete

1 Like