Temperature with arduino nodemcu

Read temperature and humidity with arduino nodemcu

Temperature arduino nodemcu

Temperature control is actually a 101 automation. It receives as input data from environment and converts it to digital data which we can process and use it to control an overall system.

If you don’t want to read everything, just watch the video below, but it is always fun to learn something new. Don’t you think?

We will present you an automation that reads temperature and humidity with the use of the following components.

  • Nodemcu
  • DHT22
  • Wires
  • Breadboard

Nodemcu

έλεγχος θερμοκρασίας με arduino
image 1 – nodemcu pinout

Microcontroller nodemcu is an “arduino” along with WiFi. It is an anternative in case you don’t want to use an arduino with esp8266 which is pain in the ass if you know what i mean or an arduino wifi shield which is quite expensive.

Nodemcu is 2 in 1. Besides the CH340G microcontroller, there is also present a esp8266 chip which allows you to connect to any WiFi or to create your own server.

The size is same as arduino nano but with the plus that has a wifi module attached to it.

You can see the pinout at image 1. Also there are 2 buttons, one for reset and the other for memory flash.

The connection with the computer is achieved through USB micro-b type

You must be carefull. While i was testing this i noticed that if i used more than 2meters cable it was not working as stable. I cannot tell you 100% whether it was a port issue or a cable issue.

nodemcu WiFi
image 2 – nodemcu WiFi

DHT11 / DHT22 temperature – humidity sensor

Temperature and Jumidity sensors. It comes in two editions. 3 pin and 4 pin. difference is that the 4 pin sensor has a NC contact (Normal Close). Something like a relay.

Inside there is a capacitive sensor and a thermistor. Thanks to these two components we can measure humidity and temperature.

For our example we are going to use the 3 pin sensor to measure temperature and humidity.

At the following image you see the sensor pinout. Pins are explained at most cases on the sensor so you can’t get this wrong when connecting the sensor.

Αισθητήρας θερμοκρασίας - υγρασίας
image 3 – Temperature – Humidity Sensor DHT22

I got this sensor from ebay very very cheap. I recommend if you buy, don’t buy just one but two or three. In case something goes wrong or you get a defective sensor (sh#t happens)


Circuit

For the wiring, thins are pretty simple. see the image below.

The signal cable is going to work at pin D3 but you can change that with programming.

έλεγχος θερμοκρασίας με arduino
εικ. 4 – σύνδεση

Setting up nodemcu to Arduino IDE

In order to get nodemcu to work with arduino IDE you must do some preperation first. This will be done only once!.

  1. File –> preferences where it says “additional URLs board manager, paste the link below διεύθυνση http://arduino.esp8266.com/stable/package_esp8266com_index.json
  2. Next, design->include library-> library manager
  3. Type on filter ‘ESP8266’ and install the esp8266 library.

After it installs you are ready if you go to board selection you have the option ‘nodemcu 0.9’ board which we will pick for our example.

Libraries

In order to run the code you must have the libraries installed to your arduino IDE. You can download the two libraries from the links below that cover up to 100% of the sensors out there.

You should install these folders (after you unzip them) to the subfolder Libraries where the IDE is installed:

C:\Program Files (x86)\Arduino\Libraries

Throw in the files to a folder named DHT.

Code

We give you the following code that is fully operational. Don’t forget to download first the libraries.

#include "DHT.h"        // including the library of DHT11 temperature and humidity sensor
#define DHTTYPE DHT22   // DHT 22
#define dht_dpin 0
DHT dht(dht_dpin, DHTTYPE); 
void setup(void)
{ 
 dht.begin();
 Serial.begin(9600);
 Serial.println("Humidity and temperature\n\n");
 delay(700);

}
void loop() {
   //float h = dht.readHumidity();
   float t = dht.readTemperature();         
   //Serial.print("Current humidity = ");
   //Serial.print(h);
   //Serial.println("%  ");
   Serial.print("Current temperature = ");
   Serial.print(t); 
   Serial.println("C ");
 delay(3500);
}

If you open the serial commucation after you upload the code you can see the temperature and humidity readings.

November 13, 2019

0 responses on "Temperature with arduino nodemcu"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Σχεδιασμός © GetCert. Με επιφύλαξη παντός δικαιώματος.