BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

Smart Switch with OLED Display

Hello all! I have been working on a project for a while. My goal is to make a super smart switch using Blynk. I have the switch part of it (that was the easy part), but the next step is to add a display. I am using a WEMOS D1 mini lite, a relay shield, and an OLED shield.

Here is the relay shield
Here is the OLED display

I would link to the WEMOS D1 mini lite, but as I am a new user I can only share 2 links (also y’all probably know about this board anyway)

What I want is for the OLED screen to display “ON” when the relay is switched on and for it to display “OFF” when the display is switched off. I have gotten the OLED to display "ON or “OFF” simply by typing “ON” or “OFF” into display.println().

I have no idea how to do this and I would really appreciate some help.
Also I would be controling this from the Blynk app

Here is the code I’m using

Relay:

#define BLYNK_PRINT Serial


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


char auth[] = "################################";


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

void setup()
{Preformatted text
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
}

OLED:

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


#define OLED_RESET 0  
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16


void setup()   {
  Serial.begin(9600);

 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  
  display.display();
  delay(2000);


  display.clearDisplay();


  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  display.println("On");
  display.display();
  delay(2000);
  display.clearDisplay();

}


void loop() {

}

explanation can be found here :wink:

https://community.blynk.cc/search?q=Wemos%20D1%20Mini%20

Thank you, but that really doesn’t help me much :wink:. None of the topics there have anything to do with using an OLED screen, only 4 talk about relays.

yes but there are many examples for I2C displays

Hmm. I must have not done a good explaining exactly what it was that I need help with. I would like to know how to get my OLED to display “ON” or “OFF” based on the state of the relay pin. I have messed around with my code and have managed to get the display to display what I want while I can still change the state of the relay.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
 

#define OLED_RESET 0  
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2


#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16
#define BLYNK_PRINT Serial



void setup()   {
  char auth[] = "3a5d5b84e1ac4ef48d4dbf196f03184c";
char ssid[] = "TP-LINK_2.4GHz_8D5014";
char pass[] = "Analog22";

  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  

 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  
  display.display();
  delay(2000);


  display.clearDisplay();


  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setCursor(45, 10);
  display.println("ON");
  display.display();
  delay(2000);
  display.clearDisplay();
}

void loop()
{
  Blynk.run();
}

Unfortunately, what is displayed is only affected by what I tell it to display in the code, not the state of the relay.

What I need to know is how to write the code that will update the display based on the state of the relay.

Perhaps spend some time reading the Documentation and looking through the Examples.

Any control widget will trigger a BLYNK_WRITE() function which in turn will run whatever OLED commands you have in it.

http://docs.blynk.cc/#blynk-firmware-blynktimer-blynk_writevpin

Searching through this forum will show this basic building block in use everywhere… Here is a bunch of other examples to learn with…

2 Likes

Thanks for your reply! I have read through what you sent me and it was helpful, but I am still having a hard time understanding how to implement it. Any examples that you could give me that pertain specifically to what I need would be great!

First you need to make it work without Blynk. Find a tutorial or code on how to read a relay state and write it to LCD or serial.

Then adding Blynk on top of that is a piece of cake

1 Like

Perfect! Thank you, that’s the help I was looking for