Hello, i’m a new and need some help with my code or connections
The Oled is connected D1 5 // SCL and D2 4 // SDA
I don’t know why the Oled is not working, is the code not correct or not good connected
#define BLYNK_PRINT Serial
/*******Waterproof Ultrasonic**********/
#include <NewPing.h>
/*******NodeMCU**********/
#include <ESP8266WiFi.h>
/*******BLYNK***********/
#include <BlynkSimpleEsp8266.h>
/*******OLED****************/
#include <SPI.h> //we need all those nasty libraries for OLED
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4 // this is the reset pin, IM NOT USING IT
Adafruit_SSD1306 display(OLED_RESET);
#define CommonSenseMetricSystem
/*********waterproof ultrasonic**************/
#define TRIGGERPIN D7
#define ECHOPIN D8
/*************LED****************************/
#define LED1 D3
#define LE21 D4
#define LED3 D5
#define LED4 D6
//#define LED5 D7
//#define LED6 D8
/****************Blynk***********************/
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "****************";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*********";
char pass[] = "***********";
/************LCD**************/
WidgetLCD lcd(V15);
void setup()
{
// Debug console
Serial.begin(115200);
pinMode(TRIGGERPIN, OUTPUT);
pinMode(ECHOPIN, INPUT);
Blynk.begin(auth, ssid, pass);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)
display.clearDisplay();
//*****Aantal LED***********
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
//pinMode(D7, OUTPUT);
//pinMode(D8, OUTPUT);
}
void loop()
{
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(0, 0, "Distance in cm"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
// Please use timed events when LCD printintg in void loop to avoid sending too many commands
// It will cause a FLOOD Error, and connection will be dropped
long duration, distance;
digitalWrite(TRIGGERPIN, LOW);
delayMicroseconds(3);
digitalWrite(TRIGGERPIN, HIGH);
delayMicroseconds(12);
digitalWrite(TRIGGERPIN, LOW);
duration = pulseIn(ECHOPIN, HIGH);
//distance = duration/58.2;
#ifdef CommonSenseMetricSystem
distance = (duration/2) / 29.1;
#endif
display.setCursor(2,0); //x,y coordinates
display.setTextSize(4); //size of the text
display.setTextColor(WHITE); //if you write BLACK it erases things
display.println(distance); //print our variable
display.setCursor(85,5); //set size,print the units (cm/in)
display.setTextSize(3);
#ifdef CommonSenseMetricSystem//if theres#define CommonSenseMetricSystem
display.println("cm"); //print "cm" in oled
#endif
display.display(); //you need to actually display all that data
delay(500); //wait!, human speed
display.clearDisplay(); //clear black the display
Serial.println(distance);//debug
//**********************
if (distance <= 150) {
Blynk.virtualWrite(V30, 0); // distance greater than 150cm LED OFF
digitalWrite(D3,LOW);
}
else {
Blynk.virtualWrite(V30, 255); // distance smaler than 150cm LED ON
digitalWrite(D3,HIGH);
}
//*********************
if (distance <= 100) {
Blynk.virtualWrite(V31, 0); // distance greater than 100cm LED OFF
digitalWrite(D4,LOW);
}
else {
Blynk.virtualWrite(V31, 255); // distance smaler than 1000cm LED ON
digitalWrite(D4,HIGH);
}
//**********************
if (distance <= 80) {
Blynk.virtualWrite(V32, 0); // distance greater than 80cm LED OFF
digitalWrite(D5,LOW);
}
else {
Blynk.virtualWrite(V32, 255); // distance smaler than 80cm LED ON
digitalWrite(D5,HIGH);
}
//*********************
if (distance <= 40) {
Blynk.virtualWrite(V33, 0); // distance greater than 40cm LED OFF
digitalWrite(D6,LOW);
}
else {
Blynk.virtualWrite(V33, 255); // distance smaler than 40cm LED ON
digitalWrite(D6,HIGH);
}
//**********************
if (distance <= 20) {
Blynk.virtualWrite(V34, 0); // distance greater than 20cm LED OFF
//digitalWrite(D7,LOW);
}
else {
Blynk.virtualWrite(V34, 255); // distance smaler than 250cm LED ON
//digitalWrite(D7,HIGH);
}
//*************
if (distance <= 0) {
Blynk.virtualWrite(V35, 0); // distance greater than 0cm LED OFF
//digitalWrite(D8,LOW);
}
else {
Blynk.virtualWrite(V35, 255); // distance is 0cm LED ON
//digitalWrite(D8,HIGH);
}
Serial.print(distance);
Serial.println("Cm");
Blynk.virtualWrite(V16, distance);
lcd.print(7, 1, distance);
Blynk.run();
delay(1000); //refrech elke 1 sec, 1000=1sec
}