Other Arduino Codes and Videos by Robojax

How to use MCP9808 Temperature sensor with Arduino

دروس آردوینو به فارسی

Arduino Code for Microchip MCP9808 Temperature sensor

This video explains the code bellow and shows you with the test on how to use the Microchip MCP9808 Temperature sensor.


  
/*
 * Arduino code for Microchip MCP9808 Temperature Sensor
 * to display temperature on the serial monitor
This code has been downloaded from Robojax.com. For library and other resources for this module
please visit robojax.com
 
 watch the video for this code: https://youtu.be/MbSe9pOytlo
 * 
 * Video tutorial by Ahmad Shamshiri for Robojax.com Video
 * on Jan 22, 2019 in Ajax,  Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.

 * Please keep this note with the code.
 * This code is available on Robojax.com
 * 
 * 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 <Wire.h>
#include "Adafruit_MCP9808.h"


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

void setup() {
  Serial.begin(9600);
  Serial.println("MCP9808 demo by Robojax");
  
  // 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!

  // Read and print out the temperature, then convert to *F
  float c = tempsensor.readTempC();
  float f = c * 9.0 / 5.0 + 32;
  Serial.print("Temp: "); Serial.print(c); Serial.print("*C	"); 
  Serial.print(f); Serial.println("*F");
  
  //Serial.println("Shutdown MCP9808.... ");
  //tempsensor.shutdown(); // shutdown MCP9808 - power consumption ~0.1 micro Ampere
  
  delay(1000);
}// loop end
   

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