搜索代码

How to Use an MCP9808 Temperature Sensor with Arduino

How to Use an MCP9808 Temperature Sensor with Arduino

This video explains the code below and shows you, with a test, how to use the Microchip MCP9808 temperature sensor.

[ad] temperature sensor

185-How to use a MCP9808 temperature sensor with an Arduino
语言: C++
/*
 * 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 January 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 downloaded 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\t"); 
  Serial.print(f); Serial.println("*F");
  
  //Serial.println("Shutdown MCP9808.... ");
  //tempsensor.shutdown(); // shutdown MCP9808 - power consumption ~0.1 micro Ampere
  
  delay(1000);
}// loop end

资源与参考

文件📁

没有可用的文件。