Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
Chamath Vithanawasam
Published © GPL3+

Dual Location Temperature Monitoring System

Transmit temperature readings via two nRF24L01 transceiver modules using an Arduino Nano and a TTGO T-Display and upload to Thingspeak.

IntermediateFull instructions provided3 hours3,533
Dual Location Temperature Monitoring System

Things used in this project

Hardware components

Nordic Semiconductor nRF24L01 Wireless RF Module
×2
LILYGO® TTGO T-Display ESP32 WiFi and Bluetooth Module Development Board For Arduino 1.14 Inch LCD
×1
Arduino Nano R3
Arduino Nano R3
×1
Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
×2
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

ThingSpeak API
ThingSpeak API
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic for transmitter and receiver

Fritzing based schematic for transmitter and receiver.

Code

Receiver

Arduino
The code used for the TINYGO TTGO T-Display (Receiver)
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI();  // Invoke library, pins defined in User_Setup.h
#include "nRF24L01.h"
#include "RF24.h"
char msg[6];
//You need the altered nRF24L01 library by nhatuan84 (https://github.com/nhatuan84/RF24)
//RF24(uint16_t _cepin, uint16_t _cspin, uint16_t sck, uint16_t miso, uint16_t mosi)
RF24 radio(32, 33, 26, 25, 27);

const uint64_t pipee = 0xE8E8AAFFE122; //Pipe value, must be similar to the value on the transmitting end

#include <OneWire.h> 
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

#include <WiFi.h>
#include "ThingSpeak.h"

//WiFi details
const char* ssid = "[your network SSID (name)]";   // your network SSID (name) 
const char* password = "[your network password]";   // your network password
WiFiClient  client;
unsigned long myChannelNumber = [your channel number]; //your channel number
const char * myWriteAPIKey = "[your write API key]"; //your write API key

//Independant time values
const long printAllTimeI = 5000; //Screen will update every 5 seconds
const long uploadDataII = 1800000; //Data will upload every 30 minutes 

//Previous time values
unsigned long prevTimeI = 0;
unsigned long prevTimeII = 0;

#define TFT_GREY 0x5AEB // We'll need this color for the screen's background

void setup(void){
  Serial.println("Dallas Temperature IC Control Library Demo"); 
  sensors.begin(); 
  
  tft.init();
  tft.setRotation(1);
 
  Serial.begin(115200);
  radio.begin();
  radio.setChannel(2);
  radio.setPayloadSize(7);
  radio.setDataRate(RF24_250KBPS);
  radio.openReadingPipe(1,pipee);
  radio.startListening();

  tft.fillScreen(TFT_BLACK);

  WiFi.mode(WIFI_STA);     
  ThingSpeak.begin(client);  // Initialize ThingSpeak

  mainScreen();
}

void loop(void){
  tft.setTextColor(TFT_WHITE);
  tft.setTextFont(2);

  Serial.print("Requesting temperatures..."); 
  sensors.requestTemperatures();
  Serial.println("DONE\n\n"); 
  
  if (radio.available()){  
    radio.read(msg, 6);      
    Serial.print("External temperature: ");
    Serial.print(msg);
    Serial.println(" C\n");
  }
  else{
    Serial.println("No radio available");
  }

  unsigned long currentTime = millis();
  
  if(currentTime - prevTimeI >= printAllTimeI){
    //tft.fillScreen(TFT_BLACK);
    Serial.print("Internal temperature: "); 
    Serial.print(sensors.getTempCByIndex(0)); 
    Serial.println(" C"); 

    tft.setTextColor(TFT_WHITE, TFT_GREY);
    tft.setCursor(35, 70, 2); //TTGO Internal temperature
    tft.print(sensors.getTempCByIndex(0));
    tft.print(" C");
    tft.setCursor(150, 70, 2); //Nano External temperature
    tft.print(msg);
    tft.print(" C");
    
    prevTimeI = currentTime;
  }

  if(currentTime - prevTimeII >= uploadDataII){
    //Connect or reconnect to WiFi
    if(WiFi.status() != WL_CONNECTED){
      Serial.print("Attempting to connect");
      while(WiFi.status() != WL_CONNECTED){
        WiFi.begin(ssid, password); 
        delay(5000);     
      } 
      Serial.println("\nConnected.");
    }

    //Uploading internal temperature
    int x = ThingSpeak.writeField(myChannelNumber, 1, (sensors.getTempCByIndex(0)), myWriteAPIKey); //TTGO

    if(x == 200){
      Serial.println("Channel 1 Field 1 update successful");
      uploadNotificationTTGO();
    }
    else{
      Serial.println("Problem updating Channel 1 Field 1. HTTP error code " + String(x));
    }

    //Uploading external temperature
    int y = ThingSpeak.writeField(myChannelNumber, 2, msg, myWriteAPIKey); //Nano

    if(y == 200){
      Serial.println("Channel 1 Field 2 update successful");
      uploadNotificationNano();
    }
    else{
      Serial.println("Problem updating Channel 1 Field 2. HTTP error code " + String(x));
    }
   
    prevTimeII = currentTime;
  }
}

