ESP 8266 Microcontroller:

The ESP8266 is a low-cost Wi-Fi microchip, with built-in TCP/IP networking software, and microcontroller capability, produced by Espressif Systems.

The chip was popularized in the English-speaking maker community in August 2014 via the ESP-01 module, made by a third-party manufacturer Ai-Thinker. This small module allows microcontrollers to connect to a Wi-Fi network and make simple TCP/IP connections using Hayes-style commands. However, at first, there was almost no English-language documentation on the chip and the commands it accepted.



Connecting to ESP 8266:

We need many components to connect to the esp 8266 controller, Like,
  • Breadboard
  • Sensors
  • Jumper Wire

There are different ways to program the ESP8266 such as micropython (a subset of python) or using the Arduino IDE.

In this lesson, we will be using the Arduino IDE as it has a simple interface with built-in examples.

Analog to Digital Converter : Analog to Digital Converter (ADC) is used to convert the analog signal into digital form. ESP8266 has an inbuilt 10-bit ADC with only one ADC channel i.e. pinMode(A0,INPUT) , Serial.begin(9600), it has only one ADC input pin to read the analog voltage from an external device. Example:


int variable =0;

void setup(){

  pinMode(A0,INPUT);

  Serial.begin(9600);

}

void loop(){

  

  variable =analogRead(A0);

  Serial.println(variable);

}


How to program an ESP8266 with Arduino GUI?


  • Select “File –> Preferences”

ESP8266-12 architecture

  • Add http://arduino.esp8266.com/stable/package_esp8266com_index.json to “Additional Boards Manager URLs”

ESP8266-12 architecture

  • Click on “OK”

Select Port

Finally you need to select the port (physical USB connector on your computer) to tell the path where the board is physically plugged in your computer.

  • Click on “Tools –> Port” and select the corresponding USB port.

ESP8266-12 select port

  • Check you have selected it: when you click again on “Tools –> Port”, you should see a “tick” in front of your selected port (see image below):
  • https://drive.google.com/file/d/1DvBg-_MTr-zP-JZKL-eL85bHfqBoP-zt/view?usp=sharing

ESP8266-12 selected port



LED On/Off (ESP8266 as server)

https://create.arduino.cc/projecthub/shauryacool/web-server-led-control-c2a84f

#include <ESP8266WiFi.h>
const char* ssid = "Yasin Arafat";
const char* password = "yasinarafat931300";
WiFiServer server(80);
int ledPin = D4;
void setup() {
pinMode(ledPin,OUTPUT);
digitalWrite(ledPin,LOW);
Serial.begin(115200);
WiFi.begin(ssid,password);
Serial.println("Connecting");
while( WiFi.status() != WL_CONNECTED ){
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("Wifi Connected");
Serial.println(WiFi.localIP() );
server.begin();
Serial.println("Server started");
}
void loop() {
WiFiClient client = server.available();
if (!client)return;
while(!client.available());
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
int value = LOW;
if (request.indexOf("/LED=ON") != -1) {
digitalWrite(ledPin, LOW);
value = HIGH;
}
else if (request.indexOf("/LED=OFF") != -1) {
digitalWrite(ledPin, HIGH);
value = LOW;
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<body>");
client.print("Status : ");
if(value == HIGH) {
client.print("On");
} else {
client.print("Off");
}
client.println("<br><br>");
client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");
client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");
client.println("</html>");
}

Comments