Hello guys, i make this instructable for the people that  liked the electronics and the botanic, with this you have the data about  the temperatura and the humidity of your orchard and register this in a data base MySQL.

For this proyect you need some knowledge of programing in PHP and MySQL, we will make three archive .php, but this I'll explain in the following steps.

Step 1: You need this

For this project, you need:

Arduino UNO or similar board  ($29.95)


WiFly Shield ($89.95)

Grove - Moisture sensor ($4.99)

Six Jumper Wires ($4.50)

DS18B20 Temperature Sensor with metal tip ($10.59)

If only  need, One protoboar ($9.58)


you need a server WEB, with PHP and database MySQL. I used the NAS of QNAP TS-110, is perfect for this project.

<p>Hello again, I did the same steps which you were did till I reached to show the content of database in the website, but it seems there is a problem between add php and arduino. the arduino sends the data but it is not shown in the website can have a look at it thanks</p>
Hi! Send me the code for review and test to see what is going wrong . My email is camilo.nunez@cnf.cl
<p>thanks for your efforts. can I use the blue WiFi shield instead of the red one that you use it. what is the example you suggest to use it.</p>
If you mean the original Shield Arduino WiFi , you need to read the page of the project : https://www.arduino.cc/en/Main/ArduinoWiFiShield<br><br>Good luck !
<p>hello. I just want to asking about the connect.php. What do you mean by &quot;your_ipserver&quot; ?</p>
Hi, &quot;your_ip server&quot; is the address where you host the server MySQL. In this case, is &quot;;, to connect the localhost.
<p>which one in it?</p>
<p>None of these data will be used , if you are using phpMyAdmin , go to the tab &quot; Estado Actual&quot; ( as from image ) and in the section of server, have the direction of you need.</p>
<p>hai. I'm having a problem with the arduino coding. It said as shown in the image:</p>
<p>This error is because you have not included the OneWire library, I recommend you download the version 2.0 from here: http://www.pjrc.com/teensy/td_libs_OneWire.html</p>
<p>Nice Tutorial. <br>Can I Add a LCD to display the temperature on it and also save it in the database.</p>
<p>Hello camilo. <br>thanks for your nice post which was very helpful.</p><p>i want to make a data storage and monitoring using Arduino uno &amp; Arduino ethernet shield W5100. please help me by PHP &amp; Arduino code.</p><p>Thanks and waiting for replay.</p>
<p>Hi ! In the case for the Ethernet Shiel, you only need modify the data of the Shield, then, you work with the variables &quot;temp&quot; and &quot;sensorValue&quot;. If you have more doubts, write me to my email camilo.nunez@cnf.cl</p><p>Regards and good luck !</p>
<p>Hola Camilo:</p><p>Muy buen tutorial, felicidades.</p><p>Que tendria que cambiar en el script de arduino, estoy utilizando un Wifi Shield cc3000 de Adafruit en lugar del WiiFly?</p>
<p>Hola Victor ! Bueno para serte honesto, no he trabajado nunca con ese modulo, pero como el programa es gen&eacute;rico en sus variables, lo que te debe importar al momento de trabajar con otros m&oacute;dulos, es que tus variables &quot;temp&quot; y &quot;sensorValue&quot; no cambien cuando manipules el Script. Si tienes m&aacute;s dudas me avisas ! Exito y muchas gracias !</p>
<p>hye.. nice posting..can you help me?because im beginner in this programming. where to put all of the code for database mysql?</p>
Hi ! For the use of MySQL you must have a server that hosted on same hosting or plan, then you only need to upload the .sql file to import the table. Greetings!
<p>Is it possible to do the same with Ultrasonic sensor and what code is necessary to do?</p>
<p>how to that?im really newbie...</p>
<p>hi,can we implement this using arduino ethernet shield</p>
<p>hye..where i have to put all this files?i just manually added?</p>
<p>Hello,</p><p>Can this work with water flow sensor? I need to create a similar project but to measure the flow rate of water. The sensor type i'm intending to use is SKU: POW110D3B. </p><p>Thanks and awaiting for your reply</p>
Hi !<br>Yes, you can, I recommend use this tutorial to get the sensor code: http://goo.gl/HBoZyr<br><br>Good luck !
<p>Hola... excelente trabajo... por lo que he visto envias datos desde tu arduino a una base de datos en SQL, y la visualizas en un browser.... pero en el caso que quieras activar una se&ntilde;al digital, lo haces desde tu front por medio del SQL o desde tu front directamente hacia Arduino?</p>
Hola Eddie. Si te refieres al Front-end de una se&ntilde;al digital, debe ser por medio del Arduino. Saludos !
<p>Hi</p><p>I tried the link goo.gl/g1lbSm but the page could not be found. Any idea?</p><p>Best regards Carl</p>
<p>Thanks for the great instructions! </p><p>one small error/typo found in the arduino code:</p><p>client.print(&quot;temp<strong>t</strong>1=&quot;);<br>should be:<br>client.print(&quot;temp1=&quot;);</p><p>Being dyslectic it took my 20 minutes to figure this out (-:</p><p>But once I found the error, ot worked like a charm and was easily adjusted for my needs.</p>
<p>Hi ! Thanks for correct the mistake, not pass without noticing. I've already changed the page. Thank you very much!</p>
<p>Hey guys, I am new here. How can I download the files (.php and .ino)?</p><p>Thanks. :)</p>
Hi Ivan ! This is the link where you can download the files : http://goo.gl/D20rsE<br><br>Good lucky !
<p>Hello. I'm doing a project that is based on receiving data of temperature, wind speed and things like that. But I'm using Arduino Y&uacute;n in case of Arduino Uno+Wifly. </p><p>Which differences will be having the code?</p>
Hi Oscar, well, for your case, I recommend you read this Instructables: <br><br>http://goo.gl/g1IbSm<br><br>The difference lies in Bridge and in which language you want to work with to the database, if PHO or Python. It will depend on your project.<br><br>If you need more information about working with databases Arduino YUN, please tell me to help.<br><br>Many luck!
<p>Hi Camilo,</p><p>Nice tutorial !!</p><p>I am trying to upload temperature from temperature sensor. I am using temperature sensor, arduino uno, arduino ethernet shield and RJ 45 cable. I am using Xampp(<a href="https://www.apachefriends.org/index.html" rel="nofollow">https://www.apachefriends.org/index.html</a>) database running on my PC. I have created a table(temp) in this database(temp_database). I have saved php files in my computer at C:xampp/htdocs/temp_database. I have hooked up Ethernet Shield to one of internet ports in my home. After all this i don't find table getting updated by temperature values. Is there any mistake? Please guide me.Here is the source code for Arduino:</p><p>#include &quot;SPI.h&quot;</p><p>#include &quot;Ethernet.h&quot;</p><p>const int temperaturePin = A0;</p><p>byte mac[] = { 0x90, 0xA2, 0xDB, 0x0F, 0x3A, 0xDF };</p><p>byte ip[] = { 131, 247, 19, 140 }; this is the ip address for Ethernet Shield</p><p>byte gateway[] = { 131, 225, 3, 254 }; </p><p>byte subnet[] = { 255, 255, 252, 0 };</p><p>EthernetClient client ;</p><p>char server[] = &quot;www.localhost.com&quot;;</p><p>void setup() {</p><p> // Open serial communications and wait for port to open:</p><p> Serial.begin(9600);</p><p> while (!Serial) {</p><p> ; // wait for serial port to connect. Needed for Leonardo only</p><p> }</p><p> // start the Ethernet connection:</p><p> if (Ethernet.begin(mac) == 0) {</p><p> Serial.println(&quot;Failed to configure Ethernet using DHCP&quot;);</p><p> // no point in carrying on, so do nothing forevermore:</p><p> // try to congifure using IP address instead of DHCP:</p><p> Ethernet.begin(mac, ip);</p><p> }</p><p> // give the Ethernet shield a second to initialize:</p><p> delay(1000);</p><p> Serial.println(&quot;connecting...&quot;);</p><p>}</p><p>void loop()</p><p>{</p><p> if( client.connect(server, 80)) </p><p> {</p><p> float tem = getTemp();</p><p> Serial.println( tem );</p><p> client.print( &quot;GET /add.php?&quot;);</p><p> client.print(&quot;tempt1=&quot;);</p><p> client.print( tem );</p><p> client.println( &quot; HTTP/1.1&quot;);</p><p> client.println( &quot;Host: localhost&quot; );</p><p> client.println( &quot;Content-Type: application/x-www-form-urlencoded&quot; );</p><p> client.println( &quot;Connection: close&quot; );</p><p> client.println();</p><p> client.println();</p><p> client.stop();</p><p> }</p><p> delay( 5000 );</p><p>}</p><p>float getTemp() {</p><p> float voltage, V,t ;</p><p> voltage = analogRead(temperaturePin) ;</p><p> V = voltage * 0.004882814 ;</p><p> t = (V - 0.5) * 100.0;</p><p> return t;</p><p>}</p><p>Here is the conec.php file</p><p>&lt;?php</p><p>function Conection(){</p><p> if (!($link=mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;8282&quot;))) {</p><p> exit();</p><p> }</p><p> if (!mysql_select_db(&quot;temp_database&quot;,$link)){</p><p> exit();</p><p> }</p><p> return $link;</p><p>}</p><p>?&gt;</p><p>Here is the add.php file:</p><p>&lt;?php</p><p> include(&quot;conec.php&quot;);</p><p> $link=Conection();</p><p>$Sql=&quot;INSERT INTO 'temp'('temp1') VALUE ('&quot;.$_GET[&quot;temp1&quot;].&quot;')&quot;; </p><p> mysql_query($Sql,$link);</p><p> header(&quot;Location: insertareg.php&quot;);</p><p>?&gt;</p><p>Here is the insertareg.php file:</p><p>&lt;html&gt;</p><p>&lt;head&gt;</p><p> &lt;title&gt;Data of Sensor&lt;/title&gt;</p><p>&lt;/head&gt;</p><p>&lt;body&gt;</p><p>&lt;h1&gt;Data from the temperature sensor&lt;/h1&gt;</p><p>&lt;form action=&quot;add.php&quot; method=&quot;get&quot;&gt;</p><p>&lt;TABLE&gt;</p><p>&lt;tr&gt;</p><p> &lt;td&gt;Temperature &lt;/td&gt;</p><p> &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;temp1&quot; size=&quot;20&quot; maxlength=&quot;30&quot;&gt;&lt;/td&gt;</p><p>&lt;/tr&gt;</p><p>&lt;/TABLE&gt;</p><p>&lt;input type=&quot;submit&quot; name=&quot;accion&quot; value=&quot;Grabar&quot;&gt;</p><p>&lt;/FORM&gt;</p><p>&lt;hr&gt;</p><p>&lt;?php</p><p> include(&quot;conec.php&quot;);</p><p> $link=Conection();</p><p> $result=mysql_query(&quot;select * from temp order by id desc&quot;,$link);</p><p>?&gt;</p><p>&lt;table border=&quot;1&quot; cellspacing=&quot;1&quot; cellpadding=&quot;1&quot;&gt;</p><p> &lt;tr&gt;</p><p> &lt;td&gt;&nbsp;Temperature &nbsp;&lt;/td&gt;</p><p> &lt;/tr&gt;</p><p>&lt;?php </p><p> while($row = mysql_fetch_array($result)) {</p><p>printf(&quot;&lt;tr&gt;&lt;td&gt; &nbsp;%s &lt;/td&gt;&lt;/tr&gt;&quot;, $row[&quot;temp1&quot;]);</p><p> }</p><p> mysql_free_result($result);</p><p>?&gt;</p><p>&lt;/table&gt;</p><p>&lt;/body&gt;</p><p>&lt;/html&gt;</p>
<p>Hi! I'm having an error in instareg.php It says </p><p><b>Warning</b>: mysql_select_db() expects parameter 2 to be resource, object given in <b>C:\xampp\htdocs\WEB2\php_files\conec.php</b> on line <b>9</b></p><p>Can\'t use sensordata :</p><p>what should I do in here? anyone help?</p>
<p>Hi! What will I write in this? Can you provide an example? </p><p>if (!($link=mysql_connect(&quot;your_ipserver&quot;,&quot;your_user&quot;,&quot;your_pass&quot;)))</p>
<p>Hi! very nice tutorial. thanks!</p><p>is there any Ethernet version?</p>
<p>Hi! Nice tutorial!</p><p><br>I have a question</p><p>Where specifically are suppose to be the add.php, conec.php, insertareg.php???</p><p>Thanks for your time! :)</p>
<p>Hi ! These files must be hosted on your serve to be consulted for the database.<br></p><p>Much success and regards !<br>Camilo</p>
<p>Hi Camilo! Thanks for your answer. <br><br>Can I know what library for the WiFly Antenna did you used in this project?</p><p>I have try with two and the program and I get errors such as:</p><p>&quot;byte has not been declared&quot;</p><p>&quot;Client has not been declared&quot;</p><p>I think that must be a problem with the library I am using :)<br><br>Thanks a lot for your help! ;)</p>
<p>Hi ! c:</p><p>I recommend that you download it from Github, this link: <a href="https://github.com/jcrouchley/WiFly-Shield" rel="nofollow">https://github.com/jcrouchley/WiFly-Shield</a></p><p>In all modes, being very honest, it is recommended that if you work with Arduino and Wifi, you better have your the Arduino YUN.</p><p>If you have further questions do not hesitate to say them c:</p><p>Regards !!</p>
<p>Hi Camilo,</p><p>Did you have the problem &quot;Client has not been declared&quot;? </p><p>I am using the same library that you used and im getting this problem. Please if you solve it help me :) </p><p>Thanks for your help ;)</p>
<p>I bought the Arduino UNO R3 Recently :(</p><p>Did the Arduino UNO gave you some problem in this project?</p>
<p>Hello I have a project of home automation and I am trying to program the wifly, I have configured this module .I want to actually insert the sensor values from the arduino and display it in a web interface and save them in the database mysql I have tested this example but the table is still empty.Also, i dont understand why the instruction of GET is shown in the serial !!! , Can you help me please?</p><p>I'am using arduino uno + WIFLY RN-171 + XBEE shield <br><a href="http://cooking-hacks.com/wp/wp-content/uploads/2012/03/DSC_0405.jpg" rel="nofollow">http://cooking-hacks.com/wp/wp-content/uploads/2012/03/DSC_0405.jpg</a><br> this is the execution of the code :</p>
<p>Hi! Why did you write </p><p> client.print(&quot;&amp;&amp;&quot;);</p><p>and not</p><p> client.print(&quot;&amp;&quot;);</p><p>?</p><p>Thank you.</p>
Dear, to perform the build I get the following message: <br> <br> <br>In file included from C:\Arduino\arduino-1.0.1\libraries\WiFly/WiFly.h:4, <br> from wifly_twosensors.cpp:13: <br>C:\Arduino\arduino-1.0.1\libraries\WiFly/SpiUart.h:62: error: conflicting return type specified for 'virtual void SpiUartDevice::write(byte)' <br>C:\Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)' <br>In file included from C:\Arduino\arduino-1.0.1\libraries\WiFly/WiFly.h:8, <br> from wifly_twosensors.cpp:13: <br>C:\Arduino\arduino-1.0.1\libraries\WiFly/Client.h:21: error: conflicting return type specified for 'virtual void Client::write(byte)' <br>C:\Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)' <br>C:\Arduino\arduino-1.0.1\libraries\WiFly/Client.h:23: error: conflicting return type specified for 'virtual void Client::write(const uint8_t*, size_t)' <br>C:\Arduino\arduino-1.0.1\hardware\arduino\cores\arduino/Print.h:50: error: overriding 'virtual size_t Print::write(const uint8_t*, size_t)'
<p>Hi, do u solve the problem? i also facing it &gt;&lt;</p>
<p>Great work. I tried it on xampp and it works. Thanks for your help :)</p>
why did you put: client.print( &quot;GET /agregar.php?&quot;); it is just that I haven't seen any agregar.php file on the example. It is equal to add.php?
Well i found this page looking tutorial on how to MYSQL + PHP, and i found this project!! It looks amazing! Congrats!

About This Instructable


238 favorites


More by camilo.n1012: Control Access of Arduino YÚN with MySQL, PHP5 and Python Access control with Arduino + Keypad 4x4 + Servo (UPDATE) Save data of temperature and humidity on MySQL with Arduino Uno and Wifly
Add instructable to: