temperature – Blog eTechPath https://blog.etechpath.com Tue, 03 Jan 2023 12:20:32 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://blog.etechpath.com/wp-content/uploads/2017/08/BrandLogo12-150x150.png temperature – Blog eTechPath https://blog.etechpath.com 32 32 K-Type Thermocouple with MAX6675 module using ESP8266 Node MCU https://blog.etechpath.com/k-type-thermocouple-with-max6675-module-using-esp8266-node-mcu/ https://blog.etechpath.com/k-type-thermocouple-with-max6675-module-using-esp8266-node-mcu/#respond Fri, 24 Jun 2022 10:14:32 +0000 https://blog.etechpath.com/?p=938 In this tutorial, you will learn how to interface MAX6675 thermocouple amplifier module with node MCU ESP8266 and view sensor reading on esp local webserver without using any router.

Table of Contents:

  • Types of temperature sensors
  • MAX6675 HW-550 Module
  • Interfacing MAX6675 with ESP
  • Installing libraries
  • Examples to read temperature from MAX6675

Types of temperature sensors.

There are four measure types of temperature sensors that are commonly used in the industry: RTD, Thermocouples, Thermistor and semiconductor based IC’s. From these four types, we will talk about the Thermocouple temperature sensors in this tutorial.

Thermocouple is a temperature sensor which contains two wires and gives output in millivoltage with respect to junction temperature. This temperature sensor wires also has fixed polarity, So you can not reverse it.

Sensor element of thermocouple is made up of two different types of metals which is joint together at one point. When this point gets heated or cooled, a voltage is created that can be use as reference for temperature calculation.

Max6675 Module:

MAX6675 is k-type thermocouple to digital converter which provides output in SPI serial interface with 12-bit resolution. MAX6675 can measure temperature range from 0°C to 1024°C with the accuracy of 0.25°C

  • Supply Voltage: 3.0V to 6.0V DC
  • Current: 50mA
  • Operating temperature : -20°C to +80°C

Schematic Diagram:

Installing Arduino Libraries:

Examples:

Interfacing MAX6675 with ESP8266 and monitoring temperature in serial monitoring.

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "max6675.h"

int thermoDO = 12;
int thermoCS = 15;
int thermoCLK = 14;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

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

  Serial.println("MAX6675 test");
  // Stabilisation delay for MAX6675 chip
  delay(500);
}

void loop() {
   Serial.print("C = "); 
   Serial.println(thermocouple.readCelsius());
   Serial.print("F = ");
   Serial.println(thermocouple.readFahrenheit());
 
   // There should be at-least 250ms delay between reeds from MAX 6675 
   delay(1500);
}

Interfacing MAX6675 with ESP8266 and monitoring temperature in ESP local webserver.

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include "max6675.h"

const char* ssid     = "MAX6675-Server";
const char* password = "12341234";

int thermoDO = 12;
int thermoCS = 15;
int thermoCLK = 14;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

float t = 0.0;
float f = 0.0;

AsyncWebServer server(80);

unsigned long previousMillis = 0; //will store last time temp was updated

const long interval = 1000;  

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    html {
     font-family: Arial;
     display: inline-block;
     margin: 0px auto;
     text-align: center;
    }
    h2 { font-size: 3.0rem; }
    p { font-size: 3.0rem; }
    .units { font-size: 1.2rem; }
    .temp-labels{
      font-size: 1.5rem;
      vertical-align:middle;
      padding-bottom: 10px;
    }
  </style>
</head>
<body>
  <h2>Max6675 Thermocouple Server</h2>
  <h3>www.eTechPath.com</h3>
  <p>
    <span class="temp-labels">Temperature</span> 
  </p>
   <p>
    <span id="temperature">%TEMPERATURE%</span>
    <sup class="units">&deg;C</sup>
  </p>
  <p>
    <span id="fahrenheit">%FAHRENHEIT%</span>
    <sup class="units">&deg;F</sup>
  </p>
</body>
<script>
setInterval(function ( ) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("temperature").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "/temperature", true);
  xhttp.send();
}, 1000 ) ;

setInterval(function ( ) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("fahrenheit").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "/fahrenheit", true);
  xhttp.send();
}, 10000 ) ;
</script>
</html>)rawliteral";

// Replaces placeholder with sensor values
String processor(const String& var){
 
  if(var == "TEMPERATURE"){
    return String(t);
  }
  else if(var == "FAHRENHEIT"){
    return String(f);
  }
  return String();
}
void setup(){
  Serial.begin(115200);  
  Serial.print("Setting AP (Access Point)…");
  WiFi.softAP(ssid, password);

  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);

  Serial.println(WiFi.localIP());

  // Route for root
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html, processor);
  });
  server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", String(t).c_str());
  });
  server.on("/fahrenheit", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", String(f).c_str());
  });
  server.begin();
} 
void loop()
{  
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) 
  {
    previousMillis = currentMillis;
    // Read Celsius
     float newT = thermocouple.readCelsius();
    if (isnan(newT))
    {
      Serial.println("Failed to read from Thermocouple Sensor!");
    }
    else 
    {
      t = newT;
      Serial.println(t);
    }
      // Read Fahrenheit
      float newF = thermocouple.readFahrenheit();
     if (isnan(newF)) 
     {
      Serial.println("Failed to read from Thermocouple Sensor!");
    }
    else 
    {
      f = newF;
      Serial.println(f);
      Serial.println(WiFi.softAPIP());
    }  
  }
}

Prototype:

]]>
https://blog.etechpath.com/k-type-thermocouple-with-max6675-module-using-esp8266-node-mcu/feed/ 0
How to interface DHT11 DHT22 Temperature sensor with Raspberry Pi https://blog.etechpath.com/how-to-interface-dht11-dht22-temperature-sensor-with-raspberry-pi/ https://blog.etechpath.com/how-to-interface-dht11-dht22-temperature-sensor-with-raspberry-pi/#respond Sun, 21 Nov 2021 21:37:39 +0000 https://blog.etechpath.com/?p=541 About:
In this tutorial i will explain how to interface and program DHT11/22 temperature sensor with Raspberry Pi. I have used adafruit python library to program these sensors in python shell.




Things you will need:
Raspberry Pi (any model will work)
DHT11 or DHT22
4k7 Resistor




Circuit Diagram:

Circuit diagram

Python Code:

#!/usr/bin/python
# Name: DHT11/DHT22Interfacing Temperature sensor with raspberry Pi
# Author: Pranay Sawarkar
# Website: www.etechpath.com
# Copyright: Creative Common

import Adafruit_DHT

# sensor = Adafruit_DHT.DHT22
sensor = Adafruit_DHT.DHT11


# Sensor connected to Raspberry Pi GPIO4.
pin = 4

humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

if humidity is not None and temperature is not None:
    print('Temperature={0:0.1f}*C  Humidity={1:0.1f}%'.format(temperature, humidity))
else:
    print('Failed to capture reading. Please Try again!')

 




Steps:

  1. Connect your temperature sensor to GPIO4 of your raspberry pi  and don’t forget to connect 4k7 pull up resistor between vcc and data output pin. You can use any 4k7 to 10k range resistor for pull up purpose.
  2. Power on your raspberry pi and open terminal.
  3. First we will download and install adafruit library for DHT sensors,
    sudo apt-get update
    git clone https://github.com/adafruit/Adafruit_Python_DHT.git
  4. Install python essential files. (if you are using it for first time)
    sudo apt-get install build-essential python-dev
    sudo python setup.py install
  5. Now your raspberry pi is ready to run the adafruit dht python program,
  6. Copy main python code at home directory in a empty file and name it as dht.py (or download ready dht.py file from download section and copy it to your raspberry pi home directory).
  7. Now you can use bellow command to check the sensor data by running this python program from your raspbery pi terminal,
    sudo python dht.py

    You will get output like this,



 

]]>
https://blog.etechpath.com/how-to-interface-dht11-dht22-temperature-sensor-with-raspberry-pi/feed/ 0
Interfacing TFT LCD ILI9163C & DHT11 Temperature Sensor with STM32F103 32bit Microcontroller https://blog.etechpath.com/interfacing-tft-lcd-ili9163c-dht11-temperature-sensor-with-stm32f103-32bit-microcontroller/ https://blog.etechpath.com/interfacing-tft-lcd-ili9163c-dht11-temperature-sensor-with-stm32f103-32bit-microcontroller/#respond Sat, 23 Feb 2019 08:21:48 +0000 https://blog.etechpath.com/?p=662 About:

