sensor – Blog eTechPath https://blog.etechpath.com Sat, 08 Apr 2023 19:44:08 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://blog.etechpath.com/wp-content/uploads/2017/08/BrandLogo12-150x150.png sensor – Blog eTechPath https://blog.etechpath.com 32 32 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
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
Digital distance measuring device using ultrasonic sensor SR04, OLED display and Arduino https://blog.etechpath.com/digital-distance-measuring-device-using-ultrasonic-sensor-sr04-oled-display-and-arduino/ https://blog.etechpath.com/digital-distance-measuring-device-using-ultrasonic-sensor-sr04-oled-display-and-arduino/#respond Sat, 05 May 2018 14:48:07 +0000 https://blog.etechpath.com/?p=573 About:

In this project i will explain how to interface SR04 ultrasonic sensor module with Arduino and display result on OLED display.




Components:

Arduino

SR04 Ultrasonic sensor module

OLED display i2c

Wires and basic tools




Circuit Diagram:

Description: 

  1. Connect SR04 ultrasonic sensor power to arduino +5v and GND also connect Trigger and Echo pin to arduino pin 9 and pin 8 as shown in above circuit diagram.
  2. In same way connect OLED power to arduino and connect SCL & SDA of oled display to arduino pin A5 and pin A4.
  3. Download arduino code and all libraries form download section, compile the code and upload it to your arduino.
  4. If you are new to ultrasonic sensors, do visit this post for basic study “SR04 Ultrasonic Sensor Module Basics”





Code:

/******************************************************************
 * Project: Printing utrasonic sensor data on OLED display
 * Author: Pranay Sawarkar
 * Website: www.etechpath.com
 *
 * This example is for a 128x32 pixel monocrome display using i2c
 *
 *****************************************************************/
#include <Ultrasonic.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Ultrasonic ultrasonic(9, 8);
#define OLED_RESET 4   //(optional)
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 32)     // change it to 64 if you are using 128x64 pixel OLED
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup()
{
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  //display.display();
  //delay(2000);
  display.clearDisplay();
}
void loop ()
{
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("Distance: ");
  display.println(ultrasonic.distanceRead());
  display.setCursor(80,0);
  display.print("cm");
  display.display();
  delay(1000);
  display.clearDisplay();
}

 



Downloads:

SR04 Ultrasonic Sensor Module Basics

SR04 Ultrasonic Module Library 

Adafruit GFX Library

Adafruit_SSD1306 OLED Library

Arduino Code

]]>
https://blog.etechpath.com/digital-distance-measuring-device-using-ultrasonic-sensor-sr04-oled-display-and-arduino/feed/ 0
How to interface HC-SR04 Ultrasonic Sensor with Arduino https://blog.etechpath.com/how-to-interface-hc-sr04-ultrasonic-sensor-with-arduino/ https://blog.etechpath.com/how-to-interface-hc-sr04-ultrasonic-sensor-with-arduino/#respond Tue, 03 Apr 2018 23:35:22 +0000 https://blog.etechpath.com/?p=555 About:

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




How HC-SR04 Works:

Ultrasonic modules work on principle similar to radar or sonar. It generates high frequency signal of 40kHz towards object and receives echo signal from subjects surface. Then it can calculate object distance using time interval between the sending of signal and the receiving of echo.




Theory:

To measure the object distance form sensor body we need to send a trigger pulse of 10uS, module will detect the trigger and will send out one 8cycle ultrasonic sound bust of 40kHz towards subject and receives echo of transmitted signal from objects surface. Now you can calculate distance from time interval between sending of signal and receiving of signal.

Distance Calculation:

Time=distance/speed

t = s / v

s = t . v

Speed of sound is 340m/s

v=340m/s = 0.034cm/uS

So, in order to calculate distance in cm, we need to multiply time with 0.034. But in this case time is distance between sensor and object in one way only and in our case the time value we will get from echo will be double because the sound wave needs to travel towards objects and bounce back to sensor. So, in our case the formula will be,

s = t . v/2

s = t . 0.034/2

Circuit Diagram:

Circuit Diagraam

Basic Code:

/*
* Ultrasonic Sensor HC-SR04 and Arduino Tutorial
*
* Crated by Pranay Sawarkar,
* www.eTechPath.com
*
*/
// defines arduino pin numbers
const int trigPin = 9;
const int echoPin = 8;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}







]]>
https://blog.etechpath.com/how-to-interface-hc-sr04-ultrasonic-sensor-with-arduino/feed/ 0