Friday , 9 June 2023
Breaking News
Home > Tutorials > Arduino Tutorials > How to save DHT11 Temperature Data into Database with Wemos D1 Mini

How to save DHT11 Temperature Data into Database with Wemos D1 Mini

Hello friends. How are you?. Today we are going to learn something amazing. In my previous tutorial, you learned that How to get temperature data from DHT11 and show it on the serial monitor, but today we will go ahead and will do something advanced. We will save hardware that we used in our previous tutorial to build a new project. If you don’t visit that page please visit it here:

http://ice786pk.com/?p=540

OK, now we need some more libraries for this tutorial.

1. ESP8266HTTPClient.h

2. ESP8266WiFi.h

3. SimpleDHT.h

4. DHT.h

There are libraries that you need for this project. You also need some PHP files that will responsible for adding and fetching data into the database. First of all, I am giving you code for Arduino.

Code for Arduino

Code it too long, I know, but it has covered everything that you need for this project. In this code you have to change some data.

  1. const char* ssid = “My Internet is not free“;
  2. const char* pwd = “@f2d22“;
  3. const char* host = “http://192.168.8.103“;
  4. String get_host = “http://192.168.8.103“;

You have to change ssid, pwd, host and get_host values that are bold (Host is your localhost IP, for this, you need to install XAMPP or WAMP server).

OK now it is perfect, so let’s move.

Now you need a server that like XAMPP or WAMP and a database. I will not guide you for server installation. You can watch videos on this topic (sorry for that).

I assumed that you have finished installation of XAMPP or WAMP and now you are ready for rest of the work. Now you have to create a database and import below database file into your database:

temps

But remember that unzip this file first and the import. Now create a folder in root of your server (or as you want) and download following three files and copy and paste it into that folder that you have created. I assumed you created a folder named temperature, so put these three files in temperature folder. Files are here:

temperature.zip

Note:- This is zip file and has three files in it, after extracting files put all three files into temperature folder and also change database connection information into inc.inc file included into zip file. Here is also source code if you don’t want to download files:

Code for inc.inc  

Code for add.php

Code for show.php

Now upload your project to Arduino and open Serial Monitor of Arduino. After a short time you see some information on the screen in which you can find your temporary IP address of Arduino to show up your desired data. It will also show you the status of your code. You can also visit your show.php file via your Local IP to check database entries.

Thanks for reading this tutorial. I hope you enjoyed this tutorial. If you have any question, please feel free to comment and ask any question. See you in next tutorial.

About Muhammad Faryad

Muhammad Faryad is a professional web application developer. He has been working for 5 years in ICE786 Technologies Pvt. Ltd as a Senior Programmer and Developer. You can contact him on facebook at www.facebook.com/tolamangali

6 comments

  1. Hi, it’s great info.
    I tried to follow your example, and my nodemcu with DHT11 is working well and the web shows current temp and humidity data as well. However, those data does not go into mySQL DB.
    I tried to change the String URL (->/pi/home/temperature), but not working.
    I’m using Raspberry pi3 and put its IP address into the sketch code, and I didn’t change inc.inc file (servername, username, etc.)
    Any advices?
    Thank you.

  2. Hi Mohammad

    I have a problem

    Notice: Undefined index: temp in C:\xampp\htdocs\temperature\add.php on line 9

    Notice: Undefined index: humidity in C:\xampp\htdocs\temperature\add.php on line 10
    2018-09-30Error:INSERT INTO temps(temp,humidity,dated,time) VALUES (,,’2018-09-30′,’05:49:51′);
    You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘,’2018-09-30′,’05:49:51′)’ at line 1

    Which is to store data in the database

    thanks a lot

    Mahdi

  3. The measurements stop after a min. or 5. is it possible to make it run continuously without stopping for like a week? also the clock isn’t correct. it is 4 hours to far.

  4. Can i get the schematic diagram on how you setup the DHT11 and NodeMcu?

Leave a Reply

Ad Test

%d bloggers like this: