Skip to content

Instantly share code, notes, and snippets.

@meech-ward
Last active May 1, 2019 20:25
Show Gist options
  • Save meech-ward/d7974f565113719ab192e5f6bce3e271 to your computer and use it in GitHub Desktop.
Save meech-ward/d7974f565113719ab192e5f6bce3e271 to your computer and use it in GitHub Desktop.
Let's Build a Temperature Sensor with a Raspberry Pi Part 1
const sensor = require('node-dht-sensor');
sensor.read(22, 4, function(err, temperature, humidity) {
if (err) {
console.log("AHHHHHHHH error", err);
return;
}
console.log('temp: ' + temperature.toFixed(1) + '°C, ' + 'humidity: ' + humidity.toFixed(1) + '%');
});

Let's Build a Temperature Sensor with a Raspberry Pi Part 1

Setting Up The Projects

Parts:

Steps

  • Install raspbian...
    • I used the April 2018 image.
  • Wire up the pi to the sensor.
  • Plug in the pi, connect it to your local network, and enable ssh.
  • Install node on the pi.
  • Make sure node is working on the pi.
    • npm install -g cowsay
    • cowsay hi
    • You might need to source ~/.bashrc before nvm works.
  • Setup the node-dht-sensor
    • The instructions are on the link, here's what I did:
      • On the pi, run the following code:
          wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.56.tar.gz
          tar zxvf bcm2835-1.56.tar.gz
          cd bcm2835-1.56
          ./configure
          make
          sudo make check
          sudo make install
        
  • Write the code.
    • Create a new node project, so just mkdir sensor or something.
    • Inside that directory, npm install node-dht-sensor, might take a while.
    • I've included my code in this gist, you can just copy and paste it.
    • Run the app, node app.js
    • 🤗
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment