Introduction: What Is the TEMPERATURE in My Room?
Have you ever been in one of the following situation.
- Your far staying lovely parents asks you about the weather at your place, in particular what is the TEMPERATURE?
- You can't fall asleep because you feel that your bedroom is very hot and at midnight laying awake on your bed you thing "What is the TEMPERATURE in this hell hole?"
- Last night you had a wonderful sleep and you think "does TEMPERATURE has to do anything with my uninterrupted wonderful sleep? If so what was the TEMPERATURE last night?"
If the answer is 'YES', lets go ahead and create a simple project that lets you answer all of the above questions by just looking at your mobile/computer's screen and makes you look like a TEMPERATURE wizard :).
Step 1: Video
Check out this quick video.
Step 2: What You Will Need to Make This Project?
Following is the list of electronics components you will need :
- NodeMcu - This is a microcontroller board with capability to connect with wifi and much more,
- DHT11 sensor - This is a temperature and humidity sensor with not too great accuracy but will work for us,
- Computer - We will need computer with Arduino IDE installed, to program NodeMcu,
- Mobile phone charger - It will act as power supply for NodeMcu once programming is done and we are ready to monitor temperature,
- USB A to micro B cable (optional) - In case your charger does not have one that is detachable, We need this cable to connect NodeMcu with computer.
- Breadboard and Jumper wires - You will need either one of them to connect DHT11 sensor with NodeMcu.
- Local wifi network - NodeMcu will connect to this network.
Following is the list of software and libraries you will need :
- Arduino IDE - Use this link to download and install IDE(Interactive Development Environment) on your computer, we will use this IDE to program NodeMcu. Once IDE is installed, download and install following libraries.
- Open Arduino IDE, go to File --> preferences and paste 'http://arduino.esp8266.com/stable/package_esp8266com_index.json' in Additional Boards Manager URLs and click OK. Following that go to Tools --> Board --> Boards Manager and search for 'esp8266', look for 'esp8266 by esp8266 community' and install it.
- Next, go to Sketch --> Include Library --> Manage Libraries, search for 'DHT11' and install 'DHT sensor library by Adafruit'.
- Next, again go to Sketch --> Include Library --> Manage Libraries, search for 'Adafruit Unified Sensor' and install 'Adafruit Unified Sensor by Adafruit'.
You might have a question after looking at the component list, 'Where will I be able to see the temperature reading from my temperature sensor?' as we did not include any display component. Answer is that we will be using wifi capabilities of NodeMcu to connect with your local wifi network and get sensor data through a web page served by NodeMcu on request from your computer/mobile.
Once done you have all the dependencies taken care of and we are ready for the next step.
Step 3: Sensor Connection With NodeMcu
You need to make 3 connections between NodeMcu and DHT11 sensor.
- Connect (+) pin of DHT11 to 3V3 pin of NodeMcu,
- Connect (-) pin of DHT11 to GND pin of NodeMcu and
- Connect signal pin of DHT11 sensor (SIG) to D4 pin of NodeMcu.
You can make these connections either using a breadboard or 3 female to female connector cables. Take help of attached images for needed assistance.
That's all the connections you need to make. Now connect your NodeMcu to your computer for the coding part.
Step 4: Arduino Code for the Project
Following is the outline of code that we will be using :
In setup() of arduino code, we :
- Initialise serial, sensor and wifi interfaces. We also initialise temperature data array to a known value. Serial interface allows us to know IP address of NodeMcu once it connects to your local wifi network.
- Following that we initialise server with function it needs to run, once it receives requests from client.
In loop() of arduino code, we :
- Take sensor reading every hour and push that data to temperature data array. You can change the period for sensor reading by modifying 'period' variable at the starting of code.
- Following that we lookout for a client's request.
Download the attached code and upload it to NodeMcu, If you face any error, let me know in comments.
Note- Don't forget to update wifi ssid and password in the code.
Step 5: Result
Once code uploading is done, which will take relatively longer than your usual arduino code. Open up serial monitor through 'Tools --> Serial Monitor' in arduino IDE. Set its baudrate to 115200 and you should see IP address of your NodeMcu.
Now open up browser in your laptop/mobile which is connected to same wifi as NodeMcu is connected to and type in the IP address you just obtained in the URL bar.
You should see the graph similar to one shown in the image. Let me reiterate 'If you face any issue, let me know in the comments'
That is it.
Thanks for reading.
Participated in the