In Lesson 1 and lesson 2 , we use Arduino board and OSOYOO ESP8266 Wifi module to make some simple web server and transfer data through HTTP protocol.

In this lesson, we will teach you to use a very simple and power protocol called UDP which is commonly used for Email service and control signal. We will use a cell phone APP to turn On/Off an LED in Arduino remotely through UDP protocol.

UDP is a simple and powerful protocol which are often used in email and one-way data transfer applications.  As Arduino board has very limited memory, UDP protocol usually has better performance than other IoT protocols such as HTTP and MQTT.

Arduino UNO board x 1

OSOYOO ESP8266 Wifi Shield x 1

LED x 1

200 ohm resistor x 1​

Circuit Connection:

OSOYOO Wifi Module Arduino UNO
LED Arduino UNO
Long Pin D13
Short Pin GND(thru 200 omh resistor)

Download above Fritzing circuit diagram file from following link:

Step 1) If you haven’t install Arduino IDE and Wifi ESP Master Library, please read lesson 1 and install the library.

Step 2)Download the sketch file from :

Unzip the download file and enter the folder esp8266-lesson3, double click to open esp8266-lesson3.ino file.

In the sketch, find following lines:

char ssid[] = "******"; // your network SSID (name)
char pass[] = "******"; // your network password
please replace the ****** with your correct wifi SSID and password, otherwise your project can
 not connect to Internet.

After changing the Wifi password, please upload the code to Arduino UNO board.  Open serial monitor, you will see:

In above example, is your Arduino IP address. We will use this IP address to send UDP command.

Step 3) Install UDP send Mobile APP
You can use any UDP send APP to run this lesson. In this lesson, we use OSOYOO Wifi UDP Robot Car APP to make the test.
In Google Play or Apple Store, please search key words “OSOYOO Wifi UDP Robot Car”, you will find a yellow icon APP .

In APP UI screen, click F1 button, your LED will be turn on , then click F2 button, your LED will be turn off.

How does this work?

When you click F1 button, our cell phone APP actually send “F” letter through UDP protocol to your Arduino.
When you click F2 button, our APP send “G” letter through UDP protocol to your Arduino.

If you don’t use OSOYOO robot car UDP APP, you can use any other UDP sending software to send an “F” or “G” UDP packet to your Arduino IP address port 8888. The result will be the same.

Following Arduino code handle the F1 and F2 command:

      switch (c)    //serial control instructions
        case 'F': digitalWrite(ledPin, HIGH) ;break; //TURN ON LED
        case 'G':digitalWrite(ledPin, LOW) ;break; //TURN OFF LED

You can see :
when Arduino receives “F” UDP message, then it gives ledPin a HIGH digital signal to turn on the LED.
when Arduino receives “G” UDP message, then it gives ledPin a LOW digital signal to turn off the LED.