#DIAGRAM:--
NOTE: REMOVE RX AND TX PIN WHILE UPLOADING CODE OR U WILL FACE ERROR
#Setting our UNO - IDE
#FOLLOW UP:)
1.OPEN-UNO-IDE: Add this link to the additional board manager URL
link: https://arduino.esp8266.com/stable/package_esp8266com_index.json
2.Install ESP8266 [fallow image]
3.HOW TO UPLOAD CODE!
#CODE FOR ARDUINO
- int led = 12;
- void setup() {
- pinMode(12,OUTPUT);
- Serial.begin(9600);
- while (!Serial);
- Serial.println("Input 1 to Turn LED on and 0 to off");
- }
- void loop() {
- if(Serial.available()){
- int state = Serial.parseInt();
- if (state == 3){
- digitalWrite(12,HIGH);
- Serial.println("Command received:1 LED turned ON");
- }
- if (state == 4){
- digitalWrite(12,LOW);
- Serial.println("Command received:0 LED turned OFF");
- }
- }}
#CODE FOR NODEMCU8266
REMEMBER TO PUT UR WIFI&PASSWORD
- # include <ESP8266WiFi.h>
- # include<SoftwareSerial.h>
- WiFiClient
- client;
- WiFiServer
- server(80);
- SoftwareSerial
- abc(13, 15);
- # define led D5
- # define led2 D6
- void
- setup()
- {
- // put
- your
- setup
- code
- here, to
- run
- once: \
- Serial.begin(9600);
- WiFi.begin("cool", "gaurav123");
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(200);
- Serial.print("..");
- }
- Serial.println();
- Serial.println("NodeMCU is connected!");
- Serial.println(WiFi.localIP());
- server.begin();
- pinMode(led, OUTPUT);
- pinMode(led2, OUTPUT);
- }
- void
- loop()
- {
- // put
- your
- main
- code
- here, to
- run
- repeatedly:
- client = server.available(); // Gets
- a
- client
- that is connected
- to
- the
- server and has
- data
- available
- for reading.
- if (client == 1)
- {
- String
- request = client.readStringUntil('\n');
- Serial.println(request);
- request.trim();
- if (request == "GET /led1on HTTP/1.1")
- {Serial.write("3");
- }
- if (request == "GET /led1off HTTP/1.1")
- {Serial.write("4");
- }
- if (request == "GET /led2on HTTP/1.1")
- {
- digitalWrite(led2, HIGH);
- }
- if (request == "GET /led2off HTTP/1.1")
- {
- digitalWrite(led2, LOW);
- }
- }
- client.println("HTTP/1.1 200 OK"); //
- client.println("Content-Type: text/html");
- client.println("");
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- client.println("<h1>Welcome to the Webpage!</h1>");
- client.println("<h3>LED Controls<h3>");
- client.println("<br>");
- client.println("<a href=\"/led1on\"\"><button>LED 1 ON</button></a>");
- client.println("<a href=\"/led1off\"\"><button>LED 1 OFF</button></a><br/>");
- client.println("<a href=\"/led2on\"\"><button>LED 2 ON</button></a>");
- client.println("<a href=\"/led2off\"\"><button>LED 2 OFF</button></a><br/>");
- client.println("</html>");
- }
#OPEN MONITOR AND & PRESS THE RESET BUTTON TO SEE THE IP WHERE U CAN CONTROL THE LED