Skip to content

Instantly share code, notes, and snippets.

@HectorTorres
Last active May 21, 2018 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HectorTorres/5a14866cc77776cee7fcf54e8cbe2ce4 to your computer and use it in GitHub Desktop.
Save HectorTorres/5a14866cc77776cee7fcf54e8cbe2ce4 to your computer and use it in GitHub Desktop.
#include <Wire.h>
#include "Adafruit_MCP9808.h"
Adafruit_MCP9808 sensor = Adafruit_MCP9808(); //objeto que tendrá los valores del sensor de temperatura
void setup()
{
Serial.begin(9600);
Serial.println("Lecturas:");
Serial.println(" ");
if (!sensor.begin(0x1F)) //direccion I2C para encontrar el sensor
{
Serial.println("No se encontro el sensor MCP9808!");
while (1);
}
}
void loop()
{
Serial.println("Temperaturas: ");
sensor.shutdown_wake(0);//nesesaria para antes de leer la temperatura
float cel = sensor.readTempC(); //lectura de temperatura
Serial.print(cel); //impresion en celcius
Serial.println(" *C");
float far = cel * 9.0 / 5.0 + 32; //conversion a fahrenheit
Serial.print(far); //impresion en fahrenheit
Serial.println(" *F");
delay(250);
Serial.println("Fin lectura");
Serial.println(" ");
sensor.shutdown_wake(1);
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment