Created
March 18, 2015 19:16
-
-
Save pingud98/54bdf82d758569ad22dd to your computer and use it in GitHub Desktop.
TC74 I2C temp sensor and arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
//wire library | |
/* | |
Sourced from | |
http://www.instructables.com/id/Thermostat-Microcontroller-with-an-Arduino-and-a-T/step4/TC74-Arduino-code/ | |
and modified a bit! | |
*/ | |
//works better when you connect SDA and SCLK | |
#define address B1001101 | |
#define baudrate 9600 | |
//baudrate for communication | |
byte val = 0; | |
void setup() | |
{ | |
Wire.begin(); | |
Serial.begin(baudrate); | |
} | |
void loop() | |
{ | |
Serial.print("temperature in Celsius: "); | |
//let's signal we're about to do something | |
int temperature; | |
//temperature in a byte | |
Wire.beginTransmission(address); | |
//start the transmission | |
Wire.write(val); | |
Wire.requestFrom(address, 1); | |
if (Wire.available()) { | |
temperature = Wire.read(); | |
Serial.println(temperature); | |
} | |
else { | |
Serial.println("---"); | |
} | |
delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment