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

In previous lessons, we have showed how to use web browser to access OSOYOO Advanced Board for Arduino MEGA2560 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 OSOYOO Advanced Board for Arduino MEGA2560 and make the servo to make a rotate at a specific angle.

We will also show you how to use a Keypad to control the servo locally.

First, please plug OSOYOO MEGA-IoT Extension Board into OSOYOO Advanced Board for Arduino MEGA2560:

Then connect the LED module to the D12 port of the OSOYOO MEGA-IoT Extension Board with 3-pin PnP cable, connect servo motor to the D3 port as below (Jumper Cap should connect ESP8266 RX with A8, TX with A9):

Notice: Shut off your battery or Unplug your power adapter when upload sketch code to OSOYOO Advanced Board for Arduino MEGA2560.

Step 1  Download OSOYOO WIFI UDP Robot Car control APP
In Google Play or Apple Store, please search key words “OSOYOO WIFI UDP Robot Car”, you will find an orange icon APP as following:

You need set up the IP address of your SmartHome based on Next Step 2 result

Step 2) Library Installation (if you have installed WifiESP library, please skip this step)

OSOYOO MEGA-IoT extension TX/RX pin to OSOYOO Advanced Board for Arduino MEGA2560 A9/A8 pin by default. So in sketch code, we need use Software Serial Port to communicate with ESP8266 (set A9 as TX and A8 as RX in softwareserial object).

To use this wifi shield in IDE, we need download WiFiEsp-master library from following link:
https://osoyoo.com/driver/WiFiEsp-master.zip

In order to use the keypad, you also need download and install a keypad library from:
https://osoyoo.com/driver/smarthome/Keypad.zip

Open IDE,  click Sketch – Include Library- Add .Zip library to load above zip files into IDE.

Step 3 To use the Servo in IDE, we need download Servo.h library from this link and save it as above operations.

Step 4  After installing above libraries, please download the main code from following link:
https://osoyoo.com/driver/smarthome/smarthome_lesson8B.zip

unzip it, you will see a folder called “smarthome-lesson8B”

Step 5 After above operations are completed, connect OSOYOO MEGA2560 Board to PC with USB cable.

Step 6 IDE:  Choose corresponding board type and port type for you project .

Step 7 IDE:  Click file – Open, then choose code “smarthome-lesson8B.ino” in the folder, double click the file and open the  sketch onto your OSOYOO Advanced Board for Arduino MEGA2560.

Note: In the  sketch, find  line 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 loading the sketch to OSOYOO Advanced Board for Arduino MEGA2560 , OPEN the serial monitor in the upper-right corner of IDE as following:

You will get the IP address and Port Number as following:

From the serial monitor,  you can see the IP address of your MEGA2560 board in the read circle (in above picture, 192.168.50.47) and default port number is 8888, you need write the IP address into your APP Setting as following:

Click the two links as showed in above picture, you will control the servo which is connected to your MEGA2560 through the IoT Shield.

Now in your APP,
when you click ◄ button, the servo will point zero degree, Green LED is OFF.
Serial Monitor will show Close THE DOOR!

when you click ▲ button, the servo will point 90 degree, Green LED is OFF.
Serial Monitor will show Half Close THE DOOR!

when you click ► button, the servo will point 180 degree, Green LED is ON.
Serial Monitor will show OPEN THE DOOR!

You can also use Keypad to control the servo.
when you click * Button, the servo will point zero degree, Green LED is OFF.
Serial Monitor will show Close THE DOOR!

when you click 0 button, the servo will point 90 degree, Green LED is OFF.
Serial Monitor will show Half Close THE DOOR!

when you click # button, the servo will point 180 degree, Green LED is ON.
Serial Monitor will show OPEN THE DOOR!