WiFi Connected Temperature and Humidity Sensor


This project was our final assignment; an environmental sensor capable of sending data over https to Tom Igoe’s sever. I attempted this project with two different kinds of sensors on a Raspberry Pi Zero W. My first attempt was with the Pimoroni Enviro sensor hat, which required programming in Python, and communicated over the i2c protocol. My second, successful attempt was using a DHT-11 temperature and humidity sensor, with a built-in pull-up resistor, which required programming in Node.js, and communicated over the 1-wire protocol.

I set up my raspberry pi using Tom’s guide.

Attempt 1 – Pimoroni Enviro Hat

The Pimoroni Eniviro Hat came with its own GitHub code, including scripts to run its various sensors. I tried cloning this repository twice, and as I rebooted my pi, my pi crashed both times. I believed my SD card was corrupted both times, and reset my SD card completely both times. Before trying the third time, I backed up a copy of wifi-accessible, set up SD card on my computer.

The third time I cloned the repository, my pi seemed to crash on the reboot again. However, I decided to try to ssh into my pi and it turned out that the files, cloned repository and all, were not corrupted. I tried to run the various pre-programmed files that were supposed to get my sensors to run. The only file that worked was the screen file.

After some unhelpful feedback from the Pimoroni manufacturers, I discovered that my pi was not reading the hat’s sensors over the i2c protocol.

The bottom portion of this code indicates that my pi did not recognize any of the sensor’s pins

After talking to Tito, we figured that the issue was a higher-level computer engineering issue, related to the types of pre-programmed communication protocols my respective hat and pi had. Unsure of how to proceed from here, I decided to go the easier route and use the Node.js based DHT-11 sensor, that my classmate, Cy Kim, was using.

Attempt 2 – DHT-11 Sensor

I. Hardware fallout from enviro

I adapted the code that I used from Tom’s Github repository and the repository for my device. However, I could not return a reading from my sensor.

I took the following steps to debug my circuit:

1. I unit tested my sensor, this gave me back values of 0 for humidity and temperature
2. I checked whether or not I was receiving integer values using a format similar to the temp-humidity-client.js from Tom’s code
3. Tried test examples from my sensor’s repo which do not provide any insight or solutions
4. Used a multimeter (which indicated that my sensor was fine)
5. Swapped out my wires and breadboards

To no avail, frustrated and defeated, I took a break, and when I returned I:

6. Wiped my pi clean of all code, Raspian Lite and all
7. Rewrote and re-downloaded all of the code from scratch
8. In the process, I fried my zero w and switched to my non-wifi zero just to see if I could get a sensor value

I should note that at this step I believe I fried my sensor as well

9. Switched my sensor with Jason Tse
10. Switched my code with Jason Tse

Again, to no avail.

The following day, I arrived with a new sensor and new Raspberry Pi and was almost immediately able to get sensor readings.

II. Functional, but too “chatty”

Once I got my sensors reading, I combined the sensor reading file with a file that was set up to send HTTPS put request strings to Tom’s server.  After sending a get request to make sure that I had sent data to Tom’s server, I attached a SSD1306 display screen and adapted Tom’s code from his pi recipes to get the whole circuit to work.

Then came cron. I spent about an hour trying to figure out why cron would not work – it turns out that I put the wrong path to the file I wanted to run with cron. I then realized that I didn’t want to run my https transmission function with the same frequency as my screen display function, so I separated the two into separate files. I set the screen file to turn on as the device was powered (@reboot) and for my send function to run every 5 minutes (*/5 * * * *). I forgot to check if the latter function was operating at the speed I wanted it to function at, and as a result, accidentally spammed Tom’s server with upwards of 30,000 sensor readings. I’m still unsure why my 5 minute cron function was overridden by the readInterval function that I had written in my function sending code. I am also unsure if I should have written my cron script in the regular cron or sudo cron file, so I wrote my script in both for posterity.

After all of this, I had a device that would display humidity and temperature, and send readings every 15 minutes.

III. Self-Sabotaged in the Finishing Stretch?

I ended up trying to get my network SSID and IP represented on my pi’s screen. My screen transmitted that information, but would only do so by flashing for every update, which I programmed to occur each second.

In trying to debug this, I ended up only being able to get my screen to run when I ran it through ssh. This led me to believe that I was running into transmission speed issues more complicated than I anticipated.

I will consult with Tom Igoe and update my blog to reflect future directions.


  1. In my transmission code, I accidentally changed my set interval to once a second
  2. I did not realize that cron jobs “overlap” – essentially when I ask to run 1 time, the script I want to run will actually run 1 x the interval I set for it to run, each time I asked for it to run.

Finished Product

Here is a final video of my sensor when it was working, a photo of my sensor when it was working, and a link to my GitHub repository for this project.

You May also Like