In this lesson, we will show you how to make simple Internet of Things (IoT) project – to control a servo from a remote browser.
We will use Osoyoo Mega-IoT Shield to connect LED and MEGA2560 MCU board. Arduino MEGA2560 board can work as a web server. Remote browser can access this web server and control the servo connected to D3 pin of MEGA2560.
First, please plug OSOYOO MEGA-IoT Extension Board into MEGA2560 board:
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):
Step 1 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 2) Library Installation (if you have installed WifiESP library, please skip this step)
OSOYOO MEGA-IoT extension TX/RX pin to Arduino A9/A8 pin by default. So in Arduino 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 Arduino IDE, we need download WiFiEsp-master library from following link:
In order to use the keypad, you also need download and install a keypad library from:
Open Arduino IDE, click Sketch – Include Library- Add .Zip library to load above zip files into Arduino IDE.
Step 3 To use the Servo in Arduino 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, unzip it, you will see a folder called “smarthome-lesson8”:
Step 5 After above operations are completed, connect OSOYOO MEGA2560 Board to PC with USB cable.
Step 6 Arduino IDE: Choose corresponding board type and port type for you project .
Step 7 Arduino IDE: Click file – Open, then choose code “smarthome-lesson8.ino” in the folder, load up the sketch onto your Arduino.
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 Arduino , open the serial monitor in the upper-right corner of Arduino IDE, you will see following result:
From the serial monitor, you can see the IP address of your MEGA2560 board in the read circle (in above picture, 192.168.50.8).
Then use your browser to visit the website http://mega2560-ip-address (in above case, http://192.168.50.8), you will see following result:
Click the two links as showed in above picture, you will control the servo which is connected to your MEGA2560 through the IoT Shield.
Click open the door, the servo will turns to 180 degrees and the green LED will be lit.
Click close the door, the servo will backs to 0 degree and the green LED will goes out.
You can also use Keypad to control the servo. When you press “*” key , the servo will rotate to 180 degree position. If you press “#” key, then the servo will rotate back to 0 degree position.
DownLoad Url osoyoo.com