1-WIRE DS18B20 TEMPERATURE SENSOR - Arduino tutorial #6

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 มิ.ย. 2024
  • In this Arduino for beginners tutorial I'll teach you how to read the DS18B20 1-wire temperature sensor.
    The Arduino for beginners tutorials series guides you through the world of Arduino. A video is around 10 minutes and shows you step-by-step how to build the circuit and write the code. The website contains the course material, circuit diagram, Arduino code and shopping list of all the components used in the tutorial.
    ⬇️ Arduino code, circuit diagram and part list arduino-tutorials.net/tutoria...
    👉 More tutorials and projects on arduino-tutorials.net
    🇳🇱 Deze tutorial is ook in het Nederlands beschikbaar • 🇳🇱 SCHAKEL LED OP TEMP...
    CHAPTERS:
    00:00 Introduction
    00:08 Requirements
    00:37 1-wire sensors
    02:39 Building the circuit
    03:45 Arduino code
    08:54 Coding challenge
    COMPONENTS
    🇨🇳 Arduino Uno (clone) with cable - AliExpress
    arduino-tutorials.net/r/Jd28hF
    🇳🇱 Arduino Uno (clone) - Opencircuit
    arduino-tutorials.net/r/8237Hd
    🇳🇱 Arduino Uno SMD (original) - Opencircuit
    arduino-tutorials.net/r/Ud29dh
    🇳🇱 Arduino Uno Chip (original) - Opencircuit
    arduino-tutorials.net/r/Jd82ha
    🇨🇳 1x breadboard small - AliExpress
    arduino-tutorials.net/r/7364GD
    🇳🇱 1x breadboard small - Opencircuit
    arduino-tutorials.net/r/238Jds
    🇨🇳 1x breadboard large - AliExpress
    arduino-tutorials.net/r/FDH28dh
    🇳🇱 1x breadboard large - Opencircuit
    arduino-tutorials.net/r/8237Dh
    🇨🇳 300x Resistors - AliExpress
    arduino-tutorials.net/r/Hd72hf
    🇳🇱 600x Resistors - Opencircuit
    arduino-tutorials.net/r/Ahd72g
    🇨🇳 Jumper wire assortment (MM/MF/FF) - AliExpress
    arduino-tutorials.net/r/Fh378fg
    🇨🇳 Jumper wire male-male - AliExpress
    arduino-tutorials.net/r/7346GD
    🇳🇱 Jumper wire male-male - Opencircuit
    arduino-tutorials.net/r/8237Jd
    🇨🇳 5x 1-wire DS18B20 temperature sensor - AliExpress
    arduino-tutorials.net/r/348fhD
    🇨🇳 1-wire DS18B20 water proof temp. sensor - AliExpress
    arduino-tutorials.net/r/s5Rmi8
    🇳🇱 1-wire DS18B20 temperature sensor - Opencircuit
    arduino-tutorials.net/r/82Hdgf
    🇳🇱 1-wire DS18B20 water proof temp. sensor - Opencircuit
    arduino-tutorials.net/r/374Hdg
    #arduino #BasOnTech

