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

In lesson 1 , we have learned how to use OSOYOO basic mainboard to make simple web server and display “Hello World” in your remote browser. This is using a protocol called HTTP to exchange data with remote client device(browser).

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 IDE remotely through UDP protocol.

OSOYOO Basic board x 1

OSOYOO ESP8266 Wifi Shield x 1

USB cablex 1

LED x 1

200 ohm resistor x 1​

First, please insert the ESP8266 wifi Shield into your baisic  board,

Make sure jumper cap connected E_TX to D4 and E_RX to D5.

Then connect the LED long pin to D13 in Wifi shield through a 200 ohm resistor, LED short pin to GND , circuit is as below:

Step A Install latest IDE (If you have IDE version after 1.1.16, please skip this step).

Download IDE from https://www.arduino.cc/en/Main/Software?setlang=en, then install the software.

Step B) Connect the OSOYOO Basic  board to computer via USB cable,

Step C) Open the IDE and choose corresponding board type and port type for you project.

Step D)Download the sketch file from : https://osoyoo.com/driver/wifi-iot/lesson2/esp8266-lesson2.zip

Unzip the download file and enter the folder esp8266-lesson2.

Step E) IDE: Click file -> click Open -> choose code “esp8266-lesson2”, load up the sketch onto your IDE .

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.

Step F) Now upload the sketch to board and open your Serial Monitor, you can see your router will assign an IP address to your IDE as following:


In above example, 192.168.1.81 is the IP address of my IDE, we need to set this IP address in our APP in next step.

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

Make sure your Cell phone is in the same Local Network of Arduino. Open the APP, click Settings, enter your Arduino IP address from Step F and Port to 8888 in settings:

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

After you click Cell phone button, the Arduino Serial monitor will also shows your cell phone’s IP address as following:

Please write down this IP address, we will use this IP address in next lesson.

FAQ about the Wifi UDP APP and sketch Code:
Q 1)What happened when you press buttons in OSOYOO WiFi UDP Robot Car APP ?
A: When you press a button of the APP, APP will send a single-letter message through UDP protocol to target device (in this example, our Wifi Shield)

Button UDP message
F1 F
F2 G
F3 H
F4 I
F5 J
F6 K
A
B
R
L
E

Q2: How do react to App command

A: Our sample code (esp8266-lesson2.ino) line 69 to line 76 switch statement handle the remote UDP command:

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

In above code lines, variable c is the message we got from Mobile APP. If message is ‘F’, it means F1 key is pressed and we should turn on the LED, if message is ‘G’, it means F2 is pressed and we need turn on the LED.

Learn More about parts

No. Picture Product Name Link
1 OSOYOO basic board https://osoyoo.store/products/osoyoo-uno-r3-for-arduino?variant=31955265290351
2 OSOYOO Wifi shield https://osoyoo.store/products/esp8266-wifi-shiled-osoyoo-wifi-internet-of-things-learning-kit-for-arduino-uno?variant=31955252215919
3 Photoresistor Sensor Module https://osoyoo.store/products/photoresistor-sensor-module-light-detection-digital-switch-mete-for-arduino?variant=31955271057519
4 Water Level Detection Sensor https://osoyoo.store/products/rain-water-level-sensor-module-detection-liquid-surface-depth-height-for-arduino?variant=31955273810031
5 Sound Detection Sensor Module https://osoyoo.store/products/high-sensitivity-sound-microphone-sensor-detection-module-for-arduino-avr-pic?variant=31955278921839
6 Ultrasonic sensor https://osoyoo.store/products/hc-sr04-ultrasonic-sensor-module-for-arduino?variant=31957815558255
7 Servo motor https://osoyoo.store/products/sg90-micro-servo-for-arduino-raspberry-pi-robot?variant=31957821096047
8 Active Buzzer Module https://osoyoo.store/products/buzzer-sensor-module-for-esp8266-iot-kit?variant=31955947225199
9 Temperature&Humidity Sensor https://osoyoo.store/products/dht11-temperature-humidity-sensor-module-for-arduino?variant=31955953221743
10 Relay Module https://osoyoo.store/products/single-channel-relay-module-for-arduino-raspberry-pi?variant=31955954401391
11 Gas Sensor Module https://osoyoo.store/products/mq-2-smoke-sensor-for-arduino?variant=31955955417199
12 Digital Barometric Pressure Sensor Module https://osoyoo.store/products/bmp180-high-precision-pressure-sensor-for-arduino?variant=31957739339887
13 Infrared Sensor Module https://osoyoo.store/products/hc-sr501-pir-motion-sensor-for-arduino?variant=31957812838511
14 LED(6 x White, 6 x Red, 6 x Yellow, 6x Green) https://osoyoo.store/products/led-packs-for-arduino?variant=31957816442991