Authorized Online Retailers:

AMAZON
AMAZON-jp
amzuk

1 Overview

In previous lessons, we have showed how to use web browser to access Arduino Board through Internet. In these examples, we used a protocol called HTTP. Arduino works as a HTTP server(web server)  and response to request from browser(client) .
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 send angle control signal to remote Arduino and make the servo to make a rotate at a specific angle.

2 Hardware Preparation

Quantity
UNO Board 1
Ethernet Shield W5100 1
USB cable 1
Servo motor SG90 1
Jumper wires Several
Breadboard 1

3 Hardware connection

Connect the servo motor SG90 with  UNO as following diagram:

4)Software Installation

Step A)Install Servo library: (if you have installed Servo Library, please skit this step)

Download the  library from:
https://osoyoo.com/driver/Servo.zip

Then in your Arduino IDE ->Sketch->Include Library->Add .ZIP Library and select these two zip files you just downloaded, and upload it to Arduino.

Step B) Download sample code from  https://osoyoo.com/driver/ethernet_iot/lesson7/w5100-lesson7.zip, unzip the file and double click the w5100-lesson5.ino file, load the sketch into Arduino IDE.

Open your Serial Monitor, you can see your router will assign an IP address to your Arduino   as following:

Your Arduino IP address is 10.0.0.45

In above result, you can see my Arduino IP address is 10.0.0.45 , we will set this IP in our UDP send/receive Cell Phone APP.

Step C)Download an Android or iOS UDP sending/receiving APP. You can use any UDP sending/receiving APP. In this lesson , we  use a free   APP called “UDP Sender/receiver” in Google Play Store. If you are using iPhone, you can search UPD sender to get similar APP.
After opening  UPD Sender/Receiver APP, you will following UI:
please be noted local Port can be any value between 1 to 10000, but can not be blank. We suggest you use 2391 same as our sample.

In above UI, you fill 3 fields:
Host: 10.0.0.45 , this is your Arduino IP which you get from Arduino Serial monitor
Port:8888 , this is your Arduino UDP listen port, defined by lesson7 sketch line 24.
Message: 15d , this is the control message which means we want Servo point to 15 degree position.

Test:
Now click send button, the message “15d” will be sent to your remote Arduino and your server will make 15 degree rotate.

You can fill the message text field with “180D” and click send, your servo turn to 180 degree position.

If you send the message “0D”, the servo will rotate back to 0 degree position.