void mainScreen(){
  tft.fillScreen(TFT_GREY);
  //range along TTGO sign
  //x 1 - 239
  //y 1 - 134
  //tft.drawRoundRect(x, y, w, h, 5, color);
  tft.setRotation(1);
  tft.setCursor(50, 5, 2);
  tft.setTextColor(TFT_WHITE, TFT_GREY);
  tft.print("2-sensor temp monitor");
  tft.setCursor(45, 40, 2); //left side
  tft.print("TTGO");
  tft.drawRoundRect(5, 30, 110, 100, 5, TFT_BLACK);
  tft.drawRoundRect(6, 31, 108, 98, 5, TFT_BLACK);
  tft.drawRoundRect(7, 32, 106, 96, 5, TFT_BLACK);
  tft.drawRoundRect(8, 33, 104, 94, 5, TFT_BLACK);
  tft.drawRoundRect(9, 34, 102, 92, 5, TFT_BLACK);

  tft.setCursor(165, 40, 2); //right side
  tft.print("Nano");
  tft.drawRoundRect(124, 30, 110, 100, 5, TFT_BLACK);
  tft.drawRoundRect(125, 31, 108, 98, 5, TFT_BLACK);
  tft.drawRoundRect(126, 32, 106, 96, 5, TFT_BLACK);
  tft.drawRoundRect(127, 33, 104, 94, 5, TFT_BLACK);
  tft.drawRoundRect(128, 34, 102, 92, 5, TFT_BLACK);
}

void uploadNotificationTTGO(){
  tft.setTextColor(TFT_GREEN, TFT_GREY);
  tft.setCursor(35, 100, 2);
  tft.print("Uploaded");  
  delay(60000);
  tft.setTextColor(TFT_GREEN, TFT_GREY);
  tft.setCursor(35, 100, 2);
  tft.print("         ");
}

void uploadNotificationNano(){
  tft.setTextColor(TFT_GREEN, TFT_GREY);
  tft.setCursor(155, 100, 2);
  tft.print("Uploaded");
  delay(60000);
  tft.setTextColor(TFT_GREEN, TFT_GREY);
  tft.setCursor(155, 100, 2);
  tft.print("         ");
}

Transmitter

Arduino
The code for the Arduino Nano (Transmitting Device)
#include  <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
char msg[6] = "hello";
RF24 radio(7,8);

const uint64_t pipee = 0xE8E8AAFFE122;

#include <OneWire.h> 
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

void setup(void) {
  Serial.begin(115200);

  Serial.println("Initializing DS18B20 sensor"); 
  sensors.begin(); 
  
  radio.begin();
  radio.setChannel(2);
  radio.setPayloadSize(7);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipee);
}

void loop(void) {
  Serial.print("Requesting temperatures..."); 
  sensors.requestTemperatures(); // Send the command to get temperature readings 
  Serial.println("DONE"); 
  Serial.print("Temperature is: ");
  Serial.print(sensors.getTempCByIndex(0)); // Not using a hexadecimal address, since there is only one sensor  
  Serial.println(" C ");

  dtostrf((sensors.getTempCByIndex(0)), 6, 2, msg);
  
  Serial.print("Sending to receiver...");
  radio.write(msg, 6);
  Serial.println("sent!\n");
  delay(3000);
}

Credits

Chamath Vithanawasam

Chamath Vithanawasam

2 projects • 17 followers
Electronics lover

Comments