Currently i'm trying to send integer data using nrf24l01 from arduino uno to esp8266. But the serial monitor for nodemcu is not displaying any integer data.
This is my code for arduino uno(transmitter)
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
Serial.begin(9600); // Communication started with 9600 baud
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
int sensor=analogRead(A0);
radio.write(&sensor, sizeof(sensor)); // Incoming analog signal read and appointed sensor
Serial.println(sensor); //Wrote serial port
delay(1000);
}
and this is my code for nodemcu esp8266 (receiver)
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define WIFI_SSID "otwtoy"
#define WIFI_PASSWORD "jangsorangje"
//basic SPI and the newly installed RF24 libraries
//and create an RF24 object
RF24 radio(D4, D8); // CE, CSN
//create a byte array which will represent the address, or the
//so called pipe through which the two modules will communicate
const byte address[6] = "00001";
//data type declaration to keep the value sensor
//int value;
void setup() {
Serial.begin(9600);
radio.begin();
//Connecting to WIFI
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".\n");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Serial.println();
//set the same address and in that way we enable
//the communication between the two modules
radio.openReadingPipe(1, address);
//set the Power Amplifier level, in our case I will set
//it to minimum as my modules are very close to each other
radio.setPALevel(RF24_PA_MIN);
//sets the module as receiver
radio.startListening();
}
void loop() {
if (radio.available()) {
int text = 0;
radio.read(&text, sizeof(text));
Serial.println(text);
}
else{
//not receive any data
Serial.println("Krik2");
delay(1000);
}
}
this is the wiring for nodemcu esp8266
Wiring Nodemcu
and the result :-
Result