Chuyển tới nội dung
Home » Esp8266 Arduino App Inventor | Creating The Android App With Mit App Inventor

Esp8266 Arduino App Inventor | Creating The Android App With Mit App Inventor

How to Make a Simple App--[NodeMCU-ESP8266] -PART1

Code

Upload the following code into your ESP8266 using the preceding software. Your file should be named “init.lua“.

Don’t forget to add your network name (SSID) and password to the script below.


-- Rui Santos -- Complete project details at https://randomnerdtutorials.com wifi.setmode(wifi.STATION) wifi.sta.config("YOUR_NETWORK_NAME","YOUR_NETWORK_PASSWORD") print(wifi.sta.getip()) led1 = 3 led2 = 4 gpio.mode(led1, gpio.OUTPUT) gpio.mode(led2, gpio.OUTPUT) srv=net.createServer(net.TCP) srv:listen(80,function(conn) conn:on("receive", function(client,request) local buf = ""; buf = buf.."HTTP/1.1 200 OK\n\n" local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP"); if(method == nil)then _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); end local _GET = {} if (vars ~= nil)then for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do _GET[k] = v end end if(_GET.pin == "ON1")then gpio.write(led1, gpio.HIGH); elseif(_GET.pin == "OFF1")then gpio.write(led1, gpio.LOW); elseif(_GET.pin == "ON2")then gpio.write(led2, gpio.HIGH); elseif(_GET.pin == "OFF2")then gpio.write(led2, gpio.LOW); end client:send(buf); client:close(); collectgarbage(); end) end)

/***********
Juan A. Villalpando
KIO4.COM
25/11/22
Version del módulo 9.2.4
Velocidad 9600
Carga el programa. Ve al Serial Monitor.
Escribe en un navegador 192.168.1.5
Pulsa los botones para encender o apagar el LED13 del Arduino.
***********/
#include

#define DEBUG true
SoftwareSerial esp8266(3,2);
// El TX del módulo al terminal 3 del Arduino.
// El RX del módulo al terminal 2 del Arduino.
void setup()
{
pinMode(13,OUTPUT);
Serial.begin(9600);
esp8266.begin(9600); // Importante la velocidad del módulo.
sendData(“AT+RST\r\n”,2000,DEBUG); // Borra la configuración que tenía el módulo
sendData(“AT+CWJAP=\”Nombre_de_tu_WiFi\”,\”Clave_de_tu_WiFi\”\r\n”, 2000, DEBUG);
delay(5000); // Espera un poco que conecte con el Router.
sendData(“AT+CWMODE=3\r\n”,1000,DEBUG); // Modo de cliente y servidor.
sendData(“AT+CIFSR\r\n”,1000,DEBUG); // En el Serial Monitor aparece la IP de cliente y servidor.
sendData(“AT+CIPMUX=1\r\n”,1000,DEBUG); // Multiples conexiones.
sendData(“AT+CIPSERVER=1,80\r\n”,1000,DEBUG); // El Puerto web es el 80
}
void loop(){
if(esp8266.available()) // Consulta si el módulo está enviando algún mensaje
{
if(esp8266.find(“+IPD,”))
{
delay(500);
int connectionId = esp8266.read()-48;
// Aquí las construcción de la PAGINA WEB.
String webpage = “HTTP/1.1 200 OK\r\n Content-Type: text/html\r\n\r\n\r\n”;
webpage += ”

KIO4.COM

“;
webpage += ”

“;
webpage += ”

“;
webpage += ”

“;
webpage += ”

\r\n\r\n”;
String cipSend = “AT+CIPSEND=”;
cipSend += connectionId;
cipSend += “,”;
cipSend +=webpage.length();
cipSend +=”\r\n”;
sendData(cipSend,500,DEBUG);
sendData(webpage,500,DEBUG);
// Lee el pin 13
int pin13 = digitalRead(13);
// Retorno de la lectura.
String retorno = “HTTP/1.1 200 OK\r\n Content-Type: text/html\r\n\r\n\r\n”;
if (pin13 == 1) {retorno += ” ON – Encendido”;}
if (pin13 == 0) {retorno += ” OFF – Apagado”;}
// ResponseCode App Inventor
cipSend = “AT+CIPSEND=”;
cipSend += connectionId;
cipSend += “,”;
cipSend += retorno.length();
cipSend +=”\r\n”;
sendData(cipSend,500,DEBUG);
sendData(retorno,500,DEBUG);
// Cierra la conexión
String closeCommand = “AT+CIPCLOSE=”;
closeCommand+=connectionId;
closeCommand+=”\r\n”;
sendData(closeCommand,500,DEBUG);
}
}
}
// Función para Enviar datos al Servidor.
String sendData(String command, const int timeout, boolean debug){
String response = “”;
esp8266.print(command); // Envía la información de command al servidor
long int time = millis();
while( (time+timeout) > millis())
{
while(esp8266.available())
{
// A response van los datos que regresan al servidor.
char c = esp8266.read(); // Va leyendo caracter a caracter.
response+=c;
// Consulta si en la información que regresa al servidor
// viene “GET /enci” o “GET /apag”
// Encenderá o apagará el LED13 del Arduino
if(response.indexOf(“GET /enci”) >0){
// Serial.print(“enciende”);
digitalWrite(13,HIGH);
}
if(response.indexOf(“GET /apag”) >0){
//Serial.print(“apaga”);
digitalWrite(13,LOW);
}
}
}
if(debug)
{
Serial.print(response);
}
return response;
}

// http://kio4.com/arduino/57modulowifi_2.htm
// Juan A. Villalpando
#include

SoftwareSerial esp8266(3,2);
// El TX del módulo al terminal 3 del Arduino.
// El RX del módulo al terminal 2 del Arduino.
int random_1 = 10;
int random_2 = 50;
String random_out = “0,0”;
String input_data = “”;
String fin = “”;
void setup(){
randomSeed(analogRead(A0));
Serial.begin(9600);
esp8266.begin(9600);
sendData(“AT+RST\r\n”,2000); // Borra la configuración que tenía el módulo
sendData(“AT+CWJAP=\”Nombre_de_tu_WiFi\”,\”Clave_de_tu_WiFi\”\r\n”, 2000);
delay(10000); // Espera un poco que conecte con el Router.
sendData(“AT+CWMODE=1\r\n”,1000); // Modo de cliente del Router.
sendData(“AT+CIFSR\r\n”,1000); // En el Serial Monitor aparece la IP del Servidor Web.
sendData(“AT+CIPMUX=1\r\n”,1000); // Multiples conexiones.
sendData(“AT+CIPSERVER=1,80\r\n”,1000); // Crea Servidor Web, puerto 80
}
void loop(){
if(esp8266.available()){
while(esp8266.available()){
char c = esp8266.read();
input_data += c;
if(input_data.indexOf(“genera”) > 0){
random_1 = random(10,50);
random_2 = random(50,99);
random_out = (String) random_1 + “,” + (String) random_2;
input_data = “”;
fin = “finalizado”;
}
}
}
// Return responseContent
if(fin == “finalizado”){
String header = “HTTP/1.1 200 OK\r\n Content-Type: text/html; \r\n”;
header += “Content-Length: “;
header += random_out.length();
header += “\r\nConnection: close\r\n\r\n”;
header += random_out;
sendData(“AT+CIPSEND=” + String(0) + “,” + header.length() + “\r\n”, 500);
sendData(header,1000);
// sendData (“AT+CIPCLOSE=” + String(0) + “\r\n”, 1000);
fin = “”;
}
}
// Envia datos al servidor y recibe la respuesta de los AT.
String sendData(String command, const int timeout){
String response = “”;
esp8266.print(command); // Envía la información de command al servidor
long int time = millis();
while( (time+timeout) > millis()){
while(esp8266.available()){
// A response van los datos que regresan al servidor.
char c = esp8266.read(); // Va leyendo caracter a caracter.
response+=c;
}
}
Serial.print(response);
return response; // Devuelve la respuesta del AT
}

It took me a while to figure out how the web server “knew” to work off IP address 192.168.1.9, but then I saw it in the COM24 log as the result of the AT+CIFSR command, and I imagine you read that output to get the IP address hard coded into the AI2 app.

Now we are going to carry out the previous example but we will create an Access Point (SoftAP – Soft Access Point), that is, the module will create a network independent from the Router, it will not be connected to the Router.

The code will create a network called ESP_81411C and the Web Server will have as IP: 192.168.4.1

For this we will change these lines…

