In order to connect our Things to Internet, we need select some Internet communication protocol so that different internet device can talk with each other. Some commonly used IoT protocols are HTTP, MQTT etc.
In this lesson, we will learn how to use HTTP protocol and how to make simple HTTP web server with Osoyoo MEGA-IoT shield and MEGA2560 micro-controller and show a “Hello World!” web page to remote browser . The web page also shows the input voltage of A0 pin which is detected by Arduino analogRead() functions.
1).please plug OSOYOO MEGA-IoT Extension Board into MEGA2560 board:
2). connect A0 to 5V by Male to Male jumper wire. (Jumper Cap should connect ESP8266 RX with A8, TX with A9)
|Download Arduino IDE here:
|7 zip is a free zip
utility that un-zips zip files
|Download 7zip here for free
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 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).we need download WiFiEsp-master library from following link firstly: https://osoyoo.com/driver/WiFiEsp-master.zip
Step3 Open Arduino IDE ->Sketch ->Include Library ->Add ,Zip library to load above zip files into Arduino IDE.
Step 4 After installing above library, please download the main code from following link.unzip the download zip file lesson3.zip, you will see a folder called smarthome-lesson3.
Step 5 After above operations are completed, connect OSOYOO MEGA2560 Board to PC with USB cable.
Step 6 Open the Arduino IDE and choose corresponding board type and port type for you project.
Step 7 Arduino IDE: Click file -> click Open -> choose code “smarthome-lesson3”, load up the sketch onto your Arduino.
Note: 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.
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.102).
Then use your browser to visit the website http://mega2560-ip-address (in above case, http://192.168.50.102), you will see following result:
Above result also shows the A0 pin input voltage through analogRead(0) function in line 94. analogRead() can read the input 0-5V voltage and return a value between 0 to 1023 standing for the voltage. We have connected A0 to 5V, so above Analog input A0: shows 1023.
DownLoad Url osoyoo.com