variable was not declared in this scope

#include <SPI.h>

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#define OLED_RESET 4

Adafruit_SSD1306 display(OLED_RESET);

void setup() {

Serial.begin(9600);

display.begin(SSD1306_SWITCHCAPVCC, 0x3D);

display.display();

delay(2000);

display.clearDisplay();

}

void loop() {

while(Serial.available() > 0){

String Date = Serial.readStringUntil('|');

Serial.read();

String Time = Serial.readStringUntil('|');

Serial.read();

String Phone = Serial.readStringUntil('|');

Serial.read();

String text = Serial.readStringUntil('\n');

Serial.read();

}

if(text == "text" && Phone == "phone")

{ display.println(Date);

display.display();

display.println(Time);

display.display();

display.clearDisplay();

}

if (text != "text" && Phone == "phone"){

display.println(text);

display.display();

delay(5000);

display.clearDisplay();

}

if (text == "text" && Phone != "phone"){

display.println(Phone);

display.display();

delay(5000);

display.clearDisplay();

}

}

I have tried all the possibilities but the problem was not solved.

Plz help me to solve this problem.

Would it be too much to ask you to post the error message?
And indent your code?
And use code tags?

The concept you need to understand is called scope.

Look at the scope of your String variables.

Good indentation will help you visualise this.

I bet it doesn't just say "variable was not declared in this scope". I bet it tells you WHICH variable and also what line it's on. That's information it would have been useful for you to pass on.

Steve

slipstick:
I bet it tells you WHICH variable

... all of them :frowning:

Oh those little } things will keep sneaking in where they're not needed!

Steve