Back to Arduino Step By Step Course

Lesson 34: Using MCP9808 High Accuracy I2C Temperature with TM1637 LED Display| Arduino Step by Step Course

If you don't like to see ads while video is being played you can purchase this course for $200 from Udemy or purchase YouTube premium Here

Please download required files for this code

Part 3: Temperature Sensors

In this lesson we learn how to use MCP9808 Temperature sensor to measure and display it on TM1637 LED Display. We have no decimal point with this display. There are two other video lectures for this sensor 1-Introduction to MCP9808 and 1-Using MCP9808 with LCD screen.


 /*
 * Robojax Arduino Step By Step Course
 * Part 3: Temperature Sensors
 * Lesson 34: MCP9808 with TM1637 LED Display
 


 * Updated by Ahmad Shamshiri for Robojax Robojax.com
 * on Mar 23, 2019 in Ajax, Ontario, Canada

 
  Please watch video instruction here https://youtu.be/Q_rBLKdnCd4
 This code is available at http://robojax.com/course1/?vid=lecture34
 
with over 100 lectures Free On  YouTube Watch it here http://robojax.com/L/?id=338
Get the code for the course: http://robojax.com/L/?id=339  
If you found this tutorial helpful, please support me so I can continue creating 
 make donation using PayPal http://robojax.com/L/?id=64

 * Code is available at http://robojax.com/learn/arduino

 * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>. 
    
	
 */ 

/**************************************************************************/
/*!
This is a demo for the Adafruit MCP9808 breakout
----> http://www.adafruit.com/products/1782
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include <math.h>
#include <Wire.h>
#include "Adafruit_MCP9808.h"

// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();

// start of settings of TM1637 display
#include <Arduino.h>
#include <TM1637Display.h>

// Module connection pins (Digital Pins)
#define CLK 5
#define DIO 6
TM1637Display display(CLK, DIO);
// start of settings of TM1637 display

uint8_t blank[] = { 0x0, 0x0, 0x0, 0x0 };// blank value for all digits

void setup() {
	//YouTube Watch it here http://robojax.com/L/?id=338	
  Serial.begin(9600);
  Serial.println("MCP9808 demo by Robojax");
   display.setBrightness(0x0f);  
  // Make sure the sensor is found, you can also pass in a different i2c
  // address with tempsensor.begin(0x19) for example
  if (!tempsensor.begin()) {
    Serial.println("Couldn't find MCP9808!");
    while (1);
  }
}

void loop() {
  //Serial.println("wake up MCP9808.... "); // wake up MCP9808 - power consumption ~200 mikro Ampere
  //tempsensor.wake();   // wake up, ready to read!

  // Robojax example 
  Serial.print(getTemp('C'));// print Temperature in Celsius
        Serial.println(" C");// print C 
  Serial.print(getTemp('F'));// print Temperature in Celsius
        Serial.println(" F");// print F   
  Serial.print(getTemp('K'));// print Temperature in Kelvin
        Serial.println(" K");// print K  
  Serial.println(); 

  display.setSegments(blank);
  display.showNumberDec(round(getTemp('C')));
  delay(3000);

  display.setSegments(blank);
  display.showNumberDec(round(getTemp('F')));  
   
  //Serial.println("Shutdown MCP9808.... ");
  //tempsensor.shutdown(); // shutdown MCP9808 - power consumption ~0.1 micro Ampere
  
  delay(1000);
	//YouTube Watch it here http://robojax.com/L/?id=338  
}



/*
 * Written by Ahmad Shamshiri 
 * Jan 22, 2019 in Ajax, Ontario, Canada
 * 
 * getTemp(char type)
 * returns temperature in either C, F or K
 * @param type is character of upper case 
 * C is used to get Celsius
 * F is used to get fahrenheit
 * K is used for Kelvin
 */
float getTemp(char type) {
	//YouTube Watch it here http://robojax.com/L/?id=338	
  float c = tempsensor.readTempC();//get main temperature in C
  float f = c * 9.0 / 5.0 + 32;// convert to fahrenheit
  if(type =='F')
  {
    return f;// fahrenheit
  }else if(type =='K')
  {
    return c + 274.15;// return Kelvin
  }else{
   return c; //return Celsius
  }
  
}//getTemp ends




   

The least I expect from you is to thumb up the video and subscribe to my channel. I appriciate that. .I have spent months making these lectures and writing code. You don't lose anything by subscribging to my channel. Your subscription is stamp of approval to my videos and more people can find them and in it turn it helps me. Thank you

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal

**** AFFILIATE PROGRAM **** We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.