Author Options:

NodeMCU to NodeMCU communication Answered

Dear All,

I am really a newbie here playing with two NodeMCUs. I started out with basics and after a while I stepped into my actual project. The project is to display toilet status indicator. My plan is to pick up the data from PIR sensor and feed it to one NodeMCU and have another NodeMCU process the data on the other end of the room and display the status on and I2c 16 x 2 LCD. I was able to connect the PIR and LCD onto one NodeMCU and test it and things were fine. I am really looking for some help to use TCP/IP protocol to have the nodeMCUs communicate to each other.

My basic code is as below:

#include <LiquidCrystal_I2C.h>

int sensor = 13;

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()

{ Serial.begin(115200);

Wire.begin(D2, D1);

pinMode(sensor, INPUT);


lcd.begin(); }

void loop ()

{ long state = digitalRead(13);

if (state == HIGH){

Serial.println("Motion recognized");

lcd.setCursor(5, 0);

lcd.print("RESTROOM IS");

lcd.setCursor(0, 1);


digitalWrite (LED_BUILTIN, LOW);


lcd.clear(); }

else {

if (state == LOW);

Serial.println("Motion Absent!");

lcd.setCursor(0, 1);

lcd.print("NOW VACANT");

digitalWrite(LED_BUILTIN, HIGH);





Thanks for any help you can provide or guide me to examples.


The forums are retiring in 2021 and are now closed for new topics and comments.