arduino – Blog eTechPath https://blog.etechpath.com Sun, 23 Apr 2023 21:03:56 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://blog.etechpath.com/wp-content/uploads/2017/08/BrandLogo12-150x150.png arduino – Blog eTechPath https://blog.etechpath.com 32 32 DIY Weighing Scale using HX711, OLED i2c display and ESP8266 NodeMCU with Zero Calibration Function https://blog.etechpath.com/diy-weighing-scale-using-hx711-oled-i2c-display-and-esp8266-nodemcu-with-zero-calibration-function/ https://blog.etechpath.com/diy-weighing-scale-using-hx711-oled-i2c-display-and-esp8266-nodemcu-with-zero-calibration-function/#respond Sun, 23 Apr 2023 21:03:26 +0000 https://blog.etechpath.com/?p=1254 Introduction:

In this tutorial you will learn how to interface HX711 loadcell amplifier module with ESP8266 NodeMCU board and getting output on i2c OLED display. Also, we will learn how to add zero push button function to adjust scale offset.

Loadcell:

Load cell is a sensor which converts mechanical force into electronic signal. Where the mechanical force can be tension, pressure, compression or torque. There are many types of load cells are available in the market which can be used as per required application. In this example we are going to use strain gauge load cell for converting mechanical force into electrical signal.

Loadcell consist of several resistive strain gauge sensor elements which changes its resistance when the load is applied and gives output in milli volts when input or excitation voltage is applied to it.
This milli volt output is then amplified to voltage signal to make it compatible with controllers to read and convert to load units.

Things You Will Need:

  • ESP8266 NodeMCU
  • HX711 Amplifier Board
  • 10kg Loadcell
  • i2c OLED Display
  • Connecting Cables

Circuit Diagram:

Code:

Example 1: ln this example we will use Arduino IDE serial monitor window to get output values from the loadcell.

/**
 *
 * Interfacing 10kg loadcell and HX711 amplifier board with ESP8266 NodeMCU
 * Author: Pranay Sawarkar
 * Website: www.eTechPath.com
 * Link: https://blog.etechpath.com/diy-weighing-scale-using-hx711-oled-i2c-display-and-esp8266-nodemcu-with-zero-calibration-function/
 * 
 *
**/

#include <Arduino.h>
#include "HX711.h"

// HX711 circuit wiring
const int Dout_Pin = 14;
const int SCK_Pin = 12;
const int pb1 = 13;            //push button input 
int tarepb = 0;
int newread = 0;
#define CalFactor 235.5    //enter your calibration factor here

HX711 scale;

void setup() {
  Serial.begin(115200);
  scale.begin(Dout_Pin, SCK_Pin);
  pinMode(pb1, INPUT_PULLUP);
  
  Serial.println("Initialization..."); 
  
  scale.set_scale(CalFactor);
  scale.tare();
  delay (200);
  Serial.println("Ready");
  delay (100);
}

void loop() {
  
  tarepb = digitalRead(pb1);
  delay(10);
  if (tarepb == LOW) 
  {
    scale.tare();
    Serial.println("TareDONE");
  }
  else
  { 
  newread = scale.get_units(5);
  Serial.println("Weight: ");
  Serial.println(newread);
  delay(10);
   }
}

Circuit Diagram:

Example 2: In this example we will interface oled display with the existing circuit and print loadcell output values on display.

/**
 *
 * DIY Weighing Scale using HX711, OLED i2c display and ESP8266 NodeMCU with Zero Calibration Function
 * Author: Pranay Sawarkar
 * Website: www.eTechPath.com
 * Link: https://blog.etechpath.com/diy-weighing-scale-using-hx711-oled-i2c-display-and-esp8266-nodemcu-with-zero-calibration-function/
 * 
 *
**/

#include <Arduino.h>
#include <U8g2lib.h>
#include "HX711.h"

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

//select your oled display size
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

// HX711 circuit wiring
const int Dout_Pin = 14;
const int SCK_Pin = 12;
const int pb1 = 13;
//const int pb2 = 5;
int tarepb = 0;
int newread = 0;
#define CalFactor 235.5

//235.5


HX711 scale;

void setup() {
  Serial.begin(115200);
  u8g2.begin();
  scale.begin(Dout_Pin, SCK_Pin);
  pinMode(pb1, INPUT_PULLUP);
  
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.drawStr(0, 20, "Initializing...");
  u8g2.sendBuffer();
  
  scale.set_scale(CalFactor);
  scale.tare();
  delay (500);
  u8g2.clearBuffer();
  u8g2.drawStr(0, 20, "Ready");
  u8g2.sendBuffer();
  delay (100);
 
}

void loop() {
  
  tarepb = digitalRead(pb1);
  delay(10);
  if (tarepb == LOW) 
  {
    scale.tare();
    u8g2.clearBuffer();
    u8g2.drawStr(0, 20, "Tare Done");
    Serial.println("TareDONE");
    u8g2.sendBuffer();
  }
  else
  {
  
  newread = scale.get_units(5);
  Serial.println(newread);
  delay(10);

      u8g2.clearBuffer();
      u8g2.setFont(u8g2_font_6x10_tf);
      u8g2.drawStr(0, 20, "Weight: ");
      u8g2.setCursor(45, 20);
      u8g2.print(newread);
      u8g2.sendBuffer();
      delay(10);
    
   }
}

Prototype:

]]>
https://blog.etechpath.com/diy-weighing-scale-using-hx711-oled-i2c-display-and-esp8266-nodemcu-with-zero-calibration-function/feed/ 0
DIY OLED Weighing Scale using 10kg Loadcell with HX711 and Arduino Uno https://blog.etechpath.com/diy-oled-weighing-scale-using-10kg-loadcell-with-hx711-and-arduino-uno/ https://blog.etechpath.com/diy-oled-weighing-scale-using-10kg-loadcell-with-hx711-and-arduino-uno/#respond Fri, 21 Apr 2023 13:00:06 +0000 https://blog.etechpath.com/?p=1240 Introduction:

In this tutorial you will learn how to interface HX711 loadcell amplifier board with Arduino uno and getting output on i2c oled display. Also, we will learn how to add calibration push button to zeroing the scale.

Loadcell:

Load cell is a sensor which converts mechanical force into electronic signal. Where the mechanical force can be tension, pressure, compression or torque. There are many types of load cells are available in the market which can be used as per required application. In this example we are going to use strain gauge load cell for converting mechanical force into electrical signal.

Loadcell consist of several resistive strain gauge sensor elements which changes its resistance when the load is applied and gives output in milli volts when input or excitation voltage is applied to it.
This milli volt output is then amplified to voltage signal to make it compatible with controllers to read and convert to load units.

Things You Will Need:

  • Arduino Uno
  • 10kg Loadcell
  • HX711 ADC amplifier board
  • i2c OLED display

Circuit Diagram:

Code:

Example 1: In this example we will use arduino serial window to get output values from the loadcell.

/**
 *
 * Interfacing 10kg loadcell and HX711 amplifier board with Arduino Uno
 * Author: Pranay Sawarkar
 * Website: www.eTechPath.com
 * Link: https://blog.etechpath.com/diy-oled-weighing-scale-using-10kg-loadcell-with-hx711-and-arduino-uno/
 * 
 *
**/

#include <Arduino.h>
#include "HX711.h"

// HX711 circuit wiring
const int Dout_Pin = 2;
const int SCK_Pin = 3;
const int pb1 = 4;
int tarepb = 0;
int newread = 0;
#define CalFactor 235.5    //enter your calibration factor here

HX711 scale;

void setup() {
  Serial.begin(115200);
  scale.begin(Dout_Pin, SCK_Pin);
  pinMode(pb1, INPUT_PULLUP);
  
  Serial.println("Initialization..."); 
  
  scale.set_scale(CalFactor);
  scale.tare();
  delay (200);
  Serial.println("Ready");
  delay (100);
}

void loop() {
  
  tarepb = digitalRead(pb1);
  delay(10);
  if (tarepb == LOW) 
  {
    scale.tare();
    Serial.println("TareDONE");
  }
  else
  { 
  newread = scale.get_units(5);
  Serial.println("Weight: ");
  Serial.println(newread);
  delay(10);
   }
}

Circuit Diagram:

Example 2: In this example we will interface oled display with the existing circuit and print loadcell output values on it.

/**
 *
 * DIY Weighing scale using 10kg loadcell and HX711 amplifier board with Arduino Uno and OLED display
 * Author: Pranay Sawarkar
 * Website: www.eTechPath.com
 * Link: https://blog.etechpath.com/diy-oled-weighing-scale-using-10kg-loadcell-with-hx711-and-arduino-uno/
 * 
 *
**/

#include <Arduino.h>
#include <U8g2lib.h>
#include "HX711.h"

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

//select your oled display type and size
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

