Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The TC74A0-5.0VAT is a digital temperature sensor that communicates over the I2C interface. Here's an example code in Arduino that reads the temperature from the sensor:
- Note: This code assumes that the TC74A0-5.0VAT temperature sensor is connected to the I2C interface of the Arduino board. The I2C address of the sensor is set to 0x4D, but you should verify the address using a scanner tool if you're unsure. Also, note that the sensor requires a warm-up time of at least 30ms after power-on before providing accurate readings, so be sure to wait for this period before reading from the sensor. Finally, note that the temperature readings are in Celsius (°C).
- */
- #include <Wire.h>
- const byte ADDRESS = 0x4D; // the I2C address of the sensor
- int temperature; // the temperature reading from the sensor
- void setup() {
- Serial.begin(9600);
- Wire.begin(); // start the I2C interface
- }
- void loop() {
- Wire.beginTransmission(ADDRESS);
- Wire.write(0x00); // select the temperature register
- Wire.endTransmission();
- Wire.requestFrom(ADDRESS, 1); // request 1 byte of data
- if (Wire.available() == 1) {
- byte msb = Wire.read();
- temperature = msb; // convert the byte to temperature
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println(" °C");
- }
- // delay before reading from the sensor again
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement