Data Logging & Monitoring Temperature on ThingSpeak - IOT:


1.   Create an account on ThingSpeak.com . It is free for personal use.
      Once you created account, Login to ThingSpeak and create a channel.
      For more info, read the ThingSpeak documentation .



2.  Once you created the channel, you can name it as required.
     Click on Channel Setting Tab, give it a Name and Description.
     There are 8 fields in each channel. One free accound you can have maximum 4 x Channels.
     In this case we are going to use 2 X  DS18B20 Temperature 
sensors.
     So we will use only 2 x fields of the 1st channel. Name the fields as required and tick them.
       Now you can see that there is a automatically generated Channel ID . 



3.  Now you have created the channel.
    Click on Sharing tab and click on the Radio button to make it public.



4.   Next click on API Key tab and copy the Write API Key . Also you can generate
      a new key if you wish. This the unique key needs to write data to the channel.
      Now the channel is ready to accept data. You can write data to each  field of the channel.     



5.  Once you have created the channel, next thing is to upload the data.
    To do this, we use Wemos D1 Mini (ESP32) development board with Wifi.
    Components needed:
      -   1 x  Wemos D1 Mini Wifi Development Board 
      -   2 x  Dallas DS18B20 One Wire Thermo Meter
      -   1 x  TM1637 4 Digit 7-Segment Display
      -   1 x  1K Resistor 


Arduino Code for the Micro-D1 Mini:

//Temperature Monitor on Thingspeak-IOT using DS18B20
//Also using TM1637-4Digit LED Display to display all Temp sensors
//Using 2 x OneWire DS18B20 Temperature 
//Designed by AMP Tech 14/09/2021
//ref https://github.com/milesburton/Arduino-Temperature-Control-Library

//Using the libraries
#include <OneWire.h>
#include <DallasTemperature.h>
#include <TM1637.h>
#include <ESP8266WiFi.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 12
#define TEMPERATURE_PRECISION 9
#define CLK D1        //clock pin for the 7-Segment LED display
#define DIO D2        //DIO pin for the 7-Segment LED display

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
TM1637 tm(CLK, DIO);
WiFiClient client;

// arrays to hold device addresses
DeviceAddress Thermometer1, Thermometer2;
String apiKey = "Your Channel Api Key";   //apikey of Temp Monitor on ThingSpeak-IOT
const char* ssid = "Your WiFi SSID";    //Your wifi SSID
const char* password = "Your WiFi PW";  //Your wifi key  
const char* server = "api.thingspeak.com";
double CurrentMillis = 0;
//String MyString = "";
uint8_t id = 0x00;
float Temp1, Temp2;

//---------------------------------
void setup(void)
{
  Serial.begin(9600);    //Start Serial
  sensors.begin();       // Start up the library
  
  // locate DS18B20devices on the bus
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");
  if (!sensors.getAddress(Thermometer1, 0)) Serial.println("Unable to find address for Device 0");
  if (!sensors.getAddress(Thermometer2, 1)) Serial.println("Unable to find address for Device 1");
  
  sensors.setResolution(Thermometer1, TEMPERATURE_PRECISION); // set the resolution to 9 bit per device
  sensors.setResolution(Thermometer2, TEMPERATURE_PRECISION);
  
  tm.init();            //initialize led display
  tm.set(1);            //set disp brightness to min,because it is powering from D1 mini 3.3V supply
  
  WiFi.begin(ssid, password);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(200);
    tm.display(3, 0);   //Blink Middle bar of Last Digit Wile Wifi establishes
    delay(200);
    tm.display(3, 8);   //Blink Middle bar of Last Digit Wile Wifi establishes
    Serial.print(".");  //Print dots on serial Wile Wifi establishes  
  }  
}
//--------------------------------------
void loop(void)
{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");
  Temp1 = sensors.getTempC(Thermometer1);
  Temp2 = sensors.getTempC(Thermometer2);
  Serial.print("Sensor1 Temperature =");
  Serial.println(Temp1);
  Serial.print("Sensor2 Temperature =");
  Serial.println(Temp2);
  Serial.println();
  id = 10;                    //shows "A"
  Display(Temp1, id);  //display "A" on last dig
  delay(2000);
  id = 11;                    //shows "b"
  Display(Temp2, id);  //display "b" on last dig
  delay(2000);
  //-----------------------------------------------
  if (millis() - CurrentMillis > 20000) { //Thingspeak update every 20 Seconds
    ThingSpeak_Update();                  //ThingSpeak minimum update duration 20sec
    CurrentMillis = millis();
  }      
}
//==============================================
//Displays Temperature on 7-Seg Display
void Display(float data, uint8_t dig3) {
  tm.point(1);                      //7-Segment disp semicolon on
  data = data * 10;
  int temp = data;
  tm.display(0, temp / 100);        //display on dig-0
  tm.display(1, temp / 10 % 10);    //display on dig-1
  tm.display(2, temp % 10);         //display on dig-2
  tm.display(3, dig3);              //display on dig-3 (ID="A" => for Sensor1 or "b" =>Sensor2)
}
//============================================
//routine to update thingspeak web
//for more informatiom refer to tinkspeak website
void ThingSpeak_Update() {
  if (client.connect(server, 80)) {
    String postStr = apiKey;
    postStr +="&field1=";
    postStr +=Temp1;
    postStr +="&field2=";
    postStr +=Temp2;
    postStr +="\r\n\r\n";
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
    Serial.println(postStr);
  }
  client.stop();
}

Arduino Coms Output:


ThingSpeak.com Channel View (Public) : (https://thingspeak.com/channels/324638)




0Comments

For Comment you need to Login


Related Product

ESP8266 ESP-12 ESP-12F CH340G V2 USB WeMos D1-Mini WIFI Development Board

ESP8266 ESP-12 ESP-12F CH340G V2 USB WeMos D1-Mini WIFI Development Board

NodeMCU Lua IOT Board 3.3V With Pins D1 Mini is mini WiFi board based on ESP8266 Compatible with M..

$7.90

DALLAS DS18B20 TO-92 ONE Wire Thermometer Temperature Sensor

DALLAS DS18B20 TO-92 ONE Wire Thermometer Temperature Sensor

DS18B20 is 1-Wire digital temperature sensor from Maxim IC. Reports degrees in Celsius with 9 t..

$2.50

TM1637 4 Digit 7-Segment 0.36 inch RED LED Display Module For Arduino with Serial Driver

TM1637 4 Digit 7-Segment 0.36 inch RED LED Display Module For Arduino with Serial Driver

The module is a 12-foot clock with 4 points of positive digital (0.36 inches) display module driver..

$2.50