// HX711 circuit wiring
const int Dout_Pin = 2;
const int SCK_Pin = 3;
const int pb1 = 4;
int tarepb = 0;
int newread = 0;
#define CalFactor 235.5   //enter your calibration factor here

HX711 scale;

void setup() {
  Serial.begin(115200);
  u8g2.begin();
  scale.begin(Dout_Pin, SCK_Pin);
  pinMode(pb1, INPUT_PULLUP);
  
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.drawStr(0, 20, "Initializing...");
  u8g2.sendBuffer();
  
  scale.set_scale(CalFactor);
  scale.tare();
  delay (500);
  u8g2.clearBuffer();
  u8g2.drawStr(0, 20, "Ready");
  u8g2.sendBuffer();
  delay (100);
 
}

void loop() {
  
  tarepb = digitalRead(pb1);
  delay(10);
  if (tarepb == LOW) 
  {
    scale.tare();
    u8g2.clearBuffer();
    u8g2.drawStr(0, 20, "Tare Done");
    Serial.println("TareDONE");
    u8g2.sendBuffer();
  }
  else
  {
  
  newread = scale.get_units(5);
  Serial.println(newread);
  delay(10);

      u8g2.clearBuffer();
      u8g2.setFont(u8g2_font_6x10_tf);
      u8g2.drawStr(0, 20, "Weight: ");
      u8g2.setCursor(45, 20);
      u8g2.print(newread);
      u8g2.sendBuffer();
      delay(10);
    
   }
}

Prototype:

]]>
https://blog.etechpath.com/diy-oled-weighing-scale-using-10kg-loadcell-with-hx711-and-arduino-uno/feed/ 0
Interfacing MPX5010DP Pressure Sensor with Arduino https://blog.etechpath.com/interfacing-mpx5010dp-pressure-sensor-with-arduino/ https://blog.etechpath.com/interfacing-mpx5010dp-pressure-sensor-with-arduino/#respond Sat, 08 Apr 2023 19:38:36 +0000 https://blog.etechpath.com/?p=1209 Introduction:

In this tutorial we will learn how to interface a MPX5010 pressure sensor with Arduino uno using onboard analog input pin A1 and generate output of sensor on serial monitor for testing then in second example we will print the sensor output on i2c OLED display using u8g2 monochrome graphics library.

MPX5010 Pressure Sensor:

  • Working voltage: 4.75v – 5.25v
  • Working pressure: 0 – 10 kPa
  • Current: 10mA max
  • Working Temperature: -40°C-125°C (0-85°C).
  • Output: 0.2vdc to 4.7vdc

MPX5010 Sensor Output Calculation and Chart:

Things you will need:

  • Arduino Uno or any Arduino board with a spare analog input.
  • MPX5010 pressure sensor.
  • SSD1306 i2c OLED display.

Circuit Diagram:

Example Code 1:

/*
 Project: Interfacing MPX5010DP with Arduino Uno.
 Project Link: 
 Website: www.etechpath.com
 Author: Pranay Sawarkar
*/

#include <Arduino.h>


void setup() {
  // initialize serial communication at 9600 bps
  Serial.begin(9600);
}

void loop() {
  // read the sensor input on analog pin 1
  int sensorValue = analogRead(A1);
  // Convert the analog reading of A1 from 0-1023 to a voltage 0-5V
  float voltage = sensorValue * (5.0 / 1023.0);
  float outputkPa = fmap(voltage, 0.2, 4.7, 0, 10);
  float outputmmH2O = fmap(voltage, 0.2, 4.7, 0, 1019.78);
  // print out the values on serial monitor
  Serial.print("Volt: ");
  Serial.println(voltage);
  Serial.print("kPa: ");
  Serial.println(outputkPa);
  Serial.print("mmH2O: ");
  Serial.println(outputmmH2O);
  Serial.println();
  delay(200);
}

float fmap(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Example Code 1 Output:

Installing Required Library:

  • Goto Sketch -> Include Library -> Manage Libraries (or Shortcut Cntl+Shift+I)
  • Search u8g2 in search bar
  • Select library U8g2 by Oliver
  • Select latest version from dropdown menu and install. (For this project we are using version 2.31.2)

Example Code 2:

/*
 Project: Interfacing MPX5010DP with Arduino Uno and OLED i2c display.
 Project Link: 
 Website: www.etechpath.com
 Author: Pranay Sawarkar
*/

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

//select your oled display size
//U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup() {
  // initialize serial communication at 9600 bits per second
  Serial.begin(9600);
  u8g2.begin();
}

