Assignment 3: Environmental Monitor

 
Schematic-Circuit-01.jpg

For my environmental monitor I used a DHT 11 temperature/humidity sensor and the SSH 1306 OLED display. The code in NodeJs and Cron Job was written so that a reading would be taken every hour, sent to an SQL database via HTTP and displayed.

link to code

The hardware side was very straightforward as the DHT11 sensor outputs digital values (an ADC is not required) via the one-wire protocol (time-based voltage reading). The diagram on the left shows the schematic and circuit wiring.

I decided to have the sensor stick out so that it can access the air beyond the box

I decided to have the sensor stick out so that it can access the air beyond the box

close up of display with the temperature and humidity values last sent

close up of display with the temperature and humidity values last sent

inside wiring

inside wiring

 
data requested from the server. the timestamp marks every top of the hour that it received temperature and humidity values

data requested from the server. the timestamp marks every top of the hour that it received temperature and humidity values

A cron job was set up so that the nodejs code would run the 0th minute of every hour. At first I planned to run the js code forever with the setInterval() function but I learned from my peers that it is not a reliable method because the Pi could reboot at any point. Having cron, a daemon that runs in the background, would ensure that the scheduled task would still run even after random reboots.

To schedule something on the 0th minute of every hour, the cron expression would be: 0 * * * *

final thoughts

I think the biggest challenges I faced with this assignment was with the Pi setup. I’m still getting familiar with NodeJS, the Node Package Manager, raspi-config and the command line interface so it was difficult to figure out what went wrong when things weren’t working. For instance, I did not realize that in the raspi-config you had to enable certain interface options like the Serial, SPI and I2C and it’s not enabled by default like the Arduino.