This Circuit will introduce a new analog component, a temperature sensor (a TMP36)!

Transcript

Hey guys, Christian here from Core Electronics. Today we're going to go through circuit 4B from project set 4.

Now in our previous circuit, we learnt how to initialize the LCD, create the LCD object and write data to the LCD. So, now that we've got that under our belt we're going to include a new component, called the TMP36 temperature sensor. So, it's a small little sensor that will change its resistance according to the temperature of the room. So, it's a nifty little thing that it can do and what we're going to do is we're going to hook that up to one of our analog pins and we're going to display the temperature on the LCD.

So, from this, it's important to connect the TMP 36 the right way. Now, if you connect it with the opposite polarity, this thing can heat up hot. So, we're going to connect it and I'm going to have the flat face the facing the middle of the breadboard. So, from there you can see on the tutorial page, the correct way to connect this and the correct way to connect this would be with the ground is in point A1. So, we're going to connect ground to the ground rail, there so A1 to ground. We're going to connect +5 volts to E3 and the signal pin can go to A0.

Now as you can see on the tutorial page we're also going to be used something called an algorithm. Now an algorithm is a way of getting from a certain set of inputs to a certain output. So, our input is going to be a digital reading from 0 to 123, that reflects volts from 0 to 5 volts. Now we're going to somehow turn that, with an offset that we've got from the TMP 36s data sheet into a relevant temperature and the way that we're going to do that is we're going to multiply it by this funky thing here, 0.004882814, which is the division of 5-volts by 1023 I believe, or a 1,024 the number of bits available. So that is they're going to be shifted by 0.005 because there's a 0.5-volt offset in the TMP 36, which you can find in its datasheet and then we're going to multiply that by 100, as it's in millivolts and we want it back to volts. So, the 100 is the correct shift, I believe. So that's said we're going to keep the rest of the circuit the same and we're only going to delete what's in the loop function. Now in the loop function, we're going to have a new value, we're going to call it a "float" and we can call it voltage and that voltage is essentially going to be what is written here, we're going to write analogRead (A0) and we're going to multiply it by 0.004882814. Now the reason that it's such a long number is that it's going to be specific, the more degree of accuracy we have here means the closer value we're going to get for our temperature reading.

So once that's done, we can have a float called "degreesC" and that's going to = (voltage minus 0.5) times by 100. Now the 100.0, once again it's for a degree of accuracy, if we just had it like that and that wasn't a float, we could get something called integer division, which cancels out and leaves some remainders. So, we're going to be leaving it in this form, so that we get an accurate or a more accurate reading.

So now that that's done what we can do is we can say LCD.setCursor and we want to set the cursor at (0,0), then we're going to say LCD.print, we can do a string and we can say the temperature is, then we can say LCD.setCursor, we're going to say (4,1) and then we can say LCD.print (degreesC). Then we can delay this function for a bit, so we can delay it for a second between readings and then we can clear it. So that our temperature doesn't get changed too much if there's a great change, so we don't have any stray numbers being printed out from the previous time.

So now that that's done we can connect our Redboard and once again, if your temperature sensor is heating up, disconnect the power wait for it to cool down and take it out and then try and reverse its polarity, but most importantly check this datasheet and check this pitcher here and it should be right. So that's uploading, and it should tell us that the temperature is 24.71 degrees C. So notice that in my sketch here, I've written the temperature is, but on the LCD we have actually run out of room for it to display that, so if I really still wanted to display that, I could write the temperature, I could come down here and then I could write LCD.print (is : ") and I can re-upload that now and it will be of a different format and I'll be able to say the temperature is, it's done uploading and it still shifted across there now. So, it's saying the temperature is 24.71 degrees Celsius. There is another way that you can get from degrees C to degrees F, so from Celsius to Fahrenheit and that's just a simple conversion that can may be found in the SparkFun inventors kit code, if you're following along with that, they just simply use this same method from the datasheet to get it from voltage to degrees C and then they transform it from degrees Celsius to degrees Fahrenheit and print out degrees C up the top and degrees Fahrenheit down the bottom, so it's definitely worth checking out if you want to see some more algorithms.

That said this has been circuit 4B, I hope you enjoyed it and join me for circuit 4C in the next video, where we will use the LCD and a button, to play a memory game.

See you then.

Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.