void loop() {
  // read the sensor input on analog pin 1
  u8g2.clearBuffer();
  int sensorValue = analogRead(A1);
  // Convert the analog reading of A1 from 0-1023 to a voltage 0-5V
  float voltage = sensorValue * (5.0 / 1023.0);
  float outputkPa = fmap(voltage, 0.2, 4.7, 0, 10);
  //float outputmmH2O = fmap(voltage, 0.2, 4.7, 0, 1019.78);
  delay(50);
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.drawStr(0, 10, "volt:");
  u8g2.setCursor(35, 10);
  u8g2.print(voltage);
  Serial.print("Volt: ");
  Serial.println(voltage);
  u8g2.drawStr(0, 22, "kPa:");
  u8g2.setCursor(35, 22);
  u8g2.print(outputkPa);
  Serial.print("kPa: ");
  Serial.println(outputkPa);
  u8g2.sendBuffer();
  delay(50);
  
}

float fmap(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Example Code 2 Output:

]]>
https://blog.etechpath.com/interfacing-mpx5010dp-pressure-sensor-with-arduino/feed/ 0
Interfacing SHARP 2Y0A21 Distance Sensor with Arduino https://blog.etechpath.com/interfacing-sharp-2y0a21-distance-sensor-with-arduino/ https://blog.etechpath.com/interfacing-sharp-2y0a21-distance-sensor-with-arduino/#respond Tue, 21 Feb 2023 08:44:53 +0000 https://blog.etechpath.com/?p=1201 Introduction:

In this tutorial, I will explain how to interface SHARP 2Y0A21 infrared distance sensor with Arduino board and display the output in serial monitor.

SHARP 2Y0A21

SHARP 2Y0A21 sensor works on infrared technology, it consists of a transmitter and a receiver diode which calculates the distance between the sensor and the target by measuring time interval between transmitted and received wave.

SHARP infrared distance sensor
SHARP 2Y0A21 Sensor Specifications:
  1. Working voltage: 4.5 – 5.5 Vdc
  2. Distance measuring range: 10cm – 80cm (10cm dead band)
  3. Output type: Analog (voltage)
  4. Output: 0 to 3.1v (3.1v at 10cm to 0.3v at 80cm)
  5. Operating Temperature: -10 to +60 °C (Storage: -40 to +70 °C)

Circuit Diagram:

Code:

//SHARP 2Y0A21 IR Distance Sensor Test (10-80cm) 
// Author: Pranay Sawarkar
// www.eTechPath.com

#define sensor A2 

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  float volts = analogRead(sensor)*0.0048828125;
  int distance = 30*pow(volts, -1.173);
  delay(1000); 
  
  if ((distance >=10)&&(distance <=80))
  {
    Serial.print("Distance:");
    Serial.println(distance);
    Serial.print("Volts:");
    Serial.println(volts);   
  }
  else
  Serial.println("Out of range");
}
]]>
https://blog.etechpath.com/interfacing-sharp-2y0a21-distance-sensor-with-arduino/feed/ 0
Water Tank Level Automation using ESP8266 and HC-SR04 Ultrasonic Sensor. https://blog.etechpath.com/water-tank-level-automation-using-esp8266-and-hc-sr04-ultrasonic-sensor/ https://blog.etechpath.com/water-tank-level-automation-using-esp8266-and-hc-sr04-ultrasonic-sensor/#respond Tue, 18 Oct 2022 09:47:57 +0000 https://blog.etechpath.com/?p=976

About:

In this tutorial, we will learn how to interface hc-sr04 ultrasonic sensor with ESP8266 module and display the water tank level on mobile browser.

Table of Contents:

  • HC-SR04 Module
  • How Ultrasonic sensor works
  • Interfacing sensor module with NodeMCU
  • Programming NodeMCU with ArduinoIDE

HC-SR04 Module and How it works

HC-SR04 is an Ultrasonic sensor module which includes ultrasonic transmitter, receiver and control circuit in single compact PCB.  HC-SR04 has distance measurement ability ranging from 2cm to 400cm. These small units are very accurate, and its accuracy can be reach up to 3mm.

Ultrasonic modules work on the principle similar to radar or sonar- sensors. It generates high frequency signals from the transmitter of about 40kHz towards the sensing object and receives echo signal back to the receiver. Then we can calculate object distance using time interval between the sending of signal and the receiving of echo pulse.

Circuit Diagram:

