ESP8266mod mini has no output in Tx pin when connected to wifi

Hi,

I am a newbee to Ardiuno.
I have created a project with Ultrasonic sensor connected to Nano and data is transmitted using RF transmitter. On reciever side i have used a ESP8266 mini to get the data from RF reciever and send to Ardiuno UNO to display it in LCD(GUI Mode).Also i have coded Blynk in ESP8266. My problem is that the data is not getting updated in the LCD or uno RX LED is not flashig when ESP8266 is connected to WIFI. If i disconnects wifi after the short while of initial power on, the LCD gets updated/refreshed in every 10 seconds. I tried changing uno,nano,ESP8266 but no luck. i am using a 5v 2.5 AMP adapter for uno& ESP8266 . Even on 12v 1 AMP adapter I am experiencing same error. Needs advise what could be wrong

ESP8266mini code
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL2odH_TnAc"
#define BLYNK_TEMPLATE_NAME "Water Level"
#define BLYNK_AUTH_TOKEN "gfSCpuFg4n3GBYjrEYhjEeFmwJ2b4nQu" 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <EEPROM.h>
#include <RCSwitch.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(D1,D2);

RCSwitch mySwitch = RCSwitch();

char auth[] = "gfSCpuFg4n3GBYjrEYhjEeFmwJ2b4nQu";
char ssid[] = "AndroidAP98D2";
char pass[] = "wdgo5814";

BlynkTimer timer;

float Tank_Hight,Tank_U_Hight;
int OldLevel;
int Distance;

float Level;

int Buzzer = D0;

int LED = D4;

long Time,UP_Time,Buzz_Time;

int i,Flag;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
  EEPROM.begin(512);
  delay(1000);
  mySwitch.enableReceive(D5);
  
  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  
  timer.setInterval(100L, Update_Data);
  
  //Tank_Hight = EEPROM.read(100)*10;

  Tank_Hight = analogRead(A0)/3;
  //Tank_Hight = Tank_Hight;

  Serial.print("Tank_Hight : "); Serial.println(Tank_Hight);

  pinMode(LED,OUTPUT);
  pinMode(Buzzer,OUTPUT);
}

void Update_Data() {
  Blynk.virtualWrite(V4, Tank_Hight);  
}

//BLYNK_WRITE(V2){ Tank_U_Hight = param.asInt(); Serial.println(Tank_Hight); }
//BLYNK_WRITE(V3){ EEPROM.write(100, Tank_U_Hight/10); EEPROM.commit(); Tank_Hight = EEPROM.read(100)*10; Serial.print("Hight Updated "); Serial.println(Tank_Hight); }

void loop() {
  Tank_Hight = analogRead(A0)/30;

  Tank_Hight = Tank_Hight*10;

  if ( millis() - UP_Time>1000){
    UP_Time = millis();
    Serial.print("Tank_Hight : "); Serial.println(Tank_Hight);
  }
  
  Blynk.run();
  timer.run();
  Run();
  }

void Run(){ 
  if (mySwitch.available()) {
    digitalWrite(LED,LOW);
    int Rec = mySwitch.getReceivedValue();
    Distance = Rec - 3000;
 
    mySwitch.resetAvailable();
    Serial.println(Distance);
    Blynk.virtualWrite(V1, Distance);

    calculate_Level(); 
    digitalWrite(LED,HIGH);

    if(Level>90 || Level<10){ if(i==0){ i=1; Buzz_Time=millis();}}
    if(Level<85 && Level>15){ i=0; }
    }

  if(millis()-Buzz_Time<60000){ if(i==1) { Buzz();} else { digitalWrite(Buzzer,LOW); }}
  else                        { digitalWrite(Buzzer,LOW);}
  }

void Buzz(){
  if(millis()-Time>100){ 
    Time = millis(); 
    Flag = !Flag; 
    digitalWrite(Buzzer,Flag); 
    }
}
void calculate_Level(){
  //Tank_Hight = 200;
  
  int h = Tank_Hight - Distance;

  Level = h*100/( Tank_Hight-25 );

  if (Level>100) { Level = 100; }
  if (Level<0)   { Level = 1; }

  Serial.println(Level);

  if(Level == OldLevel ){ OldLevel = Level; }
  else                  { OldLevel = Level; mySerial.print(Level + 100);mySerial.println("#"); }

  Blynk.virtualWrite(V0, Level);
  
  }

Ardiuno uno code
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>

