Chuyển tới nội dung
Home » Mit App Inventor Nodemcu | Installing The Android App

Mit App Inventor Nodemcu | Installing The Android App

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

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.

This is the value of latitude and longitude in my serial Arduino.

This is my example design in Mit App inventor

This is the blocks of my design in Mit app

Gps Code:


#include

#include

static const int RXPin = 3, TXPin = 4; static const uint32_t GPSBaud = 9600; // The TinyGPS++ object TinyGPSPlus gps; // The serial connection to the GPS device SoftwareSerial ss(RXPin, TXPin); void setup(){ Serial.begin(9600); ss.begin(GPSBaud); } void loop(){ // This sketch displays information every time a new sentence is correctly encoded. while (ss.available() > 0){ gps.encode(ss.read()); if (gps.location.isUpdated()){ Serial.print("Latitude= "); Serial.print(gps.location.lat(), 6); Serial.print(" Longitude= "); Serial.println(gps.location.lng(), 6); } } }


Nodemcu Esp8266 Code


#include

#include

#include

const char* host = "GPS_NodeMCU"; const char* ssid = "GPS_BOT"; ESP8266WebServer server(80); void setup() { Serial.begin(115200); // Connecting WiFi WiFi.mode(WIFI_AP); WiFi.softAP(ssid); // Starting WEB-server server.on ( "/", HTTP_handleRoot ); server.onNotFound ( HTTP_handleRoot ); server.begin(); } void loop() { server.handleClient(); delay(50); } void HTTP_handleRoot(void) { if( server.hasArg("State") ){ Serial.println(server.arg("State")); } server.send ( 200, "text/html", "" ); }



How to send the value of latitude and longitude in my serial using Arduino to my android application created in Mit App. The connection is using nodemcu esp8266.

Is it Possible to do?. Sorry, I’m just a beginner in the Arduino

I’ve made a project with a NodeMCU to cotnrol my lamp with my phone using Appinventor. This works fine but i’d like to have the lamp sending data back to my phone (Lamp is on/off). I’ve looked online but I don’t find information on two way communication with a NodeMCU and Appinventor. Is there someone who can help me on my way?

Did you find any information how to find out if the lamp is on/off with nodeMcu using other ways (not AppInventor)? The real question being, is this possible at all, regardless of AppInventor? And if yes, how.

Unusual request, which is probably why a forum search didn’t help.
If you are controlling the Lamp with your App, surely you can simply store the status (on/off) – or are you saying the lamp can be switched on/off by something else?

When you first start controlling the lamp, let’s say it’s off. After that initial setup, your App can always know if the lamp is on or off (provided the App is the only control of the lamp). You simply store an integer in TinyDb – 1 for on, 0 for off.

The problem remains, for example: When the arduino inside the lamp is powerd on, the lamp is normally off. When I open the app, the status of the lamp is also off. There’s is no problem when I turn the lamp on using the app for the first time. But then, I pull the lamp out of the plug and replug it, the arduino is reset and the lamp is by default normally off while the status in the app will still show that the lamp is on. Note that there isn’t a way for the arduino to remember what the value of the variables were before it was shut off.
There are other situations where this can happen; second person with the app turns lamp on/off, arduino is reset…
I really need a way that the appinventor can ask the NodeMCU for a status update and change the variables in the app accordingly. But therefore, the NodeMCU needs to send data and the app needs to receive it. The app -> arduino way works perfect.

android-nodemcu-connection

This is a basic led blink example using android and esp8266 nodemcu. The main purpose of this application is how to connect android device to esp8266 nodemcu lolin. I wanted to show send and get data from android to esp8266 nodemcu.I hope it will be useful for you.

Requirements

  • Breadboard
  • LED
  • Jumper Cable
  • Android Studio
  • Arduino IDE
  • A Wifi Network

Usage

  • You must use D7 pin(in Arduino IDE Digital 13 pin)
  • Connect LED to this pin
  • Open

    nodemcu.ino

    using Arduino IDE,change

    ssid

    and

    password

    for your network
  • Then install this file to nodemcu module using usb cable
  • Open Android Studio and run the app

Important Files


  • MainActivity.java

  • activity.main

  • nodemcu.ino

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 Make a Simple App--[NodeMCU-ESP8266] -PART1
How to Make a Simple App–[NodeMCU-ESP8266] -PART1

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
MIT APP INVENTOR 2 -nodemcu wifi car control app
MIT APP INVENTOR 2 -nodemcu wifi car control app

Step 6: Software for the Microcontroller

Software for the microcontroller. Appropriate firmware is required in order to have the microcontroller working. In this case, we will use firmware to be downloaded from GITHUB: https://github.com/SUPLA/ESP8266/tree/master/socket-firmware

NOTICE! Some versions of the ESP8266-12 have the 4th and 5th GPIO ports inverted. If this is the case, you need to use firmware which will be compatible. Such a solution is available at: https://github.com/SUPLA/ESP8266/tree/master/socket-firmware-gpio54

Firmware must be writted in the following flash memory area:

eagle.flash.bin——–>0x00000

eagle.irom0text.bin—->0x40000

You must use appropriate software to have firmware loaded onto the microcontroller. I have used „NODEMCU FIRMWARE PROGRAMMER” https://github.com/nodemcu/nodemcu-flasher

32bit Version: https://github.com/nodemcu/nodemcu-flasher/tree/master/Win32/Release

64bit Version: https://github.com/nodemcu/nodemcu-flasher/tree/master/Win64/Release

You must select proper serial port where the USB-Serial converter has been plugged in and enter the other settings which can be seen on the screenshots.

If the ESP module is connected via the USB-Serial converter to the computer, and all the above steps have been performed, we can upload the software.

– Provide 12V power supply. – Press and hold the micro-switch connected to the GPIO0 port (the nearest to the powering unit), and turn the power on – keep pressing the micro-switch the whole time. – Release the micro-switch when power is on.

The RGB diode should now gently flash three colors.

We can now load firmware. Using NODEMCU click „Flash” and wait until progress bar reaches 100% for each of the two files.

NOTICE! ESP8266 module is very interference-sensitive. When it is connected to breadboard temporarily, firmware load may not be successful at the first time. Therefore, sometimes the attempt must be made few times. If the firmware was loaded successfully, we can disconnect power supply and remove the USB-Serial converter and move to the next step.

NOTICE! ESP will not start, if the converter remains on the breadboard not connected to a powered-up computer.

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

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).

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!

