Showing temperature and humidity in the Web
The Arduino board itself is not able to provide information like temperature and humidity. Specific sensors are needed to read physical properties. This example uses the AM2302/DHT22 device, that provides calibrated digital signal output of the temperature and humidity. In order to show time on a website, the Arduino board has to be connected to internet. An ethernet shield can be used to enable the internet connection. The ethernet shield has to be installed on top of the Arduino board and connected with an RJ-45 cable to an IP router. The Arduino board can be programmed as web client to POST temperature and humidity values towards an external web server, where data are stored and showed by a script. In this experiment a PHP script is used in the web server. The following figure shows the main parts of this Arduino experiment: Hardware set-up
Following hardware is required to build the experiment:
Install the ethernet shield on top of the Arduino board, then proceed with the following connections, without any power connected:
Confused about all three-letters acronyms? Here is a brief explanation: GND is the ground line, Vcc is the positive supply line, SDA is the serial data line. Arduino software
Before writing software make sure to have installed the software development environment, downlodable from Arduino Software web site. It may be needed to download some library if not already present: Ethernet and DHTlib (some googling will help you finding the appropriate libraries). Libraries are required to manage the external devices. For this reason the sketch has to include the required libraries:
The setup() function has to initialize libraries features:
The loop() function does the job:
The function postPage() can be found in the Arduino playground area.
Download the complete sketch here, change the secret value and the web server name, then connect your Arduino Uno board to your computer using a USB cable and upload the sketch to the Arduino board. Server side software
A script has to be loaded in the web server for two tasks:
Information is received in a POST request. A secret value is used to check that the information is sent by Arduino board:
The main part of the functionality is provided by the following code:
Download the complete script here, unzip it, change the secret value and upload to your webserver. Now you should be able to see the temperature and humidity using a web browser! Demo
Here is an example of the output in the web browser:
28-Dec-14, 10:20:54
temperature: 20.7 humidity: 47.1 |