In this project i will teach you how to interface ILI9163C TFT LCD  color display module with STM32F103 Arm cortex microcontroller to display DHT11 temperature sensor value.




ILI9163C : It is a 1.44″ color TFT display with SPI interface. This tft comes very cheap but has lot of impressive futures and support very high speed SPI transfer of about 40Mhz. Available in two variants in market, one with the  black pcb and other one with the red pcb. In this project we will use black pcb.

STM32F103: A 32bit arm cortex high speed microcontroller. This is a very cheap, fast & advanced alternative to Arduino and can be program using Arduino IDE with simple USB bootloader. In this project we will use Black Pill STM32F103 board with USB bootloader.

DHT11: A very famous and widely used temperature & humidity sensor. This sensor uses resistive type NTC temperature measurement component with high performance 8bit microcontroller to provide calibrated digital signal output. It has measurement range of 0 to 50 degree Celsius.




Circuit Diagram:

 



Code:

 /* 
* Project: Interfacing TFT LCD ILI9163C & DHT11 Temperature Sensor with STM32F103 32bit Microcontroller 
* Author: Pranay SS, eTechPath 
* Website: www.etechpath.com 
* Tutorial Link: 
* Video Link: 
*/
  
  
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h>
#include <Fonts/FreeSerifItalic9pt7b.h>
#include <dht11.h>
#define RST PB5
#define DC PB6
#define CS PB7


dht11 DHT11;

#define DHT11PIN PC13

// Definition of colours
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0  
#define WHITE   0xFFFF

float xh = 0;
float yh = 0;
int zh; 


TFT_ILI9163C tft = TFT_ILI9163C(CS, DC, RST);  

void setup() {
  tft.begin();
  tft.drawRect(5,70,118,20,WHITE);
  tft.setCursor(22,79);
  tft.setFont(&FreeSerifItalic9pt7b);
  tft.setTextColor(RED);  
  tft.setTextSize(1);
  tft.print("eTechPath");
  tft.setFont();
  tft.setCursor(10,91);
  tft.setTextColor(WHITE);
  tft.print("www.etechpath.com");
  
}

void loop(){

    int chk = DHT11.read(DHT11PIN);
  if(zh != chk)
  {tft.fillRect(00,15,128,8,BLACK);}
  tft.setCursor(5, 5);
  tft.setTextColor(WHITE);  
  tft.setTextSize(1);
  tft.println("Sensor Status");
  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK:
        tft.setCursor(10, 15);
        tft.println("OK");
        Serial.println("OK ");
        break;
    case DHTLIB_ERROR_CHECKSUM:
        tft.setCursor(10, 15);
        tft.println("Checksum Error");
        Serial.println("Checksum error");
        break;
    case DHTLIB_ERROR_TIMEOUT:
        tft.setCursor(10,15);
        tft.println("Time out error");
        Serial.println("Time out error");
        break;
    default:
        tft.setCursor(10,15);
        tft.println("Unknown error");
        Serial.println("Unknown error");
        break;
  }

  float x = DHT11.humidity;
  float y = DHT11.temperature; 

  if (xh != x)
  {tft.fillRect(70,30,30,8,BLACK);
  tft.setCursor(5,30);
  tft.print("Humidity = ");
  tft.print(x);
  tft.println(" (%)");}
  if (yh != y)
  {tft.fillRect(46,50,30,8,BLACK);
  tft.setCursor(5,50);
  tft.print("Temp = ");
  tft.print(y);
  tft.print(" (C) ");}
  Serial.print("Temperature = ");
  Serial.print((float)DHT11.temperature);
  Serial.print(" (C) ");
  delay(500);
  xh = x;
  yh = y;
  zh = chk;
}





Project Images:

Note: Follow bellow tutorial if you want to know, how to burn USB bootloader in STM32 black-pill board.




 

]]>
https://blog.etechpath.com/interfacing-tft-lcd-ili9163c-dht11-temperature-sensor-with-stm32f103-32bit-microcontroller/feed/ 0