Transmitter and receiver with Proximity sensor and OLED display

Hello All, I am working on a project where I am using a proximity sensor and displaying the distance on an OLED display. My issue is I need to separate the oled and the sensor because I cant have a cable track. I want to use two nodemcu's for the small footprint. I have used them as a transmitter and receiver to turn on a relay. However, I am not sure how to use them where I can transmit the distance to the receiver? Would anyone be able to steer me in the right direction? I will paste the working distance code. I hope I am following correct protocol here. Thank you in advance.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define CommonSenseMetricSystem
//#define ImperialNonsenseSystem

#define trigPin 13
#define echoPin 12

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  //initialize with the I2C addr 0x3C (128x64)
  display.clearDisplay();
}

void loop() {
  long duration, distance;

  digitalWrite(trigPin, LOW);  //PULSE ___|---|___
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

#ifdef CommonSenseMetricSystem
  distance = (duration / 2) / 29.1;
#endif
#ifdef ImperialNonsenseSystem
  distance = (duration / 2) / 73.914;
#endif

  display.setCursor(0, 0);  //oled display
  display.setTextSize(4);
  display.setTextColor(WHITE);
  display.println(distance);
  display.setCursor(95, 0);
  display.setTextSize(2);

#ifdef CommonSenseMetricSystem
  display.println("cm");
#endif
#ifdef ImperialNonsenseSystem
  display.println("in");
#endif

  display.display();

  delay(500);
  display.clearDisplay();

  Serial.println(distance);  //debug
}

how far apart are the devices? what is the environment?

have a look at ESP-now - works with ESP32 and ESP8266

alternativily you could configure an ESP device as an access point (example AP with web server) and run a simple telenet service to transfer the data

They will travel from 6 feet down to zero. I cant use internet cuz of where i am at but that would have been great.

neither ESP-NOW or an Access Point requires the internet - both operate locally

OK, I will have to check that out but I still dont know how to get the display to work wirelessly?

the first thing is to test the wireless connectivity - I would suggest ESP-NOW is the simplest
then connect the sensors to one NodeMCU which then transmits the data to the other NodeMCU which has the LCD
is that what you require?

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