First: You use SoftwareSerial. If ever possible, don't use the catastrophic piece of Software.
Second:
esp8266.begin(115200);
You set the baud rate of this SoftwareSerial to 115200 baud. It won't work at that speed. If you have an extremely timing tolerant counterpart device you may perhaps reach 38400 baud at most, usually 9600 is a more realistic upper limit.
Your code is far from doing anything you described first.
If you just want to light up the LED, you should not send the characters '0' or '1' but the values 0 or 1 (I hope you understand the difference, otherwise ask).
Remote the println() calls from the ESP code and use
Is that still possible for ESP8266 connect to WIFI?
Yes, that's the intended way to use the ESP8266 as a WiFi device from an Arduino.
2 If dont want to use software serial, so how we can declare the esp8266.read(), esp8266.read()?
How to replace the below code?
You have several possibilities, which one you choose depends on the requirements you have on the project (you didn't tell us yet):
Use the hardware serial interface (pin 0 and 1) instead (Serial object to access it) but than you cannot use that channel for debugging.
Use AltSoftSerial or NeoSWSerial instead of SoftwareSerial. Both have some limitations but are by far more reliable (based on interrupts instead of deactivating all of them) and leave you more processor power for the rest of the sketch.
Thanks a lot for the information about the serial things =D
what is the requirement for my project
hmm, what is the scope u meant for the requirement?
Actually my project is smart home automation with security system. The main controller is actually Arduino Mega, and communicate with the ESP-01 and pass data to firebase. It also call homeuser through GSM when home is not secure. So i think will do something like interrupt so that the system is much more efficient? (for now still no idea how interrupt works in arduino).
And actually, face some problem when including FirebaseArduino.h and ESP8266Wifi.h in ESP-01.
Just for extra question, the firebase library and the code that deal with firebase should upload to ESP-01 instead of Arduino uno/mega right?
Actually my project is smart home automation with security system. The main controller is actually Arduino Mega, and communicate with the ESP-01 and pass data to firebase.
A Mega? Why does the thread title the specify an UNO? And in the first post you only wrote about an UNO, no mention of a Mega. It's completely stupid to use a emulation in software that blocks the complete CPU if you have 4 of these interfaces in hardware.
Please define what a "firebase" is. A link may help.
So i think will do something like interrupt so that the system is much more efficient?
Using interrupts doesn't automatically make a system more efficient, it even may be contrary. Programming in interrupt context requires a deep knowledge of the underlying processor and it's architecture otherwise raise conditions are inevitable.
Start with the simple solutions.
To be able to help you we need to know what hardware you're using. Telling us it's an UNO but using a Mega doesn't help. If you want to use GSM you must have some additional hardware. Provide a link to it.
we will use Mega for the project. For now i just test the ESP-01 module as well as Firebase with UNO because i have one UNO with me. After that will get a Mega.
p.s. is my mistake for not putting MEGA in title.
Firebase
Firebase is basically a cloud database, which is a platform owned by google. It is a real time database.
Link:
GSM
For GSM, we bought a SIM900A.
What is meant by 'use a emulation in software that blocks the complete CPU if you have 4 of these interfaces in hardware '?
What is meant by 'use a emulation in software that blocks the complete CPU if you have 4 of these interfaces in hardware '?
In your code you use SoftwareSerial which is a crippled piece of software that tries to emulate the functionality of a UART (serial interface in hardware) but does that by turning off all interrupts during the sending or reception of a complete byte. So if you have a sketch that needs to react in timely manner to external events you won't be able to do that if you use SoftwareSerial.
The Mega has 4 UARTs built in, so there's no need to use any software emulation.
If you want to go with the UNO and need the hardware serial interface for debugging, try at least if the alternative software emulations (AltSoftSerial or NeoSWSerial) might work with your setup before using that SoftwareSerial.