Libraries:

Code:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <HCSR04.h>

const char* ssid     = "WaterLevel"; //Access point ssid
const char* password = "12341234";   //Access point password

float l = 0.0;
float per = 0.0;
float fcm = 0;
//Rectangular Tank dimentions in cm
float lcm = 200;  //Length
float bcm = 200;    // width
float hcm = 130;  // Height, from Sensor to tank bottom

HCSR04 ultrasonicSensor(D6, D5, 20, 300);
AsyncWebServer server(80);
unsigned long previousMillis = 0;
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; Color:DodgerBlue; }
    h3 { font-size: 1.5rem; Color:Tomato; }
    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>Water Tank Level</h2>
  <h3>www.eTechPath.com</h3>
  <p>
    <span id="permap">%PERMAP%</span>
    <sup class="units">%</sup> 
  </p>
   <p>
   <span id="liter">%LITER%</span>
    <sup class="units">Liters</sup>
  </p>
      <p>
    <span id="distance">%DISTANCE%</span>
    <sup class="units">Cm</sup>
  </p>
</body>
<script>
setInterval(function ( ) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("permap").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "/permap", true);
  xhttp.send();
}, 1000 ) ;
setInterval(function ( ) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("liter").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "/liter", true);
  xhttp.send();
}, 1000 ) ;
setInterval(function ( ) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("distance").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "/distance", true);
  xhttp.send();
}, 1000 ) ;
</script>
</html>)rawliteral";

// Replaces placeholders with sensor values
String processor(const String& var){
 
  if(var == "DISTANCE"){
    return String(fcm);
  }
  else if(var == "LITER"){
    return String(l);
  }
  else if(var == "PERMAP"){
    return String(per);
  }
  return String();
}
void setup(){
  Serial.begin(115200);  
  ultrasonicSensor.begin(); 
  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("/permap", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", String(per).c_str());
  });
  server.on("/liter", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", String(l).c_str());
  });
  server.on("/distance", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", String(fcm).c_str());
  });
  server.begin();
} 
void loop()
{  
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) 
  {
    previousMillis = currentMillis;
     float newdistance = ultrasonicSensor.getMedianFilterDistance(); //pass 3 measurements through median filter, better result on moving obstacles
    if (newdistance != HCSR04_OUT_OF_RANGE)
    {
      Serial.print("sensor raw value:");
      Serial.println(newdistance);
      fcm = hcm - newdistance;
      float v = fcm * lcm * bcm ;
      l = v / 1000;
      per = map(fcm, 0, hcm, 0, 100);
      Serial.println(per);
      Serial.println(l);
      Serial.println(fcm);     
    }
    else 
    {
      Serial.println(F("out of range"));
    }     
  }
}

Video:

]]>
https://blog.etechpath.com/water-tank-level-automation-using-esp8266-and-hc-sr04-ultrasonic-sensor/feed/ 0
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
Setup ESP8266 Filesystem (SPIFFS) Uploader in Arduino IDE https://blog.etechpath.com/setup-esp8266-filesystem-spiffs-uploader-in-arduino-ide/ https://blog.etechpath.com/setup-esp8266-filesystem-spiffs-uploader-in-arduino-ide/#respond Tue, 14 Apr 2020 19:43:49 +0000 https://blog.etechpath.com/?p=842

Overview:

SPIFFS is Serial Peripheral Interface Flash File System which is designed for microcontrollers with flash chip, ESP8266 is one of those microcontroller. In this tutorial we will learn how to flash data in ESP8266 filesystem using Arduino IDE plugin.

Using SPIFFS with ESP8266 board you can do several useful things like saving data in file system permanently without using separate memory chip, save html and css file to build a web server, save images and icons for interactive webpage.

Parts Required:

  • ESP8266 Node MCU with data cable
  • Arduino IDE with latest ESP8266 library

Procedure:

  • Install latest Arduino IDE in your computer if it is not installed yet. You can download the latest version from Arduino site directly or from this Link.
  • Install latest ESP8266 library into your Arduino IDE. Please follow the link for detailed procedure.
  • Go to ESP8266 filesystem download page on github and download filesystem zip file as shown in bellow image, ESP8266FS Link.
  • Open Arduino IDE directory and locate tools folder in it. In most of the cases in Windows system your directly will be same as bellow,
  • Unzip the downloaded file in tools folder as it is, do not rename or change location of jar file, it should be same as shown in bellow image.
  • If you don’t find tools folder under Arduino folder, then make one with correct spell (tools) and paste downloaded unzipped folder in it.
  • That’s it, you are ready to go now. Restart your Arduino IDE and check if the plugin was successfully installed. Click on Tools menu in Arduino IDE and check that you have the option ESP8266 Sketch Data Upload in drop-down list.
]]>
https://blog.etechpath.com/setup-esp8266-filesystem-spiffs-uploader-in-arduino-ide/feed/ 0
Mini GPS Display using Ublox neo-6m module and ESP8266 nodemcu https://blog.etechpath.com/mini-gps-display-using-ublox-neo-6m-module-and-esp8266-nodemcu/ https://blog.etechpath.com/mini-gps-display-using-ublox-neo-6m-module-and-esp8266-nodemcu/#respond Fri, 30 Nov 2018 07:42:12 +0000 https://blog.etechpath.com/?p=681


About:

In this project we will learn how to interface GPS module with esp8266 as main controller to show GPS data on OLED display. We will read and display various elements from GPS like Speed, Clock, Date, Location, Altitude, Trip distance, Number of connected satellites, Cardinals (moving direction), etc. We can use this project in cars or other moving vehicles.

In next update I am planning to build a web-server using esp8266 to receive data from GPS in smart phones and generate geographical location on online 2D maps using longitude and latitude.



Components:

  • ESP8266 NodeMCU board
  • Ublox neo-6m GPS module
  • OLED i2c display 128x64px
  • Momentary push buttons – 2Nos
  • Software : Arduino IDE




Circuit Diagram:

GPS display Project



Code:

