Need help in using DS18b20 to calculate breath per minute

I am trying to use a temperature sensor(Ds18b20) to calculate the breath per minute I make research. the final thing I get is this theory
When set in low resolution 9 bit it can sample several times per second.
to remove noise you can take the (running) average of the temperature.
When the average is going up the person is breathing out / exhaling
When the average is going down then person is breathing in / inhaling
YOu follow this with a variable (0 = out, 1 = in)
When that variable changes you update a counter, and after 2 updates you have one breath cycle.
Comparing the time stamp mills() of the beginning of breath cycles gives you the interval.
Dividing 60000 mills by that timestamp gives you the breaths per minute

but I am a beginner and can't turn it into real code so if you can help me I will be thankful.

Have you considered using a hot wire anemometer?

Post your best coding, in code tags, results, inform us of what its supposed to do and what it does.

If you want someone to write the code see gigs and collaborations.

Does the response time of the DS18B20 allow one to make that measurement?

Please show us some raw data.

If my memory is correct in water it will reach 95% in less than ten seconds. For some reason I do not think your subject is breathing that slowly. Idaho Walker has a good solution. Thermocouples respond quickly to temperature changes. Thermocouple wire size will affect the response, I am assuming it is not in any sheath. Enclosing it will slow it down.

I would consider a thermocouple or a very small NTC resistor.

The issue you have with the DS18b20 is the thermal time constant of the device is likely slower than the breathing rate.

I suggest you purchase the smallest (least mass) NTC resistor in the 10k ohm range. Connect it to an ohmmeter and allow your subject to breath near it. Then see if you get a change you can measure.

NTC = negative temperature coefficient resistor.

If you can solder small devices I would consider this part SMD NTC

Else look through the internet and try to find a small device with leads. For the 1st test I would find the a small leaded device and give it a try. Goal is to see if you are in the ballpark.

I have an NTC on my bench so I did a quick test (the device was rather large, 4 mm diameter and 7 mm long). Breathing "hard" I could measure a resistance change that I could see on the DVM but it bounced around a lot and it might be hard to get a reliable signal. But it suggests a smaller NTC might do the trick.

Once you find an NTC that works the code is simple and there are many examples.

You can buy bead thermistors which are very responsive and Honeywell make a device , microbridge , which can make a very sensitive flow sensor.

Hi, @alaaelnagy
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

What DS18b20 do you have?
It comes in many packages and modules.
Can you please post a picture of your sensor?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

The "hot wire" or thermistor (they do come in very small sizes) anemometer works not by measuring the temperature of the airstream as such, but by measuring the cooling effect of the airstream.

To make it directional - as you would want n this case, you use twin sensors, one on either side of a narrow baffle, so the one on the side the air directly impacts is cooled more than the other.

welcome to the forum.

one of the ways, we expect the forum to work is that....
you get an Arduino and the sensors.
then google to see some tutorial and get the sensor to work
then do a simple test.
DOES IT DO WHAT YOU EXPECT ?
DOES IT DO WHAT IT EXPECTS ?
DOES IT WORK FOR YOUR NEEDS ?

if you get the DS18B20 in a TO92 case, it is MUCH more sensitive than the same unit in a metal can with much more mass.

so, you connect the DS18B20 and breath on it.
lets assume the temperature changes, it is doing what IT is supposed to
you try to breath in and out and it seems to follow your breath, but lags behind
it IS doing what YOU expect.

but.. if the lag is too great, and it cannot respond to rapid, shallow breaths, the it would not be working for YOUR NEEDS.

so far, we do not know any of those answers.

without any information
we can only offer speculation.

this forum works really well when you can tell us what you did and how it is working
and then what you would like to have happen.

I connected a DS18B20 and just put my nose over the board and took regular breaths.
it seemed the heat from my breath was adding heat to the mass, so was incrementing towards some state.

but in line with what the OP is asking, in this test, a TO92 package DS18B20 does offer some response to a human breathing cycle.

But you did not reveal your code for the OP! :woozy_face:

I am working on using a DS18B20 for two temperatures.
I used the 'get the ID from the sensor' method vs. the discover the sensor ID and then hard code it.

I am using a small OLED, 128x32 and the U8G2 ( or U8x8) OLED library.

The ESP8266 specifically, the WEMOS D1 mini, is the micro used.
I removed the BME280 as I need the more waterproof DS18B20 sensors.

for this test, I just used the TO92 case DS18B20 sensor

I am a bit hesitant to post my code as it is just something I kludeged together.

/*  
 *   using 8x8 display driver with 128x32 display
 *   
 *   
 *   esp8266  pins used
     rst unused  TX
     AO unused   RX
     D0          D1  I2C SCL
     D5  CLK     D2  I2C SDA
     D6  MISO    D3  1-wire
     D7  MOSI    D4   C/S
     D8  RESET   GND
     3V3         5V
  
  NOKIA 5110 with ESP8266

  rst  =  D4 - RST
  C/S  =  D8 - CS
  DC   =  D0 - DC
  MOSI =  D7 hardware
  SCK  =  D5 hardware
  3v3
  backlight
  ground


  I2C
  CL  =  D1    hardware I2C on ESP8266 
  DA  =  D2   hardware I2C on ESP8266

  1Wire = D3 //  any digital pin works

*/

#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Arduino.h>
#include <U8x8lib.h>

// U8G2_PCD8544_84X48_1_4W_HW_SPI u8g2(U8G2_R2, /* cs=*/ D8, /* dc=*/ D0, /* reset=*/ D4);                        // Nokia 5110 Display
// U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // D1 & D2
U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA);   // pin remapping with ESP8266 HW I2C

// ***************************************************************************
#define ONE_WIRE_BUS D3
// ***************************************************************************

// #define TEMPERATURE_PRECISION 12
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
DeviceAddress DS18one, DS18two; // arrays to hold device addresses

// from the BME280
float tem1, tem2, hum1, hum2, pres1, pres2, gas_t1, gas_t2 ;
unsigned long then , then1;  // for timing blink without delay, not used

void setup()  // +++++++++++++++++++++++++++++++++++++ SETUP +++++++++++++++++++++++
{
  Serial.begin(115200);
  sensors.begin();
    u8x8.begin();
  delay(2000);

  // locate devices on the bus
//  Serial.print("Locating OneWire devices...");    Serial.print("Found ");
 // Serial.print(sensors.getDeviceCount(), DEC);     Serial.println(" devices.");

  if (!sensors.getAddress(DS18one, 0)) Serial.println("Unable to find address for Device 0");
  if (!sensors.getAddress(DS18two, 1)) Serial.println("Unable to find address for Device 1");

  sensors.setResolution(DS18one, 12);
  sensors.setResolution(DS18two, 12);

  then = millis();

}  // ================================================= END SETUP =============================

void loop()
{
  sensors.requestTemperatures();
  delay(10);
  gas_t1 = sensors.getTempF(DS18one);
  gas_t1 =  ( gas_t1 - .2) ; // correct mismatched temperature sensors
  Serial.print("DS18-1: ");
  Serial.print(gas_t1);
  Serial.print("*F\t");
  delay(10);
 gas_t2 = sensors.getTempF(DS18two);
  Serial.print(" DS18-2: ");
  Serial.print(gas_t2);
  Serial.println("*F\t");
  
 // u8x8.clear();
  u8x8.setFont(u8x8_font_px437wyse700b_2x2_r);
  u8x8.setCursor(0, 0);    u8x8.print("T1=");
  u8x8.setCursor(0, 2);    u8x8.print("T2=");
  u8x8.setCursor(6, 0);    u8x8.print(gas_t1,1); 
  u8x8.setCursor(6, 2);    u8x8.print(gas_t2,1);

}  // ================================================= END LOOP  =============================
  

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.