Home‎ > ‎

Arduino Temperature and Humidity Logger

Arduinos are used by many Hams for APRS Weather Station applications and other station automation apps. I had no experience with the Arduino so I jumped at the chance to learn something new when I had a real world application.

I recently moved to a house built in 1996 and it is in dire need of updates and maintenance due to neglect. One of the major problems is excessive moisture in the crawlspace. One way to solve this problem is to encapsulate the crawlspace and use a dehumidifier to regulate the humidity. I did some preliminary encapsulation and needed a way to monitor the temperature and humidity so I could get a baseline and know the extent of the problem.

The goal was to create a method of logging temperature and humidity every 10 minutes at multiple locations. I decided to monitor the attic in addition to the crawlspace.

The hardware for this project is an Arduino Uno with an Ethernet Shield and interfaces to the temperature and humidity sensors. The Arduino publishes the data to an MQTT broker running on a Raspberry Pi.

Arduino Hardware

The hardware consists of a stock Arduino Uno, an Ethernet Shield and a custom interface to two DHT22 sensors. You will also need some headers soldered on the interface board to plug into the Ethernet Shield.

The Arduino Uno is on the bottom, the Ethernet Shield is in the middle and the interface board is on top. The sensor interface board will accommodate four sensors, but I am currently only using two.

Click on the image above to view it full size. The PCB image is 600 dpi and if printed properly on Mylar, you can create the PC Boards necessary for this project. Included in the image is the Arduino interface board, nine temperature / humidity sensor boards (only two are used in this project) and two gas sensor boards (not used in this project). Feel free to edit out my call sign or cut and paste the individual boards to suit your needs.

The interface board and the sensor boards use vertical RJ-45 connectors and the cable connecting them is a standard ethernet cable.

The Arduino Code:

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>

#include <DHT.h>
DHT dht;
#define DHTaPIN 2
#define DHTbPIN 3

char chartemp [20] ;
char charhumid [20] ;

// Update these with values suitable for your network.
byte mac[]    = {  0x00, 0x50, 0x56, 0xFE, 0x09, 0x08 };
IPAddress ip(192, 168, 254, 98);
IPAddress server(192, 168, 254, 103);

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print("] ");
  for (int i=0;i<length;i++) {

EthernetClient ethClient;
PubSubClient client(ethClient);

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    //Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("arduinoClient")) {
      // Once connected, publish an announcement...
      //client.publish("house/attic/temp","hello world");
      // ... and resubscribe
    } else {
      //Serial.print("failed, rc=");
      //Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying

void setup()

  client.setServer(server, 1883);

  Ethernet.begin(mac, ip);
  // Allow the hardware to sort itself out

void loop()
  if (!client.connected()) {

  dht.setup(DHTaPIN); // data pin 2

  float humidity = dht.getHumidity();
  float temperature = dht.getTemperature();
  temperature = ((temperature *9 / 5) + 32);

  Serial.print(humidity, 1);
  Serial.println(temperature, 1);

  dht.setup(DHTbPIN); // data pin 3

  float humidity2 = dht.getHumidity();
  float temperature2 = dht.getTemperature();
  temperature2 = ((temperature2 *9 / 5) + 32);

  Serial.print(humidity, 1);
  Serial.println(temperature, 1);


You will need to change the code to reflect the MAC address of your Ethernet Shield, the I.P. addresses of the Arduino and the MQTT broker and perhaps the MQTT topics.
Hopefully I have provided enough detail to get you started. If you have any questions, contact me.