/*
 * Project: Mini GPS Display using Ublox neo-6m and ESP8266
 * Author: Pranay SS, eTechPath
 * Website: www.etechpath.com
 * Tutorial Link: 
   
Mini GPS Display using Ublox neo-6m module and ESP8266 nodemcu
* Video Link: https://youtu.be/ExPBmiz1cj0 * */ #include <Arduino.h> #include <U8g2lib.h> #ifdef U8X8_HAVE_HW_SPI #include <SPI.h> #endif #ifdef U8X8_HAVE_HW_I2C #include <Wire.h> #endif #define menu D3 #define enter D4 int key = 0; double Home_LAT = 0; double Home_LNG = 0; //sat20x20px logo U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); static const unsigned char u8g_logo_sat[] U8X8_PROGMEM = { 0x00, 0x01, 0x00, 0x80, 0x07, 0x00, 0xc0, 0x06, 0x00, 0x60, 0x30, 0x00, 0x60, 0x78, 0x00, 0xc0, 0xfc, 0x00, 0x00, 0xfe, 0x01, 0x00, 0xff, 0x01, 0x80, 0xff, 0x00, 0xc0, 0x7f, 0x06, 0xc0, 0x3f, 0x06, 0x80, 0x1f, 0x0c, 0x80, 0x4f, 0x06, 0x19, 0xc6, 0x03, 0x1b, 0x80, 0x01, 0x73, 0x00, 0x00, 0x66, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x70, 0x00, 0x00 }; //wave10px logo static const unsigned char u8g2_logo_wave[] U8X8_PROGMEM ={ 0xE0, 0x03, 0x18, 0x00, 0xC4, 0x01, 0x32, 0x00, 0x8A, 0x01, 0x69, 0x00, 0x25, 0x00, 0x95, 0x01, 0x95, 0x01, 0x01, 0x00, }; //sat40x35px logo // The serial connection to the GPS device #include <SoftwareSerial.h> static const int RXPin = D5, TXPin = D6; static const uint32_t GPSBaud = 9600; SoftwareSerial ss(RXPin, TXPin); //GPS Library #include <TinyGPS++.h> TinyGPSPlus gps; //Program variables double Lat; double Long; double Alt; int day, month, year; //int hour, minute, second; int num_sat, gps_speed; String heading; //SETUP void setup() { pinMode(menu, INPUT_PULLUP); pinMode(enter, INPUT_PULLUP); ss.begin(GPSBaud); u8g2.begin(); //PrintingLoadingPage u8g2.firstPage(); do { print_page1(); } while ( u8g2.nextPage() ); delay(5000); }//END SETUP //LOOP void loop() { Get_GPS(); //Get GPS data if (digitalRead(menu) == LOW) key = (key+1); //else if (digitalRead(menu) == LOW) //key = (key-1); if (key<0 or key>3) key = 0; switch (key) { case 0: u8g2.firstPage(); do { print_Clock(); } while ( u8g2.nextPage() ); delay(10); break; case 1: u8g2.firstPage(); do { print_speed(); } while ( u8g2.nextPage() ); delay(10); break; case 2: u8g2.firstPage(); do { print_location(); } while ( u8g2.nextPage() ); delay(10); break; case 3: u8g2.firstPage(); do { print_Trip(); if (digitalRead(enter) == LOW) { Home_LAT = gps.location.lat(); Home_LNG = gps.location.lng(); } else { u8g2.setFont(u8g2_font_courR08_tr); u8g2.setCursor(0, 64); u8g2.print("Press Enter to reset"); } } while ( u8g2.nextPage() ); delay(10); break; } } //end of loop void print_page1() { u8g2.drawXBMP(0, 0, 20, 20, u8g_logo_sat); u8g2.setFont( u8g2_font_crox1cb_tf); //u8g2.setFont(u8g2_font_helvB12_tf); //u8g2.setFont(u8g2_font_timB12_tf); u8g2.setCursor(45, 20); u8g2.print("MINI GPS"); //u8g2.setFont(u8g2_font_7x13B_tf); u8g2.setFont(u8g2_font_nine_by_five_nbp_tf); u8g2.setCursor(55, 35); u8g2.print("by eTechPath"); u8g2.setFont(u8g2_font_nine_by_five_nbp_tf); u8g2.setCursor(0, 60); u8g2.print("Loading"); u8g2.setFont(u8g2_font_glasstown_nbp_tf); u8g2.setCursor(40, 60); u8g2.print(" . . . . . "); } void print_Clock() { u8g2.setFont(u8g2_font_courB08_tn); u8g2.setCursor(105, 64); u8g2.print( num_sat, 5); u8g2.drawXBMP(118, 54, 10, 10, u8g2_logo_wave); u8g2.setFont(u8g2_font_crox1cb_tf); u8g2.setCursor(20, 10); u8g2.print("GPS CLOCK"); u8g2.drawLine(0,12,128,12); u8g2.setFont(u8g2_font_t0_22b_tn); u8g2.setCursor(20, 42); printTime(gps.time); // u8g.print(gps.date); //Get_Date(); u8g2.setFont(u8g2_font_nine_by_five_nbp_tf); u8g2.setCursor(0, 64); printDate(gps.date); } void print_speed() { u8g2.setFont(u8g2_font_crox1cb_tf); u8g2.setCursor(16, 10); u8g2.print("Speedometer"); u8g2.drawLine(0,15,128,15); u8g2.setFont(u8g2_font_t0_22b_tn); u8g2.setCursor(5, 42); u8g2.print(gps_speed , DEC); u8g2.setFont(u8g2_font_glasstown_nbp_tf); u8g2.setCursor(62, 42); u8g2.print("km/h"); u8g2.setFont(u8g2_font_courB08_tn); u8g2.setCursor(105, 64); u8g2.print( num_sat, 5); u8g2.drawXBMP(118, 54, 10, 10, u8g2_logo_wave); u8g2.setFont(u8g2_font_glasstown_nbp_tf); u8g2.setCursor(0,64); u8g2.print("Direction:"); u8g2.setCursor(45,64); u8g2.print( heading); } void print_location() { u8g2.setFont(u8g2_font_crox1cb_tf); u8g2.setCursor(10, 10); u8g2.print("GPS Location"); u8g2.drawLine(0,12,128,12); u8g2.setFont(u8g2_font_nine_by_five_nbp_tf); u8g2.setCursor(5, 28); u8g2.print("Long: "); u8g2.setCursor(40, 28); u8g2.print( Long, 6); u8g2.setCursor(5, 43); u8g2.print("Lat: "); u8g2.setCursor(40, 43); u8g2.print( Lat, 6); u8g2.setCursor(0, 64); u8g2.print("Alt: "); u8g2.setCursor(20, 64); u8g2.print( Alt, 3); u8g2.setFont(u8g2_font_courB08_tn); u8g2.setCursor(105, 64); u8g2.print( num_sat, 5); u8g2.drawXBMP(118, 54, 10, 10, u8g2_logo_wave); } // This custom version of delay() ensures that the gps object // is being "fed". static void smartDelay(unsigned long ms) { unsigned long start = millis(); do { while (ss.available()) gps.encode(ss.read()); } while (millis() - start < ms); } void Get_GPS() { num_sat = gps.satellites.value(); if (gps.location.isValid() == 1) { Lat = gps.location.lat(); Long = gps.location.lng(); Alt = gps.altitude.meters(); gps_speed = gps.speed.kmph(); heading = gps.cardinal(gps.course.value()); } /* if (gps.date.isValid()) { day = gps.date.day(); month = gps.date.month(); year = gps.date.year(); } if (gps.time.isValid()) { hour = gps.time.hour(); minute = gps.time.minute(); second = gps.time.second(); } */ smartDelay(1000); if (millis() > 5000 && gps.charsProcessed() < 10) { // Serial.println(F("No GPS detected: check wiring.")); } } static void printDate(TinyGPSDate &d) { if (!d.isValid()) { u8g2.print(F("******** ")); } else { char sz[32]; sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year()); u8g2.print(sz); } } static void printTime(TinyGPSTime &t) { if (!t.isValid()) { u8g2.print(F("******** ")); } else { char sz[32]; sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second()); u8g2.print(sz); } // printInt(d.age(), d.isValid(), 5); smartDelay(0); } void print_Trip() { unsigned long distanceKm = (unsigned long)TinyGPSPlus::distanceBetween( gps.location.lat(), gps.location.lng(), Home_LAT, Home_LNG ) / 1000.0; u8g2.setFont(u8g2_font_nine_by_five_nbp_tf); u8g2.setCursor(0, 20); u8g2.print("Trip: "); u8g2.setCursor(50, 20); u8g2.print(distanceKm); u8g2.setCursor(90, 20); u8g2.print("Km"); double courseTo = TinyGPSPlus::courseTo( gps.location.lat(), gps.location.lng(), Home_LAT, Home_LNG ); u8g2.setCursor(0, 30); u8g2.print("Course: "); u8g2.setCursor(60, 30); u8g2.print(courseTo); u8g2.setCursor(90, 30); u8g2.print("Km"); String cardinalTo = TinyGPSPlus::cardinal(courseTo); u8g2.setCursor(0, 40); u8g2.print("Cardinal: "); u8g2.setCursor(60, 40); u8g2.print(cardinalTo); }

 




