Authorized Retailers

Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES ここでご購入を!

Introduction

In this lesson, we will demonstrate how to use the Arduino IDE to write code examples that allow two NodeMCUs to communicate using the UDP protocol.

Preparation

Hardware:

Software:

Connection

Connect each of the two NodeMCU modules to the computer via USB cable.

Upload Sketch

Open the Arduino IDE(Version1.6.4+), open the following two codes separately and upload them to the corresponding two NodeMCUs after editing them as described below.

Edit the code to fit your own WiFi settings as following operations:

1)Hotspot Configration:

// Replace with your network credentials
const char* ssid = “Your_WiFi_SSID”; //Replace with your SSID
const char* password = “Your_WiFi_Password”; //Replace with your Password

Find above code line,put your own ssid and password on there.

2)IPddress & Port Settings

After completing the previous steps, we can upload the code to the NodeMCU and then turn on the serial monitor, and if the networking is successful, we can get the corresponding IP address.

If we get the IP of NodeMCU-2 is 192, 168, 0, 17, we will change the code to be uploaded to NodeMCU-1 as the following:

// Destination IP and Port
IPAddress destIP(192, 168, 0, 17); // Replace with the IP of NodeMCU2
unsigned int destPort = 8888; // Replace with the port number of NodeMCU2

If we get the IP of NodeMCU-1 is 192, 168, 0, 15, we will change the code to be uploaded to NodeMCU-1 as the following:

// Destination IP and Port
IPAddress destIP(192, 168, 0, 15); // Replace with the IP of NodeMCU1
unsigned int destPort = 8888; // Replace with the port number of NodeMCU1

We use the “8888” local port here, you can change it to your own local port, change the IP address to the one you got in the previous steps, then, load the modified codes to the NodeMCU again.

3)Boad & COM Port Settings

After do that,choose the coresponding board type and port type as below,then upload the sketch to the NodeMCU.

Running Result

Upload both codes on both NodeMCUs separately and make sure they are both connected to the same WiFi network. You should then be able to see the communication between them in the serial monitor.

Open the Serial Monitor of NodeMCU-1, and you will see as below:

Open the Serial Monitor of NodeMCU-2, and you will see as below:

NOTE:

We need to note that ESP8266 is a 2.4G WiFi device, please access to 2.4G network, if you access to a 5G router network, there will be a prompt that the network connection is not successful.

Part details

SKU:  DKRK100700

No. Picture Name Link
1 OSOYOO NodeMCU Board https://osoyoo.store/products/osoyoo-nodemcu-module-usb-c-esp8266-esp-12f-wifi-development-board-with-ch340-for-arduino-ide-micropython-includes-tutorial?variant=41099777638511
2 Servo motor https://osoyoo.store/products/sg90-micro-servo-for-arduino-raspberry-pi-robot?variant=31957821096047
3 LED(6 x White, 6 x Red, 6 x Yellow, 6x Green) https://osoyoo.store/products/led-packs-for-arduino?variant=31957816442991
4 Buzzer https://osoyoo.store/products/piezo-buzzer-module-1pcs?variant=39879251656815
5 Push Button and Hats https://osoyoo.store/products/push-button-and-hats-5pcs?variant=39879253131375
6 Photoresistor(Light Sensor) https://osoyoo.store/products/light-sensor?variant=41099777736815
7 potentiometer(10K lohm adjustable resistor) https://osoyoo.store/products/potentionmeter-10k-adjustable-resistor-3pcs?variant=39879281016943
8 I2C LCD Display (16*2) https://osoyoo.store/products/i2c-1602-lcd-display-module-blue-backlight?variant=41099777933423
9  Temperature&Humidity Sensor Module https://osoyoo.store/products/dht11-temperature-humidity-sensor?variant=41099777998959
10 Resistors https://osoyoo.store/products/osoyoo-electronic-component-kit-total-1390-pcs-led-diodes-30-values-resistors-electrolytic-capacitor-package-ceramic-capacitors-common-diodes-common-transistor?variant=29503912706166
11 4*AA Battery Holder Box https://osoyoo.store/products/battery-box-for-4pcs-aaa-battery?variant=41099778031727
12 4 LED Module https://osoyoo.store/products/4-digit-7-segment-display?variant=41099778064495
13 Stepper Motor +Bridge https://osoyoo.store/products/stepper-motor-with-driver-28byj-48-5v-dc?variant=41099778130031
14 Tlit Sensor Module https://osoyoo.store/products/sw-520d-basic-tilt-switch?variant=41099778162799
15 Infrared Remote Controller https://osoyoo.store/products/infrared-remote-controller-for-arduino-raspberry-pi-microbit-stemmodel-2019011500?variant=31958087532655