void setup(){
randomSeed(analogRead(A0));
Serial.begin(9600);
esp8266.begin(9600);
sendData(“AT+RST\r\n”,2000); // Borra la configuración que tenía el módulo
// sendData(“AT+CWJAP=\”Nombre_de_tu_WiFi\”,\”Clave_de_tu_WiFi\”\r\n”, 2000);
// delay(10000); // Espera un poco que conecte con el Router.
sendData(“AT+CWMODE=2\r\n”,1000); // NOW IS A SOFT ACCESS POINT, MODE = 2
sendData(“AT+CIFSR\r\n”,1000); // En el Serial Monitor aparece la IP del Servidor Web. (192.168.4.1)
sendData(“AT+CIPMUX=1\r\n”,1000); // Multiples conexiones.
sendData(“AT+CIPSERVER=1,80\r\n”,1000); // Crea Servidor Web, puerto 80
}

We must change the IP in the code…

It is also convenient to install the application, since we are going to change the network and the MIT Companion will be in the Router’s network.

Once the application is installed, we go to the WiFi configuration and establish the ESP_81411C network

It is not necessary to put a Password since in this default configuration it does not have it.

If we wanted to change the name of the network and put a password on it, we would put this line:

3.- Remove the Serial Monitor, in case you have it open.

4.- We load this sketch in the IDE and upload it…

It is convenient from time to time to remove the power from the ESP8266 and put it back if it does not load well.

Summary

/*
* This sketch demonstrates how to set up a simple HTTP-like server.
* The server will set a GPIO pin depending on the request
* http://server_ip/gpio/0 will set the GPIO2 low,
* http://server_ip/gpio/1 will set the GPIO2 high
* server_ip is the IP address of the ESP8266 module, will be
* printed to Serial when the module is connected.
*/
#include

const char* ssid = “nombredemirouter”;
const char* password = “contraseñadelrouter”;
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(9600);
delay(1500);
// prepare GPIO2
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
// Start the server
server.begin();
Serial.println(“Server started”);
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println(“new client”);
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil(‘\r’);
Serial.println(req);
client.flush();
// Match the request
int val;
if (req.indexOf(“/gpio/0”) != -1)
val = 0;
else if (req.indexOf(“/gpio/1”) != -1)
val = 1;
else {
Serial.println(“invalid request”);
client.stop();
return;
}
// Set GPIO2 according to the request
digitalWrite(2, val);
client.flush();
// Prepare the response
String s = “HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n

\r\n

\r\nGPIO is now “;
s += (val)?”high”:”low”;
s += ”

\n”;
// Send the response to the client
client.print(s);
delay(1);
Serial.println(“Client disonnected”);
// The client will actually be disconnected
// when the function returns and ‘client’ object is detroyed
}

5.- When there is upload, remove the GPIO 0 to GND cable and open the Serial Monitor. Restart.

6.- Once the sketch is loaded we can remove the Arduino, connect an LED to the GPIO2 and feed the module with 3.3V

If you don’t have a 3.3V power supply, you can use the Arduino to power the module, note that you don’t need RX or TX.

Điều khiển thiết bị bằng MIT App Inventor sử dụng NodeMCU ESP8266

Trong nội dung bài viết hôm nay mình sẽ giới thiệu với các bạn một chủ đề mới cách có thể tạo một App Android trên MIT App Inventor một cách nhanh chóng mà không cần phải biết về lập trình nhiều.

Bài viết sẽ hướng dẫn các bạn cách tạo một App đơn giản và điều khiển các thiết bị trong gia đình thông qua NodeMCU ESP8266. Để có thể nắm rõ hơn các bạn có thể tìm đọc các bài viết liên quan đến dự án.

How to Make a Simple App--[NodeMCU-ESP8266] -PART1
How to Make a Simple App–[NodeMCU-ESP8266] -PART1

Creating the Android App with MIT App Inventor

MIT App Inventor is a drag-and-drop software that allows you to create a basic, but fully functional Android app within an hour or less.

Here’s how to edit the ESP8266 Controller app:

  1. Click here to download the .aia file
  2. Unzip the folder
  3. Go to MIT App Inventor
  4. Click the “Create Apps” button on the top right corner
  5. Go to the “Projects” tab and select “Import project (.aia)”

After importing the .aia file, you’ll be able to edit the app and see how the app was built.

Designer

The designer tab is where you can edit how the app looks. Feel free to change the text, change the colors, add buttons or add more features.

Blocks

The blocks section is where you can add what each button does and add logic to your app.

After finishing editing the app you can click the “Build” app tab and install the .apk file in your Android. I personally recommend that you first upload the app provided below to ensure that everything works as expected (later you can edit the app).

Installing the Android App

Follow these instructions to install the default app that I’ve created:

  1. Click here to download the .apk file
  2. Unzip the folder
  3. Move the .apk file to your Android phone
  4. Run the .apk file to install the app

Here’s how the ESP8266 Controller app looks when you to open it.

It’s very easy to configure. Click the button “Set IP Address” on the bottom of the screen and type your IP address (in my case 192.168.1.95).

You’re all set!

Now you can turn the GPIOs high and low with your smartphone. Go to the top of this page to see a video demonstration of this project.

ESP8266 Android App (created with MIT App Inventor) - Demo
ESP8266 Android App (created with MIT App Inventor) – Demo

Step 2: Install the ESP8266 Board Libraries and Tools

  1. From the Arduino IDE Menu select |Tools|Board:……|Boards Manager…| (Picture 1)
  2. In the text box of the Boards Manager dialog type ESP, then select the “esp8266 by ESP8266 Community” and click on the Install button (Picture 2)
  3. When the installation finishes, clock on the “Close” button (Picture 3)