ความคิดเห็น • 75

  • @BasonTech
    @BasonTech  4 ปีที่แล้ว

    👉 Don't forget to check arduino-tutorials.net for more Arduino tutorials and projects.
    If you have questions, don't hesitate to ask them in the comments. Remember: There are no stupid questions 😃

  • @__byteWise01
    @__byteWise01 2 ปีที่แล้ว

    Saying thank you would not be enough!

    • @BasonTech
      @BasonTech  2 ปีที่แล้ว

      It is for me! 😃

  • @kiwinesss
    @kiwinesss 3 ปีที่แล้ว

    Subscribed by the way :)

  • @OldCurmudgeon3DP
    @OldCurmudgeon3DP 6 ปีที่แล้ว

    Had 3 of these (pigtail type) wired up to an ESP32 NodeMCU. One would randomly read between real and 185F. Good thing Amazon sold them in 5 packs. Replaced the flaky one and so far all is well.

    • @BasonTech
      @BasonTech  6 ปีที่แล้ว

      I had the same thing once, guess I connected for example the GND and 5V the wrong way around and shorted the circuit. Lucky these sensors are not expensive :)

  • @kiwinesss
    @kiwinesss 3 ปีที่แล้ว

    I just did your tutorial, thank you. I will do more of yours now :) One question, would this be possible also if I used a TMP36 sensor?

    • @kiwinesss
      @kiwinesss 3 ปีที่แล้ว

      Okay I answered my own question. I tried the TMP36 sensor but it did not work, all I got was the -187 reading and the TMP36 got very hot very fast, so I had to take it out before I damaged it.

    • @kiwinesss
      @kiwinesss 3 ปีที่แล้ว

      I also tried using the DS18B20 with the cable and sensor www.aliexpress.com/item/4000143479592.html but it did not work, I also got the -127 in the serial monitor. What would be the reason for this? They both have the same number.

    • @BasonTech
      @BasonTech  3 ปีที่แล้ว +1

      The TMP36 sensor is not a 1-wire sensor, so you can not just replace the two with each other

  • @kwabzmahle9016
    @kwabzmahle9016 ปีที่แล้ว

    At around 6:30, on line 31, what is the 'delay(1000)' code meant to do?
    (I ask because the code seems to execute the same even without it in the code block.)

    • @BasonTech
      @BasonTech  ปีที่แล้ว +1

      delay() pauses the processor for the specified amount of milliseconds. So in this case it stops the program for 1000ms = 1 second

  • @mayureshmandal1423
    @mayureshmandal1423 3 ปีที่แล้ว

    Thanks for sharing. This was very helpful. I had a few questions.
    1. If you have multiple sensors connected on the same pin, how do you determine which sensor is assigned which number?
    2. When you initiate the instance as 'oneWire' for onewire and 'sensors' for dallastemperature, do you have to use those terms (oneWire and sensors) or can they be anything?

    • @BasonTech
      @BasonTech  3 ปีที่แล้ว

      1. Each 1-wire sensor has its own address. So first you can use a script to list the 1-wire address of the sensor. This code should be in de example code of the Arduino IDE
      2. Variables can be any name you want. Library names can't

    • @mayureshmandal1423
      @mayureshmandal1423 3 ปีที่แล้ว

      @@BasonTech I understand. Thanks for the prompt reply.

    • @BasonTech
      @BasonTech  3 ปีที่แล้ว

      My pleasure! 😃

  • @BitesandGo
    @BitesandGo ปีที่แล้ว

    My sensor is reading 197 C , how can I calibrate it? I'm usingthe same sensor in arduino too, but for ESP32

    • @BasonTech
      @BasonTech  ปีที่แล้ว

      You can't really "calibrate" it other than subtracting a number of the measured value. Make sure you have a DS18B20 sensor and setup the wires and code correctly. The sensor should be quite accurate.

  • @kwabzmahle9016
    @kwabzmahle9016 ปีที่แล้ว

    At 4:51, on line 12, why are we using the '&' inside the brackets?
    What does the '&' do?

    • @BasonTech
      @BasonTech  ปีที่แล้ว +1

      See 4:45 it is the memory address of the variable instead of its value

  • @kwabzmahle9016
    @kwabzmahle9016 ปีที่แล้ว

    Hi Bas :-)
    When you assign pin 12 as the T input, why do you write:
    'int oneWireBus = 12', from outside the setup() function
    instead of the usual 'pinMode(12, INPUT)', from inside the setup() function?

    • @BasonTech
      @BasonTech  ปีที่แล้ว +1

      that is because the oneWireBus constant is directly used one line below, and not in the setup. We are not using it as an input, it is used by the OneWire library

    • @kwabzmahle9016
      @kwabzmahle9016 ปีที่แล้ว +1

      @@BasonTech Thanks

  • @kwabzmahle9016
    @kwabzmahle9016 ปีที่แล้ว

    On line 17, at 5:03, why must we make sure the LED is off when the program starts?
    What happens if we don't? (I just executed without that code and it didn't make a difference - on this project.)
    Is this a good convention which is helpful in some instances? And if so, in which instances?
    (Enjoying your tutorials.)

    • @BasonTech
      @BasonTech  ปีที่แล้ว

      You want to create a "known state" when your program starts. Now further in the program we "know" that the LED is off instead of assuming. This can avoid bugs or side effects later in your program.

  • @celinelim2548
    @celinelim2548 ปีที่แล้ว

    If I am not using 4.7kohm resistor, am I not going to get the desired output? as I keep getting -127

    • @BasonTech
      @BasonTech  ปีที่แล้ว

      Correct, it is needed by 1-wire for the data bus

  • @jackiemyown9399
    @jackiemyown9399 2 ปีที่แล้ว

    without setting input pin 12, how it takes reading?, i am getting -127 as output..

    • @BasonTech
      @BasonTech  2 ปีที่แล้ว

      Are you really sure you are using a 1-wire temperature sensor? Many use another one which kinda looks the same 😃

  • @kiwinesss
    @kiwinesss 3 ปีที่แล้ว

    I have another question. How did you get the value of which resistor to use, why a 4.7K resistor?

    • @BasonTech
      @BasonTech  3 ปีที่แล้ว +1

      Hi Bob, good question. It works as pull-up for 1-wire. More info in this topic: arduino.stackexchange.com/questions/30822/the-use-of-4-7kohm-resistor-with-ds18b20-temperature-sensor

    • @kiwinesss
      @kiwinesss 3 ปีที่แล้ว

      @@BasonTech Cheers that helps.

  • @dericktharp5796
    @dericktharp5796 2 ปีที่แล้ว

    It would be so awesome if you could include the Alarm functions of this sensor. I'm utilizing my DS18B20 to monitor the green house I have. If the temp rises above the set threshold, arduino uno digitalwrite Pin high. thus turning on a relay which drives an actuator that opens an air vent. the other relay starts the vent fan. the lower threshold would initiate my heat source.

    • @BasonTech
      @BasonTech  2 ปีที่แล้ว

      What have you tried so far, and on what part are you stuck?

    • @dericktharp5796
      @dericktharp5796 2 ปีที่แล้ว

      @@BasonTech I followed all of code in this video. And added the alarm low and high that you showed. My initial attempt failed. I’m not at my computer right now. But later today I’ll try again and I’ll try to include code in an email if your comfortable sharing an email address with me.

    • @dericktharp5796
      @dericktharp5796 2 ปีที่แล้ว

      @@BasonTech thank you for your fast response!.. I’ll repay you by watching all of your videos over and over!

    • @BasonTech
      @BasonTech  2 ปีที่แล้ว

      There is a contact option at arduino-tutorials.net 😃

  • @williampowell7518
    @williampowell7518 2 ปีที่แล้ว

    I've done your tutorial, however the problem tthat I am experiencing is that the temperature does not update. It only updates to the new temperature after I reset the board. Any idea what could be causing this

    • @BasonTech
      @BasonTech  2 ปีที่แล้ว

      Hi William, could it be that you have written the code in the setup(), which only runs one time instead of the loop() which is infinitely ran?

    • @williampowell7518
      @williampowell7518 2 ปีที่แล้ว

      @@BasonTech no, the code is in loop. I figured out what the issue is. The Serial monitor is not updating the temperature after the first reading. I have to refresh the serial monitor to get the updated temp. Any idea what could be causing that?

    • @BasonTech
      @BasonTech  2 ปีที่แล้ว

      I have experienced such a thing once. The reason was that the serial.setup() was in the loop instead of the setup()

  • @kwabzmahle9016
    @kwabzmahle9016 ปีที่แล้ว

    At void loop(void) and void setup(void), why is 'void' inside the brackets?
    P.S. Thanks for a helpful channel.

    • @BasonTech
      @BasonTech  ปีที่แล้ว +1

      Because there are no arguments given to the setup and loop function we set it as void. You can leave them out if you want as shown at reference.arduino.cc/reference/en/language/variables/data-types/void/ 😃

  • @NadaLouhichi
    @NadaLouhichi ปีที่แล้ว

    Hello. I followed the tutorial exactly however I keep getting a temperature reading of -127. Does anyone have an idea about this issue ?

    • @BasonTech
      @BasonTech  ปีที่แล้ว

      Are you 100% sure you have a DS18B20? There are other components which look the same but are not the DS18B20 but for example a transistor.

    • @NadaLouhichi
      @NadaLouhichi ปีที่แล้ว

      @@BasonTech Yeah I am sure it's the DS18B20

    • @BasonTech
      @BasonTech  ปีที่แล้ว

      Then it must be the Arduino, wiring, code, or faulty sensor. Hard to say which one without having the circuit in my hand.

    • @NadaLouhichi
      @NadaLouhichi ปีที่แล้ว

      @@BasonTech Thank you for your reply.

  • @yuha4894
    @yuha4894 3 ปีที่แล้ว

    please can you help be i have TEMPERATURE SENSOR :dallas_DS1820_1324C4_+964AB it give me Temperature is: -127.00 value

    • @BasonTech
      @BasonTech  3 ปีที่แล้ว +1

      Are you very sure you are using the 1-wire SD18B20 sensor? Sometimes people use for example a diode because it looks the same.

    • @yuha4894
      @yuha4894 3 ปีที่แล้ว

      @@BasonTech oui thanks for the fast response I am very sure I think I have a problem in my sensor I need to change it. Do you know how to verify if my temperature sensor work or not?,

    • @BasonTech
      @BasonTech  3 ปีที่แล้ว

      You can with my code, or by grabbing 1-wire code from the examples in the Arduino IDE and see if the sensor gets detected.

  • @arabella8541
    @arabella8541 3 ปีที่แล้ว

    we did the same procedures but we always get - 127, we checked everything but we still couldn't figure out what is wrong

    • @BasonTech
      @BasonTech  3 ปีที่แล้ว +1

      Most people have this issue because they are not using a DS18B20 temp. sensor but for example a diode which looks the same but is a complete different component. Are you absolutely sure you have a 1-wire DS18B20?

    • @arabella8541
      @arabella8541 3 ปีที่แล้ว

      @@BasonTech we bought our sensor in a local but trusted shop, i don't think that's the case /but it could be
      is the small black thing also called LM35? we bought ds18b20 and LM35 but they are not in the same kit

    • @BasonTech
      @BasonTech  3 ปีที่แล้ว

      LM35 is a temperature sensor, but not a 1-wire one. Make very sure that the sensor has DS18B20 printed on it

  • @kwabzmahle9016
    @kwabzmahle9016 ปีที่แล้ว

    Last lesson we used a 'pull down resistor'.
    But in this lesson we're using a 'pull up resistor'.
    What's the difference?

    • @BasonTech
      @BasonTech  ปีที่แล้ว +1

      A pull-up resistor is used to ensure a HIGH level at the input of a digital circuit when no other device is driving the input. A pull-down resistor is used to ensure a LOW level at the input when no other device is driving the input.

    • @kwabzmahle9016
      @kwabzmahle9016 ปีที่แล้ว

      @@BasonTech Bedankt.
      Put differently, could we also say that:
      A pull-up resistor always intercepts the connections between the Output and Input 'ends' of a component (e.g. the T sensor in this tutorial)?
      And that a pull-down resistor always intercepts the connections between the Output and Ground 'ends' of a component (e.g the push button terminals in Tutorial #5)?

  • @dip8
    @dip8 2 ปีที่แล้ว

    I was buying 5 BJTs and they sent one of those to me by accident 🤣

    • @BasonTech
      @BasonTech  2 ปีที่แล้ว

      lol 😄 Always nice to get free new components!

    • @dip8
      @dip8 2 ปีที่แล้ว

      @@BasonTech how much do these DS18B20 cost?

    • @BasonTech
      @BasonTech  2 ปีที่แล้ว

      In the description of each video you'll find links to all the components 😃

    • @dip8
      @dip8 2 ปีที่แล้ว

      ty

  • @uzzalchandraboissha4885
    @uzzalchandraboissha4885 4 ปีที่แล้ว

    Every time Give me Temperature is: -127.00 value

    • @BasonTech
      @BasonTech  4 ปีที่แล้ว

      Hi, are you 100% sure you have the DS18B20 temperature sensor?

    • @uzzalchandraboissha4885
      @uzzalchandraboissha4885 4 ปีที่แล้ว

      @@BasonTech YES .

    • @BasonTech
      @BasonTech  4 ปีที่แล้ว

      Then it might be the wiring or the code. If you download the code you could be sure it should work. Maybe double check your pins and wiring 😃

    • @uzzalchandraboissha4885
      @uzzalchandraboissha4885 4 ปีที่แล้ว

      @@BasonTech Now its work. Thank You for fast response

    • @BasonTech
      @BasonTech  4 ปีที่แล้ว

      Super! What was the issue?