How to Make a Simple App The Code--[NodeMCU-ESP8266] -PART2
How to Make a Simple App The Code–[NodeMCU-ESP8266] -PART2

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 += ”

“; }

/***********
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.

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.

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.

FireBase IOT Smart Irrigation System | MIT App Inventor | NodeMCU 8266 |  DHT11 | Teach Me Something
FireBase IOT Smart Irrigation System | MIT App Inventor | NodeMCU 8266 | DHT11 | Teach Me Something

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!

Thầy Mò Đi Du Lịch gặp cảnh này
Thầy Mò Đi Du Lịch gặp cảnh này

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

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.

How to make a Nodemcu GAS LEVEL MONITORING system | Blynk with GAS LEVEL MONITORING [MQ2 sensor]
How to make a Nodemcu GAS LEVEL MONITORING system | Blynk with GAS LEVEL MONITORING [MQ2 sensor]

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

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.

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

Step 8: Smartphone Configuration

First of all, you need to download the application on your phone from AppStore or Google Play. Application is free of charge.

Install and start the application. Right after you start it, a window will appear, where all the settings from cloud.supla.org must be entered. Save the settings and the relay connected to the ESP can be operated via your Smartphone.

Participated in the Digital Life 101 Challenge

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.

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!

Building an Amazing Device with NodeMCU
Building an Amazing Device with NodeMCU

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)

Đ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.

SERVO MOTOR NODEMCU Tutorial | Blynk app with SERVO MOTOR NODEMCU Project [Code & Libraries]
SERVO MOTOR NODEMCU Tutorial | Blynk app with SERVO MOTOR NODEMCU Project [Code & Libraries]

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

Step 7: ESP Configuration

Before any steps are taken you need to subscribe to the OpenSource service project called SUPLA at https://cloud.supla.org/account/create .

You need to read location settings and password as well as server address after you log on cloud.supla.org.

Now, we can start the proper ESP configuration.

  • Turn the power supply on.
  • RGB diode should flash in blue indicating the module is in configuration mode. If the diode flash in red, you need to press and hold for at least 5 sec. the second switch (the furthest to the powering unit). Such action should put the unit in the configuration mode manually, and the diode should start flashing blue automatically.
  • You need to connect to SUPLA-ESP8266 WiFi network from any computer with WiFi card.
  • Go to http://192.168.4.1 and enter access data of your home WiFi having Internet access, password and location identifier obtained from cloud.supla.org into the form.Click „Save”.
  • Turn the power off and on back again or press switch No. 2 (the furthest to the powering unit).

* Module does not display password, which does not mean they are not saved.

**Properly saved data will be confirmed with the “Data Saved” alert.

***LAST STATE: defines status of the most recent svr1.supla.org. server connection. If the entered location data was incorrect, you can return to the configuration to read the last alert.

RDG diode will indicate module status, after restart:

  • Red light – No WiFi connection or IP address from DHCP has not been obtained
  • Blue light – steady burn: WiFi connection has been obtained. IP address has been obtained, but no connection to server (svr1.supla.org) has been set.
  • Green light – Server connection has been set. Unit is ready to work. It is worth pointing out that the relay can also be operated manually when pressing switch No. 2.
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

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.

This is what my database looks like. I want to create a button where whenever I click it, it fetches the data from the Firebase and displays it on the same screen as a table or as a list. I’ve tried and I’m stuck, I’m just new to MIT app. Thank you very much.

users >
users1> id: “34535”
name : “Alice”
time: “Saturday, June 17, 2023 15:58:40”
users2> id: “5675675675”
name : “Tina”
time: “Saturday, June 17, 2023 15:58:40”
users3> id: “78658856”
name : “Luis”
time: “Saturday, June 18, 2023 10:30:10”

This is what my database looks like. I want to create a button where whenever I click it, it fetches the data from the Firebase and displays it on the same screen as a table or as a list. I’ve tried and I’m stuck, I’m just new to MIT app. Thank you very much.

users >
users1> id: “34535”
name : “Alice”
time: “Saturday, June 17, 2023 15:58:40”
users2> id: “5675675675”
name : “Tina”
time: “Saturday, June 17, 2023 15:58:40”
users3> id: “78658856”
name : “Luis”
time: “Saturday, June 18, 2023 10:30:10”

i have 2 buttons with two counters attached to node mcu esp8266, now i just want to read the data of the counters in my app.

like if i press button 1 counter 1 increases and i press button 2 counter 2 increases and with reset button both counters gets reset. now i want that this data which is displyed on the screen should be displayed on my app that was made in mit app inventor.. is anyone know how to do it so kindly guide me in this.

like if i press button 1 counter 1 increases and i press button 2 counter 2 increases and with reset button both counters gets reset. now i want that this data which is displyed on the screen should be displayed on my app that was made in mit app inventor.. is anyone know how to do it so kindly guide me in this.

i have 2 buttons with two counters attached to node mcu esp8266, now i just want to read the data of the counters in my app.

like if i press button 1 counter 1 increases and i press button 2 counter 2 increases and with reset button both counters gets reset. now i want that this data which is displyed on the screen should be displayed on my app that was made in mit app inventor.. is anyone know how to do it so kindly guide me in this.

like if i press button 1 counter 1 increases and i press button 2 counter 2 increases and with reset button both counters gets reset. now i want that this data which is displyed on the screen should be displayed on my app that was made in mit app inventor.. is anyone know how to do it so kindly guide me in this.

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).

How to make a Weather monitoring system using the Nodemcu ESP8266 board and the New Blynk app
How to make a Weather monitoring system using the Nodemcu ESP8266 board and the New Blynk app

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)

Introduction: ESP8266 and Relay Control Using Smartphone

This instruction describes ESP8266 microcontroller start-up to control by smartphone a relay connected to the ESP. In a separate instruction I will try to present a similar case, but instead of the ESP8266 microcontroller we will use Raspberry PI version B+.

Here we go then

What will we need?

  1. A smartphone, Android (3.1.x Version or higher) or iPhone iOS 6.1 (or higher).
  2. An ESP8266 module version 512KB flash (or higher). This article will cover the ESP8266-12 version.
  3. A USB-Serial converter to program ESP. I have used the “FT232RL FTDI 3.3V 5.5V USB to TTL Serial Adapter”.
  4. PCB adapter for ESP.
  5. 3.3/5V powering unit. I have used the YwRobot module.
  6. A relay module. For this article I have used version I had close at hand i.e. YwRobot 4 relay.
  7. 12V charger.
  8. Two (2) LED diodes, one of which must be RGB.
  9. Two (2) micro-switches
  10. One (1) transistor. I have used BC547.
  11. Three (3) 100R resistors.
  12. Two (2) 10K resistors.
  13. One (1) breadboard.
  14. Connecting wiring.
  15. Piece of a thin wire.

Do not forget to connect the ESP module TXD pin to the USB-Serial converter RXD pin, and the ESP module RXD pin to the USB-Serial converter TXD pin. “IN1” must be connected to the relay module.

Let’s start…

Attachments

how to make Wireless Temperature and Humidity Monitoring System using Bluetooth | mit app inventor
how to make Wireless Temperature and Humidity Monitoring System using Bluetooth | mit app inventor

Keywords searched by users: mit app inventor nodemcu

Home Automation With Mit App Inventor And Esp8266 - Iot Projects Ideas
Home Automation With Mit App Inventor And Esp8266 – Iot Projects Ideas
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
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
Control Esp8266 From Anywhere Using Android App And Mqtt - Hackster.Io
Control Esp8266 From Anywhere Using Android App And Mqtt – Hackster.Io
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
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
Đ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 -Nodemcu Wifi Car Control App - Youtube
Mit App Inventor 2 -Nodemcu Wifi Car Control App – Youtube
Wifi & Voice Controlled Home Automation Using Esp8266
Wifi & Voice Controlled Home Automation Using Esp8266
Control An Led From A Mobile App Using Access Point Mode (Ap). - Youtube
Control An Led From A Mobile App Using Access Point Mode (Ap). – Youtube
Arduino - Connecting Esp8266 (Nodemcu) With Android App (Mit App Inventor)  Especially The Longitude And Latitude From A Gps Module - Stack Overflow
Arduino – Connecting Esp8266 (Nodemcu) With Android App (Mit App Inventor) Especially The Longitude And Latitude From A Gps Module – Stack Overflow
Esp8266 Android Mit App Inventor Tutorial | Random Nerd Tutorials
Esp8266 Android Mit App Inventor Tutorial | Random Nerd Tutorials
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
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
Home Automation With Mit App Inventor And Esp8266
Home Automation With Mit App Inventor And Esp8266
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
How to Make a Simple App--[NodeMCU-ESP8266] -PART1
How To Make A Simple App–[Nodemcu-Esp8266] -Part1 – Youtube
Esp8266 Android Mit App Inventor Tutorial | Random Nerd Tutorials
Esp8266 Android Mit App Inventor Tutorial | Random Nerd Tutorials
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
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
Đ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
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

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 *