Prototype:

 



GPS Display Screens:

  

Working Video:




Downloads:




]]>
https://blog.etechpath.com/mini-gps-display-using-ublox-neo-6m-module-and-esp8266-nodemcu/feed/ 0
How to flash USB bootloader in STM32 black-pill board to program it with Arduino IDE https://blog.etechpath.com/how-to-flash-usb-bootloader-in-stm32-black-pill-board-to-program-it-with-arduino-ide/ https://blog.etechpath.com/how-to-flash-usb-bootloader-in-stm32-black-pill-board-to-program-it-with-arduino-ide/#comments Mon, 12 Nov 2018 10:59:39 +0000 https://blog.etechpath.com/?p=665 About:

STM32 is a 32bit ARM cortex microcontroller and normally we need USB to TTL module or ST-link stick to dump program to its memory. So, here in this project i will teach you how to flash USB bootloader in STM32 microcontroller so that we can program it with direct USB port from Arduino IDE.

Things you will need:

  1. STM32 board. (Black pill or Blue pill)

2. USB to serial converter ( TTL module) (3.3v compatible)

3. 3.3v power supply to power the board (or separate 5v micro USB cable would work )

Circuit Diagram:

Procedure:

Windows

  1. Download the suitable boot-loader binary file from given download link. If you don’t know which binary file will suits your black-pill, then simply trace its LED pin track and notice its pin number. This same pin number binary file you will have to flash into your board.
  2. Put your black-pill board on serial programming mode by setting boot0 pin high and boot1 pin low.
  3. Connect black-pill board to serial converter as shown in circuit diagram and connect serial connector to your computer USB port.
  4. Download Flash Loader Demonstrator program to flash the boot-loader into black-pill.
  5. Open up Flash Loader Demonstrator and follow the steps. Reference snapshots are as shown bellow..
  6. After finishing flashing process you will get conformation message as shown in the reference image. After that you need to change the board programming mode to normal by replacing the jumpers as previous, without switching off the board power.

Linux

Follow step 1 to 3 same as windows procedure and then use the following command to flash the boot-loader binary into your board. Change the path and file name according to your binary file.

Change the serial programming mode to normal by changing the jumper setting as previous, without switching of the power supply.

Reference Images:

Downloads:

]]>
https://blog.etechpath.com/how-to-flash-usb-bootloader-in-stm32-black-pill-board-to-program-it-with-arduino-ide/feed/ 2