17Views0Replies

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<wire.h>
#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);

pinMode(LED_BUILTIN, OUTPUT);

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);

lcd.print("OCCUPIED");

digitalWrite (LED_BUILTIN, LOW);

delay(5000);

lcd.clear(); }

else {

if (state == LOW);

Serial.println("Motion Absent!");

lcd.setCursor(0, 1);

lcd.print("NOW VACANT");

digitalWrite(LED_BUILTIN, HIGH);

delay(5000);

lcd.clear();

}

}

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

Discussions