#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

int Val;

long Sig_Time;

void setup(void) {

  Serial.begin(9600);

  progmemPrintln(PSTR("TFT LCD test"));

#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif

  tft.reset();

  tft.begin(0x9341); // SDFP5408

  tft.setRotation(0); 
  tft.fillScreen(BLACK);

   //tft.fillRect(20, 20, 200, 160, RED); 

  tft.setRotation(1);
  tft.fillRect(85, 85, 170, 35, RED);
  tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(90, 90); tft.print("NO SIGNAL");

}

void loop(void) {
  if ( millis()-Sig_Time > 30000){
    tft.fillScreen(BLACK);
    tft.fillRect(85, 85, 170, 35, RED);
    tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(90, 90); tft.print("NO SIGNAL");
    } 
  if(Serial.available()>0){
    
    String Read = Serial.readStringUntil("#");
    Serial.println(Read);

    Val = Read.toInt();

    Serial.println(Val);

    if(Val>100){ 
      Sig_Time = millis();
      Val = Val-100; 
      
      tft.setRotation(0);

      //tft.fillRect(85, 85, 170, 35, BLACK);

      tft.fillScreen(BLACK);
  
      //tft.fillScreen(BLACK);

      tft.fillRect(20, 20, 210, 160, RED);   //delay(1000);
      tft.fillRect(25, 25, 210, 150, BLACK); //delay(3000);
  
     //for ( int i =0; i<190; i++) { tft.fillRect(30, 30, i, 140, GREEN); } //delay(1);}

     int lvl = Val*2;

           if (Val<25) { tft.fillRect(30, 30, lvl, 140, RED); }
      else if (Val<50) { tft.fillRect(30, 30, lvl, 140, YELLOW); }
      else if (Val<75) { tft.fillRect(30, 30, lvl, 140, BLUE); }
      else if (Val>=75){ tft.fillRect(30, 30, lvl, 140, GREEN); }


      tft.setRotation(1);

      tft.fillRect(200, 160, 100, 80, BLACK); tft.setTextColor(WHITE); tft.setTextSize(5); tft.setCursor(200, 160); tft.print(Val); tft.print("% ");
	  /*tft.fillRect(200, 160, 100, 80, BLACK);*/ tft.setTextColor(WHITE); tft.setTextSize(2.5); tft.setCursor(200, 40); tft.print("ECJ IOT"); 
      /*tft.fillRect(200, 160, 100, 80, BLACK);*/ tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(200, 80); tft.print("WATER"); 
                                                                                               tft.setCursor(200,120); tft.print("LEVEL");
      } 
      
    else { 
      tft.fillScreen(BLACK);
      //if(Val==33){for ( int i=0; i<20; i++){ tft.drawCircle(200, 260, i, GREEN); }} 
      //if(Val==22){for ( int i=0; i<20; i++){ tft.drawCircle(200, 260, i, YELLOW); }}

      if(Val==33){
        tft.fillRect(85, 85, 170, 35, RED);
        tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(90, 90); tft.print("NO-SIGNAL");
        } 
      }
    }
  }

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(BLACK);
  tft.fillScreen(RED);
  tft.fillScreen(GREEN);
  tft.fillScreen(BLUE);
  tft.fillScreen(BLACK);
  return micros() - start;
}

unsigned long testText() {
  tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(YELLOW); tft.setTextSize(2);
  tft.println(1234.56);
  tft.setTextColor(RED);    tft.setTextSize(3);
  tft.println(0xDEADBEEF, HEX);
  tft.println();
  tft.setTextColor(GREEN);
  tft.setTextSize(5);
  tft.println("Groop");
  tft.setTextSize(2);
  tft.println("I implore thee,");
  tft.setTextSize(1);
  tft.println("my foonting turlingdromes.");
  tft.println("And hooptiously drangle me");
  tft.println("with crinkly bindlewurdles,");
  tft.println("Or I will rend thee");
  tft.println("in the gobberwarts");
  tft.println("with my blurglecruncheon,");
  tft.println("see if I don't!");
  return micros() - start;
}

unsigned long testLines(uint16_t color) {
  unsigned long start, t;
  int           x1, y1, x2, y2,
                w = tft.width(),
                h = tft.height();

  tft.fillScreen(BLACK);

  x1 = y1 = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t     = micros() - start; // fillScreen doesn't count against timing

  tft.fillScreen(BLACK);

  x1    = w - 1;
  y1    = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(BLACK);

  x1    = 0;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(BLACK);

  x1    = w - 1;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);

  return micros() - start;
}

unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  unsigned long start;
  int           x, y, w = tft.width(), h = tft.height();

  tft.fillScreen(BLACK);
  start = micros();
  for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  //for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);

  //tft.drawFastHLine(0, y, w, color1);

  return micros() - start;
}

unsigned long testRects(uint16_t color) {
  unsigned long start;
  int           n, i, i2,
                cx = tft.width()  / 2,
                cy = tft.height() / 2;

  tft.fillScreen(BLACK);
  n     = min(tft.width(), tft.height());
  start = micros();
  for(i=2; i<n; i+=6) {
    i2 = i / 2;
    tft.drawRect(cx-i2, cy-i2, i, i, color);
  }

  return micros() - start;
}

unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  unsigned long start, t = 0;
  int           n, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  n = min(tft.width(), tft.height());
  for(i=n; i>0; i-=6) {
    i2    = i / 2;
    start = micros();
    tft.fillRect(cx-i2, cy-i2, i, i, color1);
    t    += micros() - start;
    // Outlines are not included in timing results
    tft.drawRect(cx-i2, cy-i2, i, i, color2);
  }

  return t;
}

unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;

  tft.fillScreen(BLACK);
  start = micros();
  for(x=radius; x<w; x+=r2) {
    for(y=radius; y<h; y+=r2) {
      tft.fillCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int           x, y, r2 = radius * 2,
                w = tft.width()  + radius,
                h = tft.height() + radius;

  // Screen is not cleared for this one -- this is
  // intentional and does not affect the reported time.
  start = micros();
  for(x=0; x<w; x+=r2) {
    for(y=0; y<h; y+=r2) {
      tft.drawCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testTriangles() {
  unsigned long start;
  int           n, i, cx = tft.width()  / 2 - 1,
                      cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  n     = min(cx, cy);
  start = micros();
  for(i=0; i<n; i+=5) {
    tft.drawTriangle(
      cx    , cy - i, // peak
      cx - i, cy + i, // bottom left
      cx + i, cy + i, // bottom right
      tft.color565(0, 0, i));
  }

  return micros() - start;
}

unsigned long testFilledTriangles() {
  unsigned long start, t = 0;
  int           i, cx = tft.width()  / 2 - 1,
                   cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  start = micros();
  for(i=min(cx,cy); i>10; i-=5) {
    start = micros();
    tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(0, i, i));
    t += micros() - start;
    tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(i, i, 0));
  }

  return t;
}

unsigned long testRoundRects() {
  unsigned long start;
  int           w, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  w     = min(tft.width(), tft.height());
  start = micros();
  for(i=0; i<w; i+=6) {
    i2 = i / 2;
    tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  }

  return micros() - start;
}

unsigned long testFilledRoundRects() {
  unsigned long start;
  int           i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  start = micros();
  for(i=min(tft.width(), tft.height()); i>20; i-=6) {
    i2 = i / 2;
    tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
  }

  return micros() - start;
}

// Copy string from flash to serial port
// Source string MUST be inside a PSTR() declaration!
void progmemPrint(const char *str) {
  char c;
  while(c = pgm_read_byte(str++)) Serial.print(c);
}

// Same as above, with trailing newline
void progmemPrintln(const char *str) {
  progmemPrint(str);
  Serial.println();
}

Thanks in Advance

'if' you want to use sofwareserial on an ESP, you should use espsoftwareserial

I say 'if' because you could also use UART1 for debug messages, it is TX only but that is all you need. You could then use UART0 either on the default or on the swap() pins instead of the softwareserial object

Thanks Deva_Rishi for your feedback. Sorry i have limited knowledge in coding. Please correct me if i am wrong. So i need to change the line from #include <SoftwareSerial.h> to #include<espSoftwareSerial.h> in ESP side

You will need to install it first from the library manager. After that you can include it in your sketch. Check the examples that come with the library for the exact syntax.

Thank you so much. Let me Try it and feedback. Still i didnt understand why the issue occurs only when wifi is collected. Please confirm do i needs to do any changes in my code to Tx through D2(GPIO 4) in 8266 mini other than changing to EspSoftwareSerial.h

IF you never mind can you please explain "I say 'if' because you could also use UART1 for debug messages, it is TX only but that is all you need. You could then use UART0 either on the default or on the swap() pins instead of the softwareserial object" . my little googling says UART is referring to Tx& Rx

In this context, it's a "UAT". (-:

Hi,

I reconfirmed that the installed library is same as you suggested. i tried reinstalling it again and uploaded the code, Still the issue remains the same. UNO Rx connected to D2 of ESP8266 will not update if the wifi is connected

@eldo_c_joy
You ought to post your current revision.

Installed library is EspSoftwareSerial by Dirk Kaar,Peter Lerup version 8.1.0. And also i tried by replacing ESP8266 mini with NodeMcu but the results were same

@eldo_c_joy
Seems you didn't read the robmiles article.

Yes i read it and with my little knowledge what i understand is not to use software serial. Please guide me as i couldnt figure out how to transmit the data from wemos 8266 mini to Uno if i dont use software serial. currenlty i am using D2 to transmit, D4 is already in use.i tried connecting to Tx of the wemos 8266 mini but it didnt picked any signal or printed any output to LCD connected to Uno. i am very new to Ardiuno coding. I have posted my complete code above, please help

Put what you have on D4 somewhere else.

Serial1.begin(9600); // open the port at 19200 baud
Serial1.println(“hello”);

On an ESP8266 the RX of UART1 is used for communication with the flash and so it is not available for the user.
What i mean to tell you mainly is that 'softwareSerial' can be used as a way to solve the lack of Serial communication ports, by doing it through software. Doing this through software is of course quite CPU intensive and way more CPU intensive than using a hardware UART. As a result all sorts of side effects can occur. So the expression is actually. If it works it is a solution, if it causes issues than it is more a problem than it's worth. So if it is possible you can circumvent this 'problem' (which appeared to be a solution), and on an ESP8266 this can be done. I tend to avoid software serial if possible and make compromises to do so. I find it is worth it, both for speed and reliability.

I always just use GPIO numbers, so i had to look it up so that is GPIO 5 & 4., right ?

Anyway, as far as i know ESPSoftwareserial should work in combination with WiFi, but clearly it doesn't for you as yet. Best if you post a schematic , and if you want to use hardware Serial for the communication, you may need to swap a few functions of some of the pins in your project.

This is not reflected in your code.

Well the use of softwareserial can be an issue,

I Missed to communicate that even when i am not getting the data update to Rx pin of Uno to display in LCD, i am still recieving the data from RF Reciever to ESP8266 mini as expected when connected to wifi.This is shown in serial monitor of ESP8266. Only issue is that the LCD will not update/refresh. By reading the post i suspect that the micro controller may be too busy to update the data through wifi(Blynk) and skipping the process of updating its Tx pin(D2)

so now my query is that as u suggested to if i include serial1.begin(9600) in the sketch should i remove the line softwareserial my serial(D1,D2) or i edit it to (D1,D4) and hook the Uno Rx line to D4

image
This is because i had made a lot of googling before i am requesting an assistance from the forum. Also these codes are copied from different websites and altered to my requirement.

I have connected ESP8266 mini D2(GPIO 4) to Uno Rx pin directly.

i will post the schematic soon

Please advise which functions needs to swap on the pins to use hardware serial for communication. Please advise if its Pin D4(GPIO 2) where the inbuilt LED is connected and which i am using to flash when the data is recieved

Basically my whole setup was working initially for a day before started showing the issues

But you understand the code ?

anyway in that case let's get rid of these functions and just use 'normal' Serial print(). I am not so sure this is working the way it is supposed to, and there is no need for them

void progmemPrint(const char *str) {
  char c;
  while(c = pgm_read_byte(str++)) Serial.print(c);
}

// Same as above, with trailing newline
void progmemPrintln(const char *str) {
  progmemPrint(str);
  Serial.println();
}

I mean this would work on an ESP, but they are part of your UNO code.
It would help overview (for us) if you would put these code in separate windows
Actually i think you managed to put the UNO code in the middle of the ESP code somehow, it is rather confusing.

These macros have not been defined, is there any more code you are omitting ?

How about first just the esp code in it's most recent version and complete with all it's definitions. And a schematic. I want to tell you what to do but i can only be correct if i have all the info.

And you have no idea what you had done ?

Eh yes, on a nodeMCU the builtin led is on GPIO 2. You can put another led(+resistor) on a different pin if you need something to flash. It will now serve as a tx-led for the output of UART1. Do you actually require the ESP to receive data the UNO ? If so there is still a work around.
edit; You could still use that LED btw, but then you should manually switch the pinMode of it and make sure that the data has been fully sent before you switch it 'on'

Q: You could still use that LED btw, but then you should manually switch the pinMode of it and make sure that the data has been fully sent before you switch it 'on'
A: i am ok even if i dont have an LED to flash when data is recieved

Q:Do you actually require the ESP to receive data the UNO ? If so there is still a work around.
A: I am using ESP8266 to connect to wifi(Blynk App). in the recieving side instead of Uno if i can use ESP32/ Node Mcu 8266 to output data through LCD is also fine for me

Q:And you have no idea what you had done ?
A: it worked for some hours then it stopped, not sure what has gone wrong

Q:pinMode(LED,OUTPUT);//macros have not been defined
A: int LED = D4; // is this is the one or i need to define in any other way like #define

Uno.ino (9.6 KB)
Wemos_ESP8266_mini.ino (2.7 KB)

Let me give an idea regarding my project. i am using ultrasonic sensor to read water level from overhead tank, trasmitted through RF transmitter using Ardiuno Nano. Recieved through RF reciever and data is feeded to wemos 8266 mini. output data from 8266 is fed to Uno Rx to display a GUI Animation of water level

Thanks for assistance so far. really its encouraging when i am getting assistance

Please not as a link. I don't want to have to download it.

You can use whichever board is fine for you, the question was if data is one way from the esp to the UNO.

Basically you want the sensor somewhere and the screen somewhere else. And you want to upload the data to Blynk. What kind of screen do you have ? do you think you can get it to work on the nodeMCU ? I mean have you tried. 1 board less is always more practical, so it's worth making the UNO obsolete if possible..

Code for uno connected to LCD

#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>

#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

int Val;

long Sig_Time;

void setup(void) {

  Serial.begin(9600);

  progmemPrintln(PSTR("TFT LCD test"));

#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif

  tft.reset();

  tft.begin(0x9341); // SDFP5408

  tft.setRotation(0); 
  tft.fillScreen(BLACK);

   //tft.fillRect(20, 20, 200, 160, RED); 

  tft.setRotation(1);
  tft.fillRect(85, 85, 170, 35, RED);
  tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(90, 90); tft.print("NO SIGNAL");

}

void loop(void) {
  if ( millis()-Sig_Time > 30000){
    tft.fillScreen(BLACK);
    tft.fillRect(85, 85, 170, 35, RED);
    tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(90, 90); tft.print("NO SIGNAL");
    } 
  if(Serial.available()>0){
    
    String Read = Serial.readStringUntil("#");
    Serial.println(Read);

    Val = Read.toInt();

    Serial.println(Val);

    if(Val>100){ 
      Sig_Time = millis();
      Val = Val-100; 
      
      tft.setRotation(0);

      //tft.fillRect(85, 85, 170, 35, BLACK);

      tft.fillScreen(BLACK);
  
      //tft.fillScreen(BLACK);

      tft.fillRect(20, 20, 210, 160, RED);   //delay(1000);
      tft.fillRect(25, 25, 210, 150, BLACK); //delay(3000);
  
     //for ( int i =0; i<190; i++) { tft.fillRect(30, 30, i, 140, GREEN); } //delay(1);}

     int lvl = Val*2;

           if (Val<25) { tft.fillRect(30, 30, lvl, 140, RED); }
      else if (Val<50) { tft.fillRect(30, 30, lvl, 140, YELLOW); }
      else if (Val<75) { tft.fillRect(30, 30, lvl, 140, BLUE); }
      else if (Val>=75){ tft.fillRect(30, 30, lvl, 140, GREEN); }


      tft.setRotation(1);

      tft.fillRect(200, 160, 100, 80, BLACK); tft.setTextColor(WHITE); tft.setTextSize(5); tft.setCursor(200, 160); tft.print(Val); tft.print("% ");
	  /*tft.fillRect(200, 160, 100, 80, BLACK);*/ tft.setTextColor(WHITE); tft.setTextSize(2.5); tft.setCursor(200, 40); tft.print("ECJ IOT"); 
      /*tft.fillRect(200, 160, 100, 80, BLACK);*/ tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(200, 80); tft.print("WATER"); 
                                                                                               tft.setCursor(200,120); tft.print("LEVEL");
      } 
      
    else { 
      tft.fillScreen(BLACK);
      //if(Val==33){for ( int i=0; i<20; i++){ tft.drawCircle(200, 260, i, GREEN); }} 
      //if(Val==22){for ( int i=0; i<20; i++){ tft.drawCircle(200, 260, i, YELLOW); }}

      if(Val==33){
        tft.fillRect(85, 85, 170, 35, RED);
        tft.setTextColor(WHITE); tft.setTextSize(3); tft.setCursor(90, 90); tft.print("NO-SIGNAL");
        } 
      }
    }
  }

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(BLACK);
  tft.fillScreen(RED);
  tft.fillScreen(GREEN);
  tft.fillScreen(BLUE);
  tft.fillScreen(BLACK);
  return micros() - start;
}

unsigned long testText() {
  tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(YELLOW); tft.setTextSize(2);
  tft.println(1234.56);
  tft.setTextColor(RED);    tft.setTextSize(3);
  tft.println(0xDEADBEEF, HEX);
  tft.println();
  tft.setTextColor(GREEN);
  tft.setTextSize(5);
  tft.println("Groop");
  tft.setTextSize(2);
  tft.println("I implore thee,");
  tft.setTextSize(1);
  tft.println("my foonting turlingdromes.");
  tft.println("And hooptiously drangle me");
  tft.println("with crinkly bindlewurdles,");
  tft.println("Or I will rend thee");
  tft.println("in the gobberwarts");
  tft.println("with my blurglecruncheon,");
  tft.println("see if I don't!");
  return micros() - start;
}

unsigned long testLines(uint16_t color) {
  unsigned long start, t;
  int           x1, y1, x2, y2,
                w = tft.width(),
                h = tft.height();

  tft.fillScreen(BLACK);

  x1 = y1 = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t     = micros() - start; // fillScreen doesn't count against timing

  tft.fillScreen(BLACK);

  x1    = w - 1;
  y1    = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(BLACK);

  x1    = 0;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(BLACK);

  x1    = w - 1;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);

  return micros() - start;
}

unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  unsigned long start;
  int           x, y, w = tft.width(), h = tft.height();

  tft.fillScreen(BLACK);
  start = micros();
  for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  //for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);

  //tft.drawFastHLine(0, y, w, color1);

  return micros() - start;
}

unsigned long testRects(uint16_t color) {
  unsigned long start;
  int           n, i, i2,
                cx = tft.width()  / 2,
                cy = tft.height() / 2;

  tft.fillScreen(BLACK);
  n     = min(tft.width(), tft.height());
  start = micros();
  for(i=2; i<n; i+=6) {
    i2 = i / 2;
    tft.drawRect(cx-i2, cy-i2, i, i, color);
  }

  return micros() - start;
}

unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  unsigned long start, t = 0;
  int           n, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  n = min(tft.width(), tft.height());
  for(i=n; i>0; i-=6) {
    i2    = i / 2;
    start = micros();
    tft.fillRect(cx-i2, cy-i2, i, i, color1);
    t    += micros() - start;
    // Outlines are not included in timing results
    tft.drawRect(cx-i2, cy-i2, i, i, color2);
  }

  return t;
}

unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;

  tft.fillScreen(BLACK);
  start = micros();
  for(x=radius; x<w; x+=r2) {
    for(y=radius; y<h; y+=r2) {
      tft.fillCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int           x, y, r2 = radius * 2,
                w = tft.width()  + radius,
                h = tft.height() + radius;

  // Screen is not cleared for this one -- this is
  // intentional and does not affect the reported time.
  start = micros();
  for(x=0; x<w; x+=r2) {
    for(y=0; y<h; y+=r2) {
      tft.drawCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testTriangles() {
  unsigned long start;
  int           n, i, cx = tft.width()  / 2 - 1,
                      cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  n     = min(cx, cy);
  start = micros();
  for(i=0; i<n; i+=5) {
    tft.drawTriangle(
      cx    , cy - i, // peak
      cx - i, cy + i, // bottom left
      cx + i, cy + i, // bottom right
      tft.color565(0, 0, i));
  }

  return micros() - start;
}

unsigned long testFilledTriangles() {
  unsigned long start, t = 0;
  int           i, cx = tft.width()  / 2 - 1,
                   cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  start = micros();
  for(i=min(cx,cy); i>10; i-=5) {
    start = micros();
    tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(0, i, i));
    t += micros() - start;
    tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(i, i, 0));
  }

  return t;
}

unsigned long testRoundRects() {
  unsigned long start;
  int           w, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  w     = min(tft.width(), tft.height());
  start = micros();
  for(i=0; i<w; i+=6) {
    i2 = i / 2;
    tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  }

  return micros() - start;
}

unsigned long testFilledRoundRects() {
  unsigned long start;
  int           i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  start = micros();
  for(i=min(tft.width(), tft.height()); i>20; i-=6) {
    i2 = i / 2;
    tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
  }

  return micros() - start;
}

// Copy string from flash to serial port
// Source string MUST be inside a PSTR() declaration!
void progmemPrint(const char *str) {
  char c;
  while(c = pgm_read_byte(str++)) Serial.print(c);
}

// Same as above, with trailing newline
void progmemPrintln(const char *str) {
  progmemPrint(str);
  Serial.println();
}

code for wemos ESP8266 mini connected with RF Reciever,POT,Buzzer

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL2odH_TnAc"
#define BLYNK_TEMPLATE_NAME "Water Level"
#define BLYNK_AUTH_TOKEN "gfSCpuFg4n3GBYjrEYhjEeFmwJ2b4nQu" 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <EEPROM.h>
#include <RCSwitch.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(D1,D2);

RCSwitch mySwitch = RCSwitch();

char auth[] = "gfSCpuFg4n3GBYjrEYhjEeFmwJ2b4nQu";
char ssid[] = "AndroidAP98D2";
char pass[] = "wdgo5814";

BlynkTimer timer;

float Tank_Hight,Tank_U_Hight;
int OldLevel;
int Distance;

float Level;

int Buzzer = D0;

int LED = D4;

long Time,UP_Time,Buzz_Time;

int i,Flag;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
  EEPROM.begin(512);
  delay(1000);
  mySwitch.enableReceive(D5);
  
  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  
  timer.setInterval(100L, Update_Data);
  
  //Tank_Hight = EEPROM.read(100)*10;

  Tank_Hight = analogRead(A0)/3;
  //Tank_Hight = Tank_Hight;

  Serial.print("Tank_Hight : "); Serial.println(Tank_Hight);

  pinMode(LED,OUTPUT);
  pinMode(Buzzer,OUTPUT);
}

void Update_Data() {
  Blynk.virtualWrite(V4, Tank_Hight);  
}

//BLYNK_WRITE(V2){ Tank_U_Hight = param.asInt(); Serial.println(Tank_Hight); }
//BLYNK_WRITE(V3){ EEPROM.write(100, Tank_U_Hight/10); EEPROM.commit(); Tank_Hight = EEPROM.read(100)*10; Serial.print("Hight Updated "); Serial.println(Tank_Hight); }

void loop() {
  Tank_Hight = analogRead(A0)/30;

  Tank_Hight = Tank_Hight*10;

  if ( millis() - UP_Time>1000){
    UP_Time = millis();
    Serial.print("Tank_Hight : "); Serial.println(Tank_Hight);
  }
  
  Blynk.run();
  timer.run();
  Run();
  }

void Run(){ 
  if (mySwitch.available()) {
    digitalWrite(LED,LOW);
    int Rec = mySwitch.getReceivedValue();
    Distance = Rec - 3000;
 
    mySwitch.resetAvailable();
    Serial.println(Distance);
    Blynk.virtualWrite(V1, Distance);

    calculate_Level(); 
    digitalWrite(LED,HIGH);

    if(Level>90 || Level<10){ if(i==0){ i=1; Buzz_Time=millis();}}
    if(Level<85 && Level>15){ i=0; }
    }

  if(millis()-Buzz_Time<60000){ if(i==1) { Buzz();} else { digitalWrite(Buzzer,LOW); }}
  else                        { digitalWrite(Buzzer,LOW);}
  }

void Buzz(){
  if(millis()-Time>100){ 
    Time = millis(); 
    Flag = !Flag; 
    digitalWrite(Buzzer,Flag); 
    }
}
void calculate_Level(){
  //Tank_Hight = 200;
  
  int h = Tank_Hight - Distance;

  Level = h*100/( Tank_Hight-25 );

  if (Level>100) { Level = 100; }
  if (Level<0)   { Level = 1; }

  Serial.println(Level);

  if(Level == OldLevel ){ OldLevel = Level; }
  else                  { OldLevel = Level; mySerial.print(Level + 100);mySerial.println("#"); }

  Blynk.virtualWrite(V0, Level);
  
  }