Advertisement
microrobotics

TC74A0-5.0VAT

Mar 30th, 2023
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. 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:
  3.  
  4. 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).
  5. */
  6.  
  7. #include <Wire.h>
  8.  
  9. const byte ADDRESS = 0x4D; // the I2C address of the sensor
  10. int temperature;  // the temperature reading from the sensor
  11.  
  12. void setup() {
  13.   Serial.begin(9600);
  14.   Wire.begin(); // start the I2C interface
  15. }
  16.  
  17. void loop() {
  18.   Wire.beginTransmission(ADDRESS);
  19.   Wire.write(0x00); // select the temperature register
  20.   Wire.endTransmission();
  21.  
  22.   Wire.requestFrom(ADDRESS, 1); // request 1 byte of data
  23.   if (Wire.available() == 1) {
  24.     byte msb = Wire.read();
  25.     temperature = msb; // convert the byte to temperature
  26.     Serial.print("Temperature: ");
  27.     Serial.print(temperature);
  28.     Serial.println(" °C");
  29.   }
  30.  
  31.   // delay before reading from the sensor again
  32.   delay(1000);
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement