PART 1 - Send Arduino Data to the Web ( PHP/ MySQL/ D3.js )





Introduction: PART 1 - Send Arduino Data to the Web ( PHP/ MySQL/ D3.js )

The objective of this project was to use and Arduino to read a sensor and send the values to the internet, to be stored in a Web Server and displayed.

It consists in an Arduino Uno with an Ethernet Shield and a DHT 11 temperature / moisture sensor, acting as a Web Client. It sends POST requests with the readings to a web server running a custom Database and PHP application.

The PHP app stores the values when new POST requests are received and also serves the pages that display the information. In Part 2, i will explain the use of D3.js to dynamically show the data stored in the Database.

The Arduino it's configured to use a Dynamic IP Address, in order to solve any conflicting IP issues, and also to work easily with most home networks/routers.

This project is divided in 2 main parts:

- Arduino Web client Application: reads the sensor values and sends them to the webserver.
- PHP/MySQL Application: handles the POST requests that are sent to the server and serves the pages to clients who connect 
- Data Visualization: The PHP application will use the Javascript Framework D3.js to display the values stored in the DB with graphics. It will allow to navigate to the past days to observe the readings


  1. Arduino Uno
  2. Ethernet Shield (eBay clone)
  3. DHT 11 sensor
  4. breadboard
  5. 10k Ohm resistor
  6. USB cable
  7. Ethernet cable
  8. wires
  9. piece of acrylic
  10. PCB spacers


- You need access to a web server ( can be from a free hosting company ) with capability to run PHP applications and also to create databases. ( possibly cPanel with phpMyAdmin)


Request Maker: This online tool is very useful to test the PHP application. You can simulate the POST requests that will be made by the Arduino and check if everything is working well.

DHT11 sensor library from Adafruit

Arduino Web Client

Arduino IDE

Arduino Ethernet

Step 1: Arduino Web Client + DHT11 Sensor

The code is very simple, all the important section are commented. If you have any doubt feel free to ask.

Step 2: PHP / MySQL Application

In this second part i will explain briefly the PHP application and the database. The database is used obviously to store the sensor readings, so that they can be accessed later. It's a very simple DB, with just one table with 3 columns. It stores the time stamp and the corresponding temperature and humidity values.

		temperature int(11) NOT NULL,
		humidity int(11) NOT NULL,

The PHP application consists of 3 files:

- connect.php: this file is loaded every time we need to access to the database. It's loaded in the beginning of the almost each file. It contains a function that returns a new connection to be used by the PHP to execute query's to the DB. You need to store the DB configs (hostname, database, user, password) in this file.

- add.php: when the Arduino sends POST requests to the server, is to to this page. The PHP receives the values sent in the request and executes an insertion query with those values.

Sometimes you need to change the permissions of this file (should be 644), because it might be protected to allow only executions from the localhost.

- index.php: this is the website landing page. It displays the values that are stored in the database. Right now, it will display all the values in a single HTML table, just to show that works.

So, this concludes the first part of this Instructable. Feel free to ask questions about anything related, i'm glad to help.

3 People Made This Project!


  • Water Contest

    Water Contest
  • Clocks Contest

    Clocks Contest
  • Creative Misuse Contest

    Creative Misuse Contest

162 Discussions

Respected sir, Good morning sir, i am madhu from Madanapalle. Sir, I want know about how we will connect IoT things to website. can you please expalin it sir.


Question 4 months ago

Hi, tried this tutorial of yours. But its not working, data wont feed into my SQL database. I used a server, saved my php script to that server to fetch the data from arduino and send to database. But seems to be not working :( Please help me. Thanks

Sir , i want to connect my gsm module to apache server! Is it possible ?


Question 5 months ago

I have to control an Home automation system through Web so would php be enough for backend and how would i connect the server through IP address if i am able to send ardino data over wifi module


Question 5 months ago

How to put the ph files in my subdomain? I tried but showing server not found


Question 5 months ago

In the add.php section,you said that sometimes we have to change the permission of this file. What do you mean by that?

from where will the ethernet shield get internet?


First thanks for this project, it is exactly what I wanted to start Arduino-WEB experiences.

Everthing is fine for measuring on arduino, connecting with ethernet shield, and also connection to my WEBside returns = 1 so it connects correctly. Database is also created.

But The add.PHP dosent work ( no data apears in the table of database).

Who can I debug for finding solution ? Who can I know if it is a problem to not access to PHP file / not connecting to database / SQL execution ?

Your help would greatly be apreceated !!

I copy only the code of the part that doesnt work :

(I modified the sql to write fix values to test, but still does not work)


= client.connect("", 80);

if (Conect) {

client.println("POST /add.php HTTP/1.1");

client.println("Host:"); // SERVER ADDRESS HERE TOO


client.print("Content-Length: ");





if (client.connected()) {

client.stop(); //









$connection = mysql_connect($server, $user,

if (!$connection) {

die('MySQL ERROR: '
. mysql_error());


or die( 'MySQL ERROR: '. mysql_error() );

return $connection;



PHP add





$query =
"INSERT INTO `tempLog` (`temperature`, `humidity`) VALUES





what version of xampp need to use ?

enthernet shield is unable to send data on WAN i mean hosting companies are unisg ssl and ethernet shield unable to handle it please help me i want to send data on my website on WAN ....


9 months ago

I'm having trouble compiling for the wemos d1. The error I''m getting has to do with the concatination in the data = line. Can you not concat in the Arduino IDE?

Thank you for the detailed instructions.

Just curious if there is a quick way to have event based data logging and still have time stamp in database.

In file included from C:\Users\YPK\Documents\Arduino\libraries\DHT-sensor-library-master\DHT_U.cpp:22:0:

C:\Users\YPK\Documents\Arduino\libraries\DHT-sensor-library-master\DHT_U.h:25:29: fatal error: Adafruit_Sensor.h: No such file or directory

#include <Adafruit_Sensor.h>


compilation terminated.

exit status 1

Ошибка компиляции для платы Arduino/Genuino Uno.

1 reply

try to use older version of DHT library, it works for me

how to connect Arduino + mysql + android, means i need to access that mysql data from android it self

Thank you for the instructable..can we add a relay to the arduino and control it by server...

How about instead of monitoring temp we monitor voltage? Say, from a solar panel battery bank!