Buy from US | Buy from UK | Buy from DE | Buy from IT | Buy from FR | Buy from ES | Buy from JP |
In lesson 1 , we have learned how to use Arduino to make simple web server and display “Hello World” in your remote browser. The Arduino 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 Arduino remotely through UDP protocol.
Arduino UNO 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 UNO 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 Arduino IDE (If you have Arduino IDE version after 1.1.16, please skip this step).
Download Arduino IDE from https://www.arduino.cc/en/Main/Software?setlang=en, then install the software.
Step B) Connect the Arduino UNO board to computer via USB cable,
Step C) Open the Arduino 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) Arduino IDE: Click file -> click Open -> choose code “esp8266-lesson2”, load up the sketch onto your Arduino.
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.
Now upload the sketch to Arduino board and open your Serial Monitor, you can see your router will assign an IP address to your Arduino as following:
In above example, 192.168.50.47 is the IP address of my Arduino, we need to set this IP address in our APP in next step.
Step F) 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 test.
In Google Play or Apple Store, please search key words “OSOYOO WIFI UDP Robot Car”, you will find a yellow icon APP .
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 Arduino 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 Arduino 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.
DownLoad Url osoyoo.com
You must be logged in to post a comment.
When using this tutorial, averything works as expected EXCEPT:
My serial monitor doesnot show the IP address of my mobile phone.
I am directed to write this down because it will be required in the next tutorial.
I am using:
Arduino IDE 2.0.4
OSOYOO WiFi Internet of things learning kit for arduino
Arduino sketch downloaded today (3/17/23) from OSOYOO website “esp8266-lesson2.zip
Serial monitor displays:
please set your UDP APP target IP to: xx.x.x.xx target port 8888
Received packet of size 1
Received packet of size 1
Received packet of size 1
In Step F, the Serial monitor will show your Arduino IP address. Did you get your Arduino IP address and set it to your cell phone?