Wireless Temperature Sensor

About the project

This is a quick and easy Wireless Temperature Sensor. One Espruino reads the temperature from a DS18B20 temperature sensor.

Project info

Difficulty: Easy

Platforms: Espruino

Estimated time: 1 day

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

espruino board espruino board http://www.espruino.com/EspruinoBoard x 2
nRF24L01P-MODULE-PCB nRF24L01P-MODULE-PCB x 1
SEN-11050 SparkFun Accessories Temperature Sensor Waterproof (DS18B20) SEN-11050 SparkFun Accessories Temperature Sensor Waterproof (DS18B20) x 1
4.7k resistor 4.7k resistor x 1
LCD-10168 Display Development Tools Graphic LCD 84x48 Nokia 5110 LCD-10168 Display Development Tools Graphic LCD 84x48 Nokia 5110 x 1

Story

Wiring Up

Board 1 (transmitter)

  • Follow the wiring instructions for wiring up the NRF24L01+ wireless module
  • Connect up the DS18B20 Temperature sensor as follows:

Board 2 (receiver)

Software

Connect to the transmitting Espruino, copy and paste this into the right-hand window, then click the Send to Espruino button.

  1. SPI1.setup({sck:A5, miso:A6, mosi:A7});
  2. var nrf = require("NRF24L01P").connect( SPI1, B0, B1 );
  3. var ow = new OneWire(A1);
  4. var sensor = require("DS18B20").connect(ow);
  5. function onInit() {
  6. nrf.init([0,0,0,0,2], [0,0,0,0,1]);
  7. }
  8. onInit();
  9. setInterval(function() {
  10. var temperature = sensor.getTemp();
  11. nrf.sendString(""+temperature);
  12. }, 10000);

Now, connect to the second (receiving) Espruino, and copy and paste this in:

  1. SPI1.setup({sck:A5, miso:A6, mosi:A7});
  2. var nrf = require("NRF24L01P").connect( SPI1, B0, B1 );
  3. SPI3.setup({ baud: 1000000, sck:B3, mosi:B5 });
  4. var g;
  5. function onInit() {
  6. nrf.init([0,0,0,0,1], [0,0,0,0,2]);
  7. // We set up the LCD here because it needs to initialise at power on
  8. g = require("PCD8544").connect(SPI3,B6,B7,B8);
  9. }
  10.  
  11. // Draw temperature onto the LCD
  12. function showTemperature(temp) {
  13. g.clear();
  14. g.setFontBitmap();
  15. g.drawString("Temp",1,0);
  16. g.drawLine(0,10,84,10);
  17. g.setFontVector(20);
  18. g.drawString(temp,1,15);
  19. g.flip();
  20. }
  21.  
  22. // Keep checking to see if we have any new data...
  23. dataLine = "";
  24. setInterval(function() {
  25. while (nrf.getDataPipe() !== undefined) {
  26. var data = nrf.getData();
  27. for (var i in data) {
  28. var ch = data[i];
  29. if (ch===0 && dataLine!=="") {
  30. // if we got a 0 (end of string), show what we got
  31. showTemperature(dataLine);
  32. dataLine = "";
  33. } else if (ch!==0) {
  34. dataLine += String.fromCharCode(ch);
  35. }
  36. }
  37. }
  38. }, 50);
  39.  
  40. onInit();

About 10 seconds later the display should update with the temperature received from the sender...

And that's it! A wireless temperature sensor. This could be extended with the code from the Heater Controller to make a wireless themostat, a history graph could be drawn, more than one wireless temperature sensor could be used or data could be logged onto an SD card...

Code

Main Code 1

Main Code 2

Credits

Photo of Espruino

Espruino

Espruino, Espruino Pico and Puck.js are low-power Microcontrollers that run JavaScript. Espruino is a JavaScript Interpreter for Microcontrollers that is designed to make development quick and easy. The Espruino interpreter is firmware that runs on a variety of different microcontrollers, but we also make Espruino Boards that come with the interpreter pre-installed and are the easiest devices to get started with. However Espruino itself isn't just the interpreter firmware or hardware - there's also the Web IDE, command-line tools, documentation, tutorials, and modules that form a complete solution for embedded software development.

   

Leave your feedback...