References[edit]

  1. ^ “ESP8266 Overview”. Espressif Systems. Retrieved 2017-10-02.
  2. ^ Brian Benchoff (August 26, 2014). “New Chip Alert: The ESP8266 WiFi Module (It’s $5)”. Hackaday. Retrieved 2015-06-24.
  3. ^ Brian Benchoff (September 6, 2014). “The Current State of ESP8266 Development”. Hackaday. Retrieved 2015-06-24.
  4. ^ “Espressif Announces ESP8285 Wi-Fi Chip for Wearable Devices”. Espressif Systems. Mar 9, 2016. Archived from the original on 2016-07-25. Retrieved 2016-07-10.
  5. ^ “ESP8266 Non-OS SDK API Reference, Chapter 2.4. System Performance” (PDF). espressif.com. Espressif Systems. The flash mode and frequency directly influence the code execution speed. Setting the flash to a higher frequency and QIO mode may produce the best results in terms of performance, though it costs in terms of power consumption. “ESP8266 Non-OS SDK API Reference” (PDF). espressif.com. Espressif Systems.Success varies chip to chip.[citation needed]
  6. ^ “ESP8266 Non-OS SDK API Reference, Chapter 2.5. System Memory” (PDF). espressif.com. Espressif Systems.
  7. ^ “ESP8266 Technical Reference, Version 1.7” (PDF). Espressif Systems. Retrieved 2021-04-22.
  8. ^ “Espressif ESP8266 Developer Zone Discussion Forum: Does ESP8266 actually have hardware I2C?”. Espressif Systems. 2014-10-27. Retrieved 2017-10-02.
  9. ^ Brian Benchoff (October 25, 2014). “An SDK for the ESP8266 WiFi Chip”. Hackaday. Retrieved 2015-06-24.
  10. ^ “Official SDK release from Espressif for ESP8266”. Espressif Systems. July 29, 2015. Retrieved 2015-08-08.
  11. ^ Paul Sokolovsky (11 November 2022). “esp-open-sdk: Free and open (as much as possible) integrated SDK for ESP8266/ESP8285 chips”. GitHub.
  12. ^ Max Filippov (February 15, 2015). “ESP8266 GCC Toolchain”. GitHub. Retrieved 2015-08-08.
  13. ^ Mikhail Grigorev (29 August 2022). “Unofficial Development Kit for Espressif ESP8266 (GitHub Repository)”. GitHub.
  14. ^ Mikhail Grigorev. “Project Unofficial Development Kit for Espressif ESP8266”.
  15. ^ “Mongoose OS Documentation”. Cesanta. Archived from the original on 2018-01-27. Retrieved 2017-10-02.
  16. ^ Luigi F. Cerfeda (June 15, 2017). “Python for ESP8266 in just a few clicks using Zerynth”. Zerynth (Kinzica Ventures LLC).
  17. ^ “Espressif ESP-WROOM-02”. Espressif Systems. Retrieved 2015-07-29.
  18. ^ a b “ESP-WROOM-02D/ESP-WROOM-02U Datasheet” (PDF). Espressif Systems. Archived from the original (PDF) on 2017-12-01. Retrieved 2017-11-25.
  19. ^ “ESP-WROOM-S2 Datasheet” (PDF). Espressif Systems. Archived from the original (PDF) on 2017-10-08. Retrieved 2017-10-08.
  20. ^ “ESP8266 module family”. ESP8266 Community Wiki. Retrieved 2015-06-24.
  21. ^ “ESP-01 (esp8266): high-resolution pinout and specs”. Mischianti.
  22. ^ “ESP-01S (esp8266): high-resolution pinout and specs”. Mischianti.
  23. ^ “2ADUIESP-12 by Shenzhen Anxinke technology co., LTD for Wi-Fi Module”. FCC. December 30, 2014. Retrieved 2015-06-24.
  24. ^ “FCC ID 2AHMR-ESP12S, Shenzhen Ai-Thinker Technology co., LTD WIFI MODULE -ESP12S”. FCC. August 4, 2016. Retrieved 2017-07-17.
  25. ^ “MOD-WIFI-ESP8266”. Olimex. Retrieved 2015-06-25.
  26. ^ “MOD-WIFI-ESP8266-DEV”. Olimex. Retrieved 2015-06-25.
  27. ^ “Adafruit HUZZAH ESP8266 Breakout”. Adafruit Industries. Retrieved 2015-06-25.
  28. ^ “SparkFun ESP8266 Thing”. SparkFun. Retrieved 2015-06-27.
  29. ^ “KNEWRON smartWIFI”. KNEWRON. Archived from the original on November 14, 2016. Retrieved 2016-03-04.
  30. ^ ESP8266 UNO (25 April 2016). “ArduCAM ESP8266 UNO Board”.

    {{cite web}}

    : CS1 maint: numeric names: authors list (link)
  31. ^ ESPduino. “Arduino ESPduino”. GitHub.
  32. ^ SwitchDoc Labs. “Grove WeatherPlus”.
  33. ^ a b c d e WeMos. “WEMOS”. WEMOS.
  34. ^ “WeMos D1”. WeMos. Archived from the original on 2017-09-03. Retrieved 2016-11-30.
  35. ^ “WeMos D1 R2”. WeMos. Archived from the original on 2017-09-03. Retrieved 2016-01-05.
  36. ^ “WeMos D1 mini”. WeMos. Archived from the original on 2017-07-02. Retrieved 2017-06-29.
  37. ^ “WeMos D1 mini Lite”. WeMos. Archived from the original on 2017-06-06. Retrieved 2017-06-29.
  38. ^ “WeMos D1 mini Pro”. WeMos. Archived from the original on 2017-08-27. Retrieved 2017-06-29.
  39. ^ “Espert”. Espert. Retrieved 2016-01-07.
  40. ^ “ESPresso Lite V2.0”. Espert Pte Ltd. Retrieved 2017-10-02.
  41. ^ “ESP-ADC DIL18 development board”. In-Circuit Wiki. Retrieved 2016-02-03.
  42. ^ “Watterott ESP-WROOM02-Breakout”. Watterott. Retrieved 2016-11-06.
  43. ^ “Geek Wave Solution ESP8266-WROOM-02-IOT WiFi Development Board”. Geek Wave Solution. Archived from the original on 2017-09-04. Retrieved 2017-09-04.
  44. ^ “Witty ESP8266 ESP-12E dual-level board”. N/A. Retrieved 2019-08-29.
  45. ^ List, Jenny (2020-11-22). “Espressif Leaks ESP32-C3: A WiFi SOC That’s RISC-V and is ESP8266 Pin-Compatible”. Hackaday.

In this project, you’re going to build an Android app using the MIT App Inventor software that allows you to control the ESP8266 GPIOs.

ESP8266 ve Android Haberleşmesi - FireBase Kullanımı - Nesnelerin İnterneti - IoT || App Inventor 2
ESP8266 ve Android Haberleşmesi – FireBase Kullanımı – Nesnelerin İnterneti – IoT || App Inventor 2

First, watch the video demonstration

To learn more about the ESP8266 use the following tutorials as a reference:

  • Getting started with the ESP8266
  • ESP8266 web server with NodeMCU
  • Flashing NodeMCU firmware
  • ESP8266 troubleshooting guide

If you like the ESP and you want to do more projects you can download my eBook Home Automation using ESP8266 here.

Let’s get started!

Espressif modules[edit]

This is the series of ESP8266-based modules made by Espressif:

Name Active pins Pitch Form factor LEDs Antenna Shielded Dimensions (mm) Notes
ESP-WROOM-02[17] 18 1.5 mm 2×9 castellated No PCB trace Yes 18 × 20 FCC ID 2AC7Z-ESPWROOM02.
ESP-WROOM-02D[18] 18 1.5 mm 2×9 castellated No PCB trace Yes 18 × 20 FCC ID 2AC7Z-ESPWROOM02D. Revision of ESP-WROOM-02 compatible with both 150-mil and 208-mil flash memory chips.
ESP-WROOM-02U[18] 18 1.5 mm 2×9 castellated No U.FL socket Yes 18 × 20 Differs from ESP-WROOM-02D in that includes an U.FL compatible antenna socket connector.
ESP-WROOM-S2[19] 20 1.5 mm 2×10 castellated No PCB trace Yes 16 × 23 FCC ID 2AC7Z-ESPWROOMS2.

In the table above (and the two tables which follow), “Active pins” include the GPIO and ADC pins with which external devices can be attached to the ESP8266 MCU. The “Pitch” is the space between pins on the ESP8266 module, which is important to know if the device will be used on a breadboard. The “Form factor” also describes the module packaging as “2 × 9 DIL”, meaning two rows of 9 pins arranged “Dual In Line”, like the pins of DIP ICs. Many ESP-xx modules include a small onboard LED which can be programmed to blink and thereby indicate activity. There are several antenna options for ESP-xx boards including a trace antenna, an onboard ceramic antenna, and an external connector that allows an external Wi-Fi antenna to be attached. Since Wi-Fi communications generate a lot of RFI (Radio Frequency Interference), governmental bodies like the FCC like shielded electronics to minimize interference with other devices. Some of the ESP-xx modules come housed within a metal box with an FCC seal of approval stamped on it. First and second world markets will likely demand FCC approval and shielded Wi-Fi devices.[citation needed]

How To Build a WiFi Based Robot with Android Application Control | Android App with MIT App Inventor
How To Build a WiFi Based Robot with Android Application Control | Android App with MIT App Inventor

Parts List

Here’s the hardware that you need to complete this project:

  • 1x ESP8266 -read Best ESP8266 Wi-Fi Developmento Boards
  • 1x FTDI programmer
  • 2x LEDs
  • 2x 220Ω Resistors
  • 1x Breadboard
  • 1x Android Phone – example OnePlus 5 (read review)

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Introduction: Setting Up the Arduino IDE to Program ESP8266

ESP8266 are widely available low cost Wi-Fi modules. They consist of single chip CPU with GPIO, Analog channel, Serial channels, I2C, SPI, and most importantly on chip Wi-Fi. Initially marketed as a low cost Wi-Fi modules for Arduino, and Raspberry Pi boards, they also can be programmed as stand alone boards with the Arduino IDE. To do this, you need first to install the ESP8266 libraries and tools in the Arduino IDE.

In this Instructable I will show you how you can install the ESP8266 libraries and tools, and start programming your ESP8266 modules in the Arduino IDE.

The libraries and tools are available on gighub here:

Hướng dẫn sử dụng App Inventor với ESP8266 wifi điều khiển thiết bị
Hướng dẫn sử dụng App Inventor với ESP8266 wifi điều khiển thiết bị

Creating the Android App with MIT App Inventor

MIT App Inventor is a drag-and-drop software that allows you to create a basic, but fully functional Android app within an hour or less.

Here’s how to edit the ESP8266 Controller app:

  1. Click here to download the .aia file
  2. Unzip the folder
  3. Go to MIT App Inventor
  4. Click the “Create Apps” button on the top right corner
  5. Go to the “Projects” tab and select “Import project (.aia)”

After importing the .aia file, you’ll be able to edit the app and see how the app was built.

Designer

The designer tab is where you can edit how the app looks. Feel free to change the text, change the colors, add buttons or add more features.

Blocks

The blocks section is where you can add what each button does and add logic to your app.

After finishing editing the app you can click the “Build” app tab and install the .apk file in your Android. I personally recommend that you first upload the app provided below to ensure that everything works as expected (later you can edit the app).

Taking It Further

This is a basic example that shows you how easy it is to integrate an Android app with the ESP8266. You can take this example and modify it.

You could add multiple screens to the app, so you can other ESPs or add buttons to control more GPIOs.

Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

I want to send temperature sensor data whenever a button named get temperature is pressed on app it should display the current temperature value. I am able to see new client request whenever I click the button and also Arduino serial print but it does not appear on the app text box… Please help

Welcome,

Most of the devices does not have the temperature sensor. See the documentation.

A sensor component that can measure the ambient (external) temperature. Most Android devices do not have this sensor.

They’re using an Arduino Temperature Sensor

Oh, I thought it is an Android sensor

This may help you:

Thanks @NishyanthKumarbut i m using Wifi instead of bluetooth … Here is the sample blocks which i want to use please ignore the cross marks as this is just an example. What i want to do is there is a button on my app which is getTemp when i press that button it sends new client request to esp8266 and whatever output in the form of text i get on serial monitor of arduino should get updated on the text box (temp) located just above the button.ill also provide sample arduino code here i have given constant temp example but it is a variable in my case and its changing

#include

const char* ssid = “JioFi2_C4FFC1”;const char* password = “######”;WiFiServer server(80);

void setup() {Serial.begin(38400);


Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(100); //500 Serial.print("."); } Serial.println(""); Serial.println("Wifi Connected"); Serial.println("Server started "); Serial.println(WiFi.localIP());

server.begin();

}void loop() {string temp=38*cWiFiClient client = server.available();if (!client){return;}Serial.println(“new client”);while(!client.available()){delay(1);}String req = client.readStringUntil(‘\r’);Serial.println(req);


if (req.indexOf("/getTemp")!=-1) { client.println(temp); Serial.println(temp); } String web = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"; client.print(web); client.flush();

Ah, sorry. Didn’t see that.I’m not the best at Arduino (I don’t know C++), but @Juan_Antonio and @NissanCedric are the go-to people to ask in its terms inside of this Community.

Check

Thanks @Juan_AntonioI have already gone through these two links but the problem with in my case is that I want to receive the text that obtained on serial monitor of Arduino but these 2 examples will send data from to esp device do I need to make any change in Arduino code or in app blocks to receive text from esp device to app using wifi.. … Please help

Here many examples with ESP32

Check your phone to see if its web browser can reach that 192.168… address.

You may need to switch from your cell service’s net access to local WiFi access to get there.

thanks for your support @Juan_Antonio I tried your example of analog read from potentiometer… but in my case it displays “Error1101: unable to connect to specific URL http://192.168.1.184/temp”i made the same program as like yours but to get temperature data in form of stringthe only difference here is :this is from your code-if (req.indexOf(“consulta”) != -1){valor = analogRead(Ent_Anilogica);valor_map = map(valor, 0, 4095, 0, 330);Serial.println(valor);}

this is from my code-if (req.indexOf(“/getTemp”)!=-1){client.println(temp);Serial.println(temp);}

I can’t understand why its not working please help.

@Sneha_JangidTry

if(req.indexOf(“getTemp”)!=-1)

@Juan_Antonio did but same error

@ABG checked but not working

#include

const char* ssid = “XXXXXXX”;const char* password = “XXXXXXXXXXXX”;

String temperature = “34”;

WiFiServer server(80);

void setup() {Serial.begin(115200);

// Conecta a la red wifi.Serial.println();Serial.print(“Conectando con “);Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(“.”);}Serial.println(“Conectado con WiFi.”);

// Inicio del Servidor web.server.begin();Serial.println(“Servidor web iniciado.”);

// Esta es la IPSerial.print(“Esta es la IP para conectar: “);Serial.print(“http://”);Serial.print(WiFi.localIP());}

void loop() {// Consulta si se ha conectado algún cliente.WiFiClient client = server.available();if (!client) {return;}

Serial.print(“Nuevo cliente: “);Serial.println(client.remoteIP());

// Espera hasta que el cliente envíe datos.while(!client.available()){ delay(1); }

/////////////////////////////////////////////////////// Lee la información enviada por el cliente.String req = client.readStringUntil(‘\r’);Serial.println(req);

// Realiza la petición del cliente.if (req.indexOf(“consulta”) != -1){temperature = String(random(1,100));Serial.println(temperature);delay(10);}

//////////////////////////////////////////////// Página WEB. ////////////////////////////client.println(“HTTP/1.1 200 OK”);client.println(“Content-Type: text/html”);client.println(“”); // Importante.

client.println(temperature);

Serial.print(“Cliente desconectado: “);Serial.println(client.remoteIP());// client.flush();}

Here with a potentiometer:http://kio4.com/arduino/347B_esp8266_AI2_Potenciometro.htm

@Sneha_Jangid did it work ?

Hello friends,

1.- Send message and view it on an LCD screen.

1.- You write a message in TexBox1 and it is sent by WiFi to ESP8266, that message is shown on the LCD screen.2.- If you write on5, off5, on6, off6, LEDs 5 or 6 turn on/off.


``` // Juan A. Villalpando. // KIO4.COM // Send a message // from App Inventor #include

const char* ssid = "Name_Net_WiFi"; const char* password = "Password_WiFi"; // Static IP. IPAddress local_IP(192, 168, 1, 12); IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 255, 0); #define LED5 D5 // LED in pin 5 #define LED6 D6 // LED in pin 6 #include int columns = 16; int rows = 2; LiquidCrystal_I2C lcd(0x27, columns, rows); // LiquidCrystal_I2C lcd(0x3F, columns, rows); WiFiServer server(80); void setup() { Serial.begin(115200); pinMode(LED5, OUTPUT); pinMode(LED6, OUTPUT); lcd.init(); lcd.backlight(); // Set Static IP. WiFi.config(local_IP, gateway, subnet); // Connection to WiFi Serial.println(); Serial.print("Connecting with "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("Connected with WiFi."); // Start WebServer. server.begin(); Serial.println("WebServer started."); // This is IP of WebServer Serial.print("IP of WebServer: "); Serial.print("http://"); Serial.print(WiFi.localIP()); } void loop() { // Check if a client has connected. WiFiClient client = server.available(); if (!client) { return; } Serial.print("New client: "); Serial.println(client.remoteIP()); // Wait for the client to send data. while(!client.available()){ delay(1); } ///////////////////////////////////////////////////// // Read information of client. String req = client.readStringUntil('\r'); Serial.println(req); req.replace("+", " "); // Spaces without + req.replace(" HTTP/1.1", ""); // this delete HTTP/1.1 req.replace("GET /", ""); // this delete GET / lcd.clear(); // Borra pantalla. lcd.setCursor(0, 0); // Start cursor lcd.print("Mensaje"); lcd.setCursor(0,1); // Next row. lcd.print(req); // Make the customer's request. if (req.indexOf("on5") != -1) {digitalWrite(LED5, HIGH);} if (req.indexOf("off5") != -1){digitalWrite(LED5, LOW);} if (req.indexOf("on6") != -1) {digitalWrite(LED6, HIGH);} if (req.indexOf("off6") != -1){digitalWrite(LED6, LOW);} ////////////////////////////////////////////// // Página WEB. //////////////////////////// client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); // Important. Serial.print("Client disconnected: "); Serial.println(client.remoteIP()); client.flush(); client.stop(); } ```

  • In this code I use static IP.

  • Utilizo:

Regards,http://kio4.com/arduino/345_esp8266_AI2_LCD.htm

With NodeMcu:https://groups.google.com/forum/#!searchin/mitappinventortest/esp8266$20sends$20message|sort:date/mitappinventortest/t9DJ8U0KE6Y/18orp_xgBwAJ

Hey guys, I need to create an app by app inventor. It should be able to receive strings from Arduino via ESP8266.
I need an app inventor extension of the WiFi module.
I have seen so many module of Bluetooth or wifi module that can only send messages to Arduino.

So I need an extension that can receive data from Arduino via WiFi module.
Any idea? Thank you very much!

My extension works with TCP/IP. I can’t tell if it works with your WIFI card.
If you are going to connect to the Arduino from time to time, and use your phone for other tasks as well, then I think it’s better to let the Arduino be the server and your phone be a client. Then use polling as suggested before. This will be easier to implement.

Dear @Junrong_Huang,
I’m struggling since a couple of days with a problem similar to yours.
Behind the scene: => I wanted to make something like a home automation/antitheft system on my own.
I have then bought 3 NODEMCU8266 and some PIR sensors (Arduino compatibles).
The aim is to have a PAD (or phone) with an AI2 application to behave as the “controller” of the various NODEMCU’s in a totally local WiFi network, without any router (therefore no remote control via WEB).
.I’ve then decided to have a structure like:
1 NODEMCU (#1) acting as a soft Access Point in Server configuration. It acquires the PIR and drives two relays (when it receives the command by each of the other two NODEMCU’s).
2 NODEMCU’s (#2 and #3) acting as Stations (STA) in Client configuration, Every 5 seconds they send a relay ON/OFF request to the AP, just to see whether they are alive and connected.
1 PAD (Lenovo M8 Android 9) in Client configuration, acting as User Interface or Controller. It can send a relay ON/OFF command by hitting on two buttons (of the PAD screen). On the screen are also shown the HTML strings as they come from the AP. No extensions used, just blocks.
With my configuration, in which the PAD (phone) is a client, I found that the “easy” way to receive messages from the server, is to set a periodical clock (i.e. 250 ms) on the PAD, so the PAD can ask the server if there are any news (like it was sent unsolicited by the server: see [(@rkl099) Rolf’s answer].
In other words, by means of a 250 ms clock, the PAD (phone) asks the server to respond with some updates. If the server has some news to transmit to the client, it sends this new information, else, it sends the string “nothing to say”. As soon as the string is received by the PAD, the app parses it, and decides consequently (i.e. “nothing to say” = no actions ).
The .aia and the .ino files that you find attached are really far from being “ready to use” but, anyway, they are working in my configuration, as described above and I guess they can be a good base that you can elaborate to get your needs Auto_Home_04 _1.aia (103.0 KB) ESP_8266_base.ino (8.1 KB)

EDIT: removed yesterday’s Client .ino. Replaced with a commented one:

I know you are at the experimental stage but it is best to not have any unused cables near the Arduino and no cables should be near the module other than the ones connected to it. ESP-01S ESP8266 Module should work just fine, make sure it’s in good condition -check for hairline cracks with a magnifying glass and test the cabling for continuity. Need to be sure you start with a good base

I saw several projects that integrate APP Inventor with Arduino,
unfortunately I only found projects where data from arduino sensors
are replicated on the mobile screen or actuators are turned on or off.

Would anyone know of an example where the mobile APP can pass a value
to an Arduino variable?

For example, turning on a lamp if the level of the photoresistor is
less than x, and the value of x is can be changed on the application
screen (typing the value or using a slider, etc.)

If you would like to have full control over ESP, send and read data. Also be able to control ESP remotely, e.g. from work, read about the MQTT protocol. There is a nice MQTT extension for appinvwntor and lots of libraries for arduino. There are also many free mqtt brokers (servers) available. You can also create your own server, e.g. using the android application. This way you can also control esp from e.g. the google assistant.

Here is English translated Wifi Led control project, But I am still trying to write correct code for Nodemcu
Also I will have to findout How to upload LEDWifi_ESP_BIJ_1Aia Project file here for community

Điều khiển thiết bị bằng MIT App Inventor sử dụng ESP8266
Điều khiển thiết bị bằng MIT App Inventor sử dụng ESP8266

Uploading Code

You should see a window similar to the preceding Figure, follow these instructions to upload a Lua file:

  1. Connect your FTDI programmer to your computer
  2. Select your FTDI programmer port
  3. Press Open/Close
  4. Select NodeMCU+MicroPtyhon tab
  5. Create a new file called init.lua
  6. Press Save to ESP

Everything that you need to worry about or change is highlighted in red box.

First, watch the video demonstration

To learn more about the ESP8266 use the following tutorials as a reference:

  • Getting started with the ESP8266
  • ESP8266 web server with NodeMCU
  • Flashing NodeMCU firmware
  • ESP8266 troubleshooting guide

If you like the ESP and you want to do more projects you can download my eBook Home Automation using ESP8266 here.

Let’s get started!

MQTT Android Application | MIT app inventor
MQTT Android Application | MIT app inventor

Parts List

Here’s the hardware that you need to complete this project:

  • 1x ESP8266 -read Best ESP8266 Wi-Fi Developmento Boards
  • 1x FTDI programmer
  • 2x LEDs
  • 2x 220Ω Resistors
  • 1x Breadboard
  • 1x Android Phone – example OnePlus 5 (read review)

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Other boards[edit]

The reason for the popularity of many of these boards over the earlier ESP-xx modules is the inclusion of an on-board USB-to-UART bridge (like the Silicon Labs’ CP2102 or the WCH CH340G) and a Micro-USB connector, coupled with a 3.3-volt regulator to provide both power to the board and connectivity to the host (software development) computer – commonly referred to as the console, making it an easy development platform. With earlier ESP-xx modules, these two items (the USB-to-serial adapter and the regulator) had to be purchased separately and be wired into the ESP-xx circuit. Modern ESP8266 boards like the NodeMCU are easier to work with and offer more GPIO pins. Most of the boards listed here are based on the ESP-12E module, but new modules are being introduced seemingly every few months.

Name Active pins Pitch Form factor LEDs Antenna Shielded Dimensions (mm) Notes
Bolt IoT 14 0.1 in 2×14 DIL Yes PCB trace Yes 30 × 40 Comes with an onboard SD card and features like Lib-Discovery and Fail Safe Mode. Has its own cloud for IoT.
Olimex MOD-WIFI-ESP8266[25] 0.1 in UEXT module Yes PCB trace No Only RX/TX are connected to UEXT connector.
Olimex MOD-WIFI-ESP8266-DEV[26] 20 0.1 in 2×11 DIL + castellated Yes PCB trace No 33 × 23 All available GPIO pins are connected, also has pads for soldering UEXT connector (with RX/TX and SDA/SCL signals).
NodeMCU DEVKIT 14 0.1 in 2×15 DIL Yes PCB trace Yes 49 × 24.5 Uses the ESP-12 module; includes USB to serial interface.
Adafruit Huzzah ESP8266 breakout[27] 14 0.1 in 2×10 DIL Yes PCB trace Yes 25 × 38 Uses the ESP-12 module.
SparkFun ESP8266 Thing[28] WRL-13231 12 0.1 in 2×10 DIL Yes PCB trace + U.FL socket No 58 × 26 FTDI serial header, Micro-USB socket for power, includes Li-ion battery charger.
KNEWRON Technologies smartWIFI[29] 12 0.1 in 2×20 DIL Yes 1 RGB PCB trace Yes 25.4 × 50.8 CP2102 USB bridge, includes battery charger, micro-USB socket for power and battery charging, 1 RGB LED and USER / Reflash button.
ArduCAM ESP8266 UNO[30] 12+ 0.1 in Arduino Uno Yes PCB trace Yes 53.4 × 68.6 Uses the AI Thinker’s ESP8266MOD module and features Micro-USB port, Battery pins, Camera pins and uSD card all on the same board. Fully compatible with Arduino Uno shields.
DoIT ESPduino[31] 12 0.1 in Arduino Uno Yes PCB trace Yes 53.4 × 68.6 Uses the ESP-WROOM-02 (ESP-13) module and USB Type B port. Fully compatible with Arduino Uno shields.
WeatherPlus – SwitchDoc Labs[32] 26+Grove 0.1 in Custom Yes PCB trace Yes 86.0 × 50.0 Uses the AI Thinker Model ESP8266MOD (ESP-13) module and FTDI for Programming and Mini-USB port for power. Fully compatible with Adafruit Huzzah software. Includes BMP280 Barometer, ADS1115 and Grove I2C connectors. Plugs for Anemometer/Wind Vane/Rain Bucket.
WeMos[33] D1[34] 12 0.1 in Arduino Uno Yes PCB trace Yes 53.4 × 68.6 Uses the ESP-12F module and Micro-USB socket. Discontinued in favor of WeMos D1 R2.
WeMos[33] D1 R2[35] 12 0.1 in Arduino Uno Yes PCB trace Yes 53.4 × 68.6 Uses ESP-12F module and has Micro-USB socket.
WeMos[33] D1 mini[36] 12 0.1 in 2×8 DIL Yes PCB trace Yes 25.6 × 34.2 Uses ESP-12S module and has Micro-USB socket.
WeMos[33] D1 mini Lite[37] 12 0.1 in 2×8 DIL Yes PCB trace Yes 25.6 × 34.2 Based on the ESP8285, an ESP8266 with 1 MiB flash built-in; has Micro-USB socket.
WeMos[33] D1 mini Pro[38] 12 0.1 in 2×8 DIL Yes Ceramic and U.FL socket Yes 25.6 × 34.2 Uses ESP8266EX chip; has Micro-USB socket, U.FL antenna connector, and 16 MiB flash.
ESPert ESPresso Lite[39] 16 0.1 in 2×8 DIL Yes PCB trace Yes 26.5 × 57.6 Uses the ESP-WROOM-02 module. Produced in limited quantity as beta version.
ESPert ESPresso Lite V2.0[40] 24 0.1 in 2×10 DIL Yes PCB trace Yes 28 × 61 Improved version of ESPresso Lite.
In-Circuit ESP-ADC[41] 18 0.1 in 2×9 DIL No U.FL socket Yes 22.9 × 14.9 Uses ESP8266EX chip.
Watterott ESP-WROOM02-Breakout[42] 14 0.1 in 2×10 DIL Yes PCB trace Yes 40.64 × 27.94 Uses the Espressif ESP-WROOM-02 module.
Geek Wave Solution IOT WROOM-02 Dev. Board[43] 20 0.1 in Yes PCB trace Yes 93.80 × 80.02 Development board with Espressif ESP-WROOM-02 module and four relays.
Witty 2-piece board[44] 20 0.1 in Yes PCB trace Yes Development board with Espressif ESP8266 ESP-12E and separate board for CH340G USB interface.
Mobile App Control LED | NodeMCU | IOT | ESP8266 | ThingSpeak Server | MIT APP Inventor.
Mobile App Control LED | NodeMCU | IOT | ESP8266 | ThingSpeak Server | MIT APP Inventor.

Step 1: Add the ESP8266 Boards Manager Link to the Arduino IDE Preferences

  1. From the Menu select |File|Preferences| (Picture 1)
  2. For the “Additional Boards Manager URLs”, in the “Preferences” dialog (Picture 2) set one of the following:If you want to use the stable release of the ESP8266 libraries:http://arduino.esp8266.com/stable/package_esp8266com_index.json
  3. If you want to use the latest staging version of the ESP8266 libraries: http://arduino.esp8266.com/staging/package_esp8266com_index.json
  4. Click the OK button.

Uploading Code

You should see a window similar to the preceding Figure, follow these instructions to upload a Lua file:

  1. Connect your FTDI programmer to your computer
  2. Select your FTDI programmer port
  3. Press Open/Close
  4. Select NodeMCU+MicroPtyhon tab
  5. Create a new file called init.lua
  6. Press Save to ESP

Everything that you need to worry about or change is highlighted in red box.

How to Program the ESP8266 ESP01 Wi-Fi Relay Module | RemoteXY | FLProg
How to Program the ESP8266 ESP01 Wi-Fi Relay Module | RemoteXY | FLProg

Pinout of ESP-01[edit]

The pinout is as follows for the common ESP-01 module:

  1. GND, Ground (0 V)
  2. GPIO 2, General-purpose input/output No. 2
  3. GPIO 0, General-purpose input/output No. 0
  4. RX, Receive data in, also GPIO3
  5. VCC, Voltage (+3.3 V; can handle up to 3.6 V)
  6. RST, Reset
  7. CH_PD, Chip power-down
  8. TX, Transmit data out, also GPIO1

Features[edit]

  • Processor: L106 32-bit RISC microprocessor core based on the Tensilica Diamond Standard 106Micro running at 80 or 160 MHz[5]
  • Memory:[6]

    • 32 KiB instruction RAM
    • 32 KiB instruction cache RAM
    • 80 KiB user-data RAM
    • 16 KiB ETS system-data RAM
  • External QSPI flash: up to 16 MiB is supported (512 KiB to 4 MiB typically included)
  • IEEE 802.11 b/g/n Wi-Fi

    • Integrated TR switch, balun, LNA, power amplifier and matching network
    • WEP or WPA/WPA2 authentication, or open networks
  • 17 GPIO pins[7]
  • Serial Peripheral Interface Bus (SPI)
  • I²C (software implementation)[8]
  • I²S interfaces with DMA (sharing pins with GPIO)
  • UART on dedicated pins, plus a transmit-only UART can be enabled on GPIO2
  • 10-bit ADC (successive approximation ADC)
how to make Arduino based Joystick Controlled Robot | how to build Android App on MIT App inventor
how to make Arduino based Joystick Controlled Robot | how to build Android App on MIT App inventor

SDKs[edit]

In October 2014, Espressif Systems released a software development kit (SDK) for programming the chip directly, which removed the need for a separate microcontroller.[9] Since then, there have been many official SDK releases from Espressif; Espressif maintains two versions of the SDK — one that is based on FreeRTOS and the other based on callbacks.[10]

An alternative to Espressif’s official SDK is the open-source ESP-Open-SDK[11] that is based on the GNU Compiler Collection (GCC) toolchain, maintained by Max Filippov.[12] Another alternative is the “Unofficial Development Kit” by Mikhail Grigorev.[13][14]

Other SDKs, mostly open-source, include:

  • Arduino — A C++-based firmware. With this core, the ESP8266 CPU and its Wi-Fi components can be programmed like any other Arduino device. The ESP8266 Arduino Core is available through GitHub.
  • ESP8266 BASIC — An open-source BASIC-like interpreter specifically tailored for the Internet of Things (IoT). Self-hosting browser-based development environment.
  • ESP Easy — Developed by home automation enthusiasts.
  • ESPHome — ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through home automation systems.
  • Tasmota – open-source firmware, for home automation.
  • ESP-Open-RTOS — Open-source FreeRTOS-based ESP8266 software framework.
  • ESP-Open-SDK — Free and open (as much as possible) integrated SDK for ESP8266/ESP8285 chips.
  • Espruino — An actively maintained JavaScript SDK and firmware, closely emulating Node.js. Supports a few MCUs, including the ESP8266.
  • ESPurna — Open-source ESP8285/ESP8266 firmware.
  • Forthright — Port of Jones Forth to the ESP8266 microcontroller.
  • MicroPython — A port of MicroPython (an implementation of Python for embedded devices) to the ESP8266 platform.
  • Moddable SDK — includes JavaScript language and library support for the ESP8266
  • Mongoose OS — An open-source operating system for connected products. Supports ESP8266 and ESP32. Develop in C or JavaScript.[15]
  • NodeMCU — A Lua-based firmware.
  • PlatformIO — A cross-platform IDE and unified debugger, which sits on top of Arduino code and libraries.
  • Punyforth — Forth-inspired programming language for the ESP8266.
  • Sming — An actively developed asynchronous C/C++ framework with superb performance and multiple network features.
  • uLisp — A version of the Lisp programming language specifically designed to run on processors with a limited amount of RAM.
  • ZBasic for ESP8266 — A subset of Microsoft’s widely-used Visual Basic 6, which has been adapted as a control language for the ZX microcontroller family and the ESP8266.
  • Zerynth — IoT framework for programming ESP8266[16] and other microcontrollers in Python.
  • IOTBAH – is An operating system (OS) for Espressif ESP8266
  • EspOS Webserver, easy IoT solution.

Code

#include

const char* ssid = “Phamson”; const char* password = “phamtheson”; WiFiServer server(80); void setup() { Serial.begin(115200); //Default Baud Rate for NodeMCU delay(10); pinMode(2, OUTPUT); // Connect Relay to NodeMCU’s D4 Pin digitalWrite(2, 0); // Connect to WiFi network Serial.println(); Serial.println(); Serial.print(“Connecting to “); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print(“.”); } Serial.println(“”); Serial.println(“WiFi connected”); // Start the server server.begin(); Serial.println(“Server started”); // Print the IP address Serial.println(WiFi.localIP()); } void loop() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Wait until the client sends some data Serial.println(“new client”); while(!client.available()){ delay(1); } String req = client.readStringUntil(‘\r’); Serial.println(req); client.flush(); int val; if (req.indexOf(“/gpio/0”) != -1) val = 0; else if (req.indexOf(“/gpio/1”) != -1) val = 1; else { Serial.println(“invalid request”); client.stop(); return; } // Set GPIO2 according to the request digitalWrite(2, val); client.flush(); String s = “HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n

\r\n

\r\nGPIO is now “; s += (val)?”high”:”low”; s += ”

“; }

In this project, you’re going to build an Android app using the MIT App Inventor software that allows you to control the ESP8266 GPIOs.

How to setup & test ESP8266 with an Arduino UNO
How to setup & test ESP8266 with an Arduino UNO

Taking It Further

This is a basic example that shows you how easy it is to integrate an Android app with the ESP8266. You can take this example and modify it.

You could add multiple screens to the app, so you can other ESPs or add buttons to control more GPIOs.

Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

I am trying to use the app inventor with an iPhone and and Arduino. I used code I learned in a workshop for Android phones and it doesn’t work with the iPhone.

A recent post gave this as an answer to the same question, but I don’t understand how to use the answer: “Use ElementsFromString property in the designer rather than the ListData property.”

Are there any tutorials you can suggest to help me use it with the iPhone and Arduino?

Welcome Elene.

The Android users use Bluetooth to communicate with an Arduino . I don’t think an ios version of App Inventor can do that yet. Android users use extensions to accomplish that goal. The ios version of App Inventor currently cannot use extensions.

Some users use the Web component to talk to their arduinos. See Search results for ‘arduino Web ‘ – MIT App Inventor Community.

Is this using App Inventor Blocks?

Ultimately it will depend on the Arduino you are using. At the moment, App Inventor for iOS does not have the BluetoothClient, BluetoothLE (currently an extension), or Serial components implemented, which are common ways to connect to Arduinos. If you have an Arduino Yun (or another Wifi shield), you should be able to use the Web component to communicate with it.

Of the three unavailable connection methods, BluetoothLE is the mostly likely to be implemented in the short term as we are producing new curricula around BluetoothLE and the micro:bit, and we want to ensure that this will be a good experience for both Android and iOS users.

1 Like

Yes. They used the app inventor with the HM-10 Bluetooth module, the Arduino Uno, and an android phone.

Does this mean that the App inventor will work with the HM-10 Bluetooth module, Arduino uno and iPhones in the future?

I would need to see an example project to better assess that.

Step 3: Test the ESP8266 With Arduino Project

  1. Connect with USB cable your ESP8266 module to the computer.
  2. You can test with an empty sketch or a small sketch such as Blink.
  3. In the Arduino IDE from the menu select the type of the board type that you have. In my case this is “NodeMCU 0.9 (ESP-12 Module)” (Picture 1)
  4. Also from the Arduino IDE menu, select the Serial Port to which the module is connected (Picture 2)
  5. Click on the Upload button to compile and upload the sketch (Picture 3)

Congratulations! Your Arduino IDE is ready to support ESP8266 modules.

In the following Instructables I will show you how you can program the ESP8266 with Visuino and how you can connect multiple ESP8266 modules together to create IoT projects.

Participated in the Arduino All The Things! Contest

ESP8266

ESP8266-IC

Manufacturer Espressif Systems
Type 32-bit microcontroller
CPU Tensilica Diamond Standard 106Micro (aka. L106) @ 80 MHz (default) or 160 MHz
Memory 32 KiB instruction, 80 KiB user data
Input 17 GPIO pins
Power 3.3 V DC
Successor ESP32

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

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.[2] The very low price and the fact that there were very few external components on the module, which suggested that it could eventually be very inexpensive in volume, attracted many hackers to explore the module, the chip, and the software on it, as well as to translate the Chinese documentation.[3]

The ESP8285 is a similar chip with a built-in 1 MiB flash memory, allowing the design of single-chip devices capable of connecting via Wi-Fi.[4]

These microcontroller chips have been succeeded by the ESP32 family of devices.

Getting Started with Adafruit IO: Control Led with Esp8266 NodeMCU
Getting Started with Adafruit IO: Control Led with Esp8266 NodeMCU

Schematics (3.3V FTDI Programmer)

The schematics for this project are very straight forward. You only need to establish a serial communication between your FTDI programmer and your ESP8266. You can buy one FTDI programmer on eBay.

Wiring:

  • RX -> TX
  • TX -> RX
  • CH_PD -> 3.3V
  • VCC -> 3.3V
  • GND -> GND

Code

Upload the following code into your ESP8266 using the preceding software. Your file should be named “init.lua“.

Don’t forget to add your network name (SSID) and password to the script below.


-- Rui Santos -- Complete project details at https://randomnerdtutorials.com wifi.setmode(wifi.STATION) wifi.sta.config("YOUR_NETWORK_NAME","YOUR_NETWORK_PASSWORD") print(wifi.sta.getip()) led1 = 3 led2 = 4 gpio.mode(led1, gpio.OUTPUT) gpio.mode(led2, gpio.OUTPUT) srv=net.createServer(net.TCP) srv:listen(80,function(conn) conn:on("receive", function(client,request) local buf = ""; buf = buf.."HTTP/1.1 200 OK\n\n" local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP"); if(method == nil)then _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); end local _GET = {} if (vars ~= nil)then for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do _GET[k] = v end end if(_GET.pin == "ON1")then gpio.write(led1, gpio.HIGH); elseif(_GET.pin == "OFF1")then gpio.write(led1, gpio.LOW); elseif(_GET.pin == "ON2")then gpio.write(led2, gpio.HIGH); elseif(_GET.pin == "OFF2")then gpio.write(led2, gpio.LOW); end client:send(buf); client:close(); collectgarbage(); end) end)

Adafruit io kullanımı w/ESP8266 | Arduino projesi nasıl geliştirilir?
Adafruit io kullanımı w/ESP8266 | Arduino projesi nasıl geliştirilir?

Installing the Android App

Follow these instructions to install the default app that I’ve created:

  1. Click here to download the .apk file
  2. Unzip the folder
  3. Move the .apk file to your Android phone
  4. Run the .apk file to install the app

Here’s how the ESP8266 Controller app looks when you to open it.

It’s very easy to configure. Click the button “Set IP Address” on the bottom of the screen and type your IP address (in my case 192.168.1.95).

You’re all set!

Now you can turn the GPIOs high and low with your smartphone. Go to the top of this page to see a video demonstration of this project.

Downloading ESPlorer IDE

I recommend using the ESPlorer IDE which is a program created by 4refr0nt to send commands to your ESP8266.

Follow these instructions to download and install ESPlorer IDE:

  1. Click here to download ESPlorer
  2. Unzip that folder
  3. Go to the main folder
  4. Run “ESPlorer.jar” file
  5. Open the ESPlorer IDE
Chế bộ điều khiển không giới hạn khoảng cách ESP8266
Chế bộ điều khiển không giới hạn khoảng cách ESP8266

Downloading ESPlorer IDE

I recommend using the ESPlorer IDE which is a program created by 4refr0nt to send commands to your ESP8266.

Follow these instructions to download and install ESPlorer IDE:

  1. Click here to download ESPlorer
  2. Unzip that folder
  3. Go to the main folder
  4. Run “ESPlorer.jar” file
  5. Open the ESPlorer IDE

Schematics (3.3V FTDI Programmer)

The schematics for this project are very straight forward. You only need to establish a serial communication between your FTDI programmer and your ESP8266. You can buy one FTDI programmer on eBay.

Wiring:

  • RX -> TX
  • TX -> RX
  • CH_PD -> 3.3V
  • VCC -> 3.3V
  • GND -> GND
How to make a Android Application control Robot Camera | MIT App inventor based Android Application
How to make a Android Application control Robot Camera | MIT App inventor based Android Application

Sơ đồ đấu nối

Các linh kiện cần thiết cho dự án

Tên linh kiện Số lượng Shopee
NodeMCU ESP8266 Mua ngay
Dây cắm (Cái – Cái) Mua ngay
Module Relay 5V Mua ngay

Tạo App Android bằng MIT APP INVENTOR

Để có thể tạo một App Android bằng MIT app inventor chúng truy cập vào link để tạo dự án nhé: http://appinventor.mit.edu

Bước đầu tiên các bạn Click vào Projects chọn “Start new project” để tạo một dự án mới.

Tiếp theo chúng ta cần đặt tên cho dự án.

Ở bên tay trái màn mình các bạn, chúng ta Click vào Button dùng để bật tắt thiết bị. Ở đây mình sẽ chọn 2 nút và đặt là “ON” và “OFF”.

Để có thể chỉnh sửa các thông số của Button các bạn Click vào và nó sẽ xổ ra các trường thông tin. Ở đây các bạn có thể đặt lại tên cho Button ở phần Text …

Tiếp theo, các bạn chọn mục Connectivity và cho Web và kéo thả vào Viewer nhé.

Sau khi đã cấu hình cho các Button và Web ta chọn vào Block để chuyển qua lập trình kéo thả Block.

Click vào “Button 1” chọn phần mà mình đã khoanh đỏ và kéo chúng vào vùng lập trình.

Tiếp tục, ta chọn “Web1” và kéo Block đã được đánh dấu. Ở phần này chúng ta sẽ cấu hình địa chỉ IP Web.

Chọn mục “Text” kéo block được khoanh đỏ vào vùng lập trình.

Tiếp theo ở mục Web1 chọn Block “Call Web.Get”.

Để biết được địa chỉ IP của NodeMCU ESP8266 ta cần nạp Code và bật Monitor lên xem nhé. Code mình để cuối bài viết các bạn tải về và

thực hiện nhé. Ở đây địa chỉ IP của mình là: 192.168.88.106

  • http://192.168.88.106/gpio/1
  • http://192.168.88.106/gpio/0

Các bạn kéo thả các Block lại với nhau giống như trên màn hình nhé.

Để có thể tải dự án về điện thoại, các bạn vào mục Build chọn App (project QR code for apk).

Quét mã QR code xuất hiện trên màn hình. Và các bạn tiến hành cài đặt App vào điện thoại nhé.

Như vậy là đã xong các bạn có thể điều khiển bật tắt thiết bị trên App điện thoại rồi.

ESP8266 Web Server APP Home Automation | Build Application
ESP8266 Web Server APP Home Automation | Build Application

Ai-Thinker modules[edit]

This is the first series of modules made with the ESP8266 by the third-party manufacturer Ai-Thinker and remains the most widely available.[20] They are collectively referred to as “ESP-xx modules”. To form a workable development system, they require additional components, especially a serial TTL-to-USB adapter (sometimes called a USB-to-UART bridge) and an external 3.3 volt power supply. Novice ESP8266 developers are encouraged to consider larger ESP8266 Wi-Fi development boards like the NodeMCU which includes the USB-to-UART bridge and a Micro-USB connector coupled with a 3.3 volt power regulator already built into the board. When project development is complete, those components are not needed and these cheaper ESP-xx modules are a lower power, smaller footprint option for production runs.

In the Notes column, Flash memory sizes apply to the given module and all those below it in the table. Exceptions which apply to a single module are shown in ().

Name Active pins Pitch Form factor LEDs Antenna Shielded Dimensions (mm) Notes
ESP-01 6[21] 0.1 in 2×4 DIL Yes PCB trace No 14.3 × 24.8 512 KiB Flash and blue PCB from a generic manufacturer. 1 MiB Flash, AI-Cloud and black PCB from AI-Thinker.
ESP-01S 6[22] 0.1 in 2×4 DIL Yes PCB trace No 14.4 × 24.7 1 MiB Flash
ESP-01M 16 1.6 mm 2×9 edge connector No PCB trace Yes 18.0 × 18.0 Uses ESP8285 (1 MiB built-in flash).
ESP-02 0.1 in 2×4 castellated No U.FL socket No 14.2 × 14.2
ESP-03 10 2 mm 2×7 castellated No Ceramic No 17.3 × 12.1
ESP-04 10 2 mm 2×4 castellated No None No 14.7 × 12.1
ESP-05 0.1 in 1×5 SIL No U.FL socket No 14.2 × 14.2
ESP-06 11 various 4×3 dice No None Yes 14.2 × 14.7 Not FCC approved.
ESP-07 14 2 mm 2×8 pinhole Yes Ceramic + U.FL socket Yes 20.0 × 16.0 Not FCC approved.
ESP-07S 14 2 mm 2×8 pinhole No U.FL socket Yes 17.0 × 16.0 FCC and CE approved.
ESP-08 10 2 mm 2×7 castellated No None Yes 17.0 × 16.0 Not FCC approved.
ESP-09 10 various 4×3 dice No None No 10.0 × 10.0
ESP-10 2 mm 1×5 castellated No None No 14.2 × 10.0
ESP-11 1.27 mm 1×8 pinhole No Ceramic No 17.3 × 12.1
ESP-12 14 2 mm 2×8 castellated Yes PCB trace Yes 24.0 × 16.0 FCC and CE approved.[23]
ESP-12E 20 2 mm 2×8 castellated Yes PCB trace Yes 24.0 × 16.0 4 MiB flash.
ESP-12F 20 2 mm 2×8 castellated Yes PCB trace Yes 24.0 × 16.0 FCC and CE approved. Improved antenna performance.
ESP-12S 14 2 mm 2×8 castellated Yes PCB trace Yes 24.0 × 16.0 FCC approved.[24]
ESP-13 16 1.5 mm 2×9 castellated No PCB trace Yes W18.0 × L20.0 Marked as “FCC”. Shielded module is placed sideways, as compared to the ESP-12 modules.
ESP-14 22 2 mm 2×8 castellated +6 Yes PCB trace Yes 24.3 × 16.2 Mostly advertised with “AI Cloud Inside”.

Keywords searched by users: esp8266 arduino app inventor

Send Text From Arduino To Mit App Using Esp8266 Wifi - Mit App Inventor  Help - Mit App Inventor Community
Send Text From Arduino To Mit App Using Esp8266 Wifi – Mit App Inventor Help – Mit App Inventor Community
Mai And Esp8266 Coupled To Arduino Ide - Mit App Inventor Help - Mit App  Inventor Community
Mai And Esp8266 Coupled To Arduino Ide – Mit App Inventor Help – Mit App Inventor Community
Receiving Data From Mcu (Esp8266) And Displaying On App Over Local Network  Wifi - Mit App Inventor Help - Mit App Inventor Community
Receiving Data From Mcu (Esp8266) And Displaying On App Over Local Network Wifi – Mit App Inventor Help – Mit App Inventor Community
Control Esp8266 From Anywhere Using Android App And Mqtt - Hackster.Io
Control Esp8266 From Anywhere Using Android App And Mqtt – Hackster.Io
Điều Khiển Thiết Bị Bằng Mit App Inventor Sử Dụng Nodemcu Esp8266 | Arduino  Kit
Điều Khiển Thiết Bị Bằng Mit App Inventor Sử Dụng Nodemcu Esp8266 | Arduino Kit
Mit App Inventor 2 Meets Esp8266! #Kidserie-03 - Youtube
Mit App Inventor 2 Meets Esp8266! #Kidserie-03 – Youtube
Arduino + Esp8266 Remote Control Led Using An Android App With Camera Live  View | Petestechprojects
Arduino + Esp8266 Remote Control Led Using An Android App With Camera Live View | Petestechprojects
Send String From Mit App Text Box To Esp8266 And Arduinomega - Internet Of  Things - Mit App Inventor Community
Send String From Mit App Text Box To Esp8266 And Arduinomega – Internet Of Things – Mit App Inventor Community
Nodemcu Esp8266: Home Automation System With Sensors And Mit App Inventor 2  : 17 Steps - Instructables
Nodemcu Esp8266: Home Automation System With Sensors And Mit App Inventor 2 : 17 Steps – Instructables
Esp8266 Android App (Created With Mit App Inventor) - Demo - Youtube
Esp8266 Android App (Created With Mit App Inventor) – Demo – Youtube
Using Esp8266 And Mit App Inventor To Control A Relay | Iot | Iot, Inventor,  Relay
Using Esp8266 And Mit App Inventor To Control A Relay | Iot | Iot, Inventor, Relay
Connecting Esp8266 (Nodemcu) With Android App (Mit App Inventor) Especially  The Longitude And Latitude From A Gps Module - Mit App Inventor Help - Mit  App Inventor Community
Connecting Esp8266 (Nodemcu) With Android App (Mit App Inventor) Especially The Longitude And Latitude From A Gps Module – Mit App Inventor Help – Mit App Inventor Community
How To Program Esp8266 | How To Control Gpio Pins Of Esp8266 Using Mit App  Inventor ? - Youtube
How To Program Esp8266 | How To Control Gpio Pins Of Esp8266 Using Mit App Inventor ? – Youtube
Điều Khiển Thiết Bị Bằng Mit App Inventor Sử Dụng Nodemcu Esp8266 | Arduino  Kit
Điều Khiển Thiết Bị Bằng Mit App Inventor Sử Dụng Nodemcu Esp8266 | Arduino Kit
Esp8266 Android Mit App Inventor Tutorial | Random Nerd Tutorials
Esp8266 Android Mit App Inventor Tutorial | Random Nerd Tutorials
Nodemcu Esp8266: Home Automation System With Sensors And Mit App Inventor 2  : 17 Steps - Instructables
Nodemcu Esp8266: Home Automation System With Sensors And Mit App Inventor 2 : 17 Steps – Instructables
Examples With The Esp8266-01. Wifi. Led On/Off. Arduino. Standalone. Mqtt -  Tutorials And Guides - Mit App Inventor Community
Examples With The Esp8266-01. Wifi. Led On/Off. Arduino. Standalone. Mqtt – Tutorials And Guides – Mit App Inventor Community
Using Esp8266 And Mit App Inventor To Control A Relay | Iot | Relay, App,  Iot
Using Esp8266 And Mit App Inventor To Control A Relay | Iot | Relay, App, Iot
Communication With Esp8266 Server - General Discussion - Mit App Inventor  Community
Communication With Esp8266 Server – General Discussion – Mit App Inventor Community
Control Multiple Nodemcu With App-Inventor Application.
Control Multiple Nodemcu With App-Inventor Application.
Nodemcu (Esp8266) Tutorial B-23: Mqtt Control Of Esp8266 With Your Android  App - Youtube
Nodemcu (Esp8266) Tutorial B-23: Mqtt Control Of Esp8266 With Your Android App – Youtube
Send Sensor Data To Android Using Google Firebase & Esp8266
Send Sensor Data To Android Using Google Firebase & Esp8266
Nodemcu Esp8266: Home Automation System With Sensors And Mit App Inventor 2  : 17 Steps - Instructables
Nodemcu Esp8266: Home Automation System With Sensors And Mit App Inventor 2 : 17 Steps – Instructables
Wifi & Voice Controlled Home Automation Using Esp8266
Wifi & Voice Controlled Home Automation Using Esp8266

See more here: kientrucannam.vn

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *