Categories

Arduino and TMP175 digital temperature sensor example

The TMP75 and TMP175 devices are digital temperature sensors ideal for NTC and PTC thermistor replacement. The devices offer a typical accuracy of ±1°C without requiring calibration or external component signal conditioning. IC temperature sensors are highly linear and do not require complex calculations or look-up tables to derive the temperature. The on-chip 12-bit ADC offers resolutions down to 0.0625°C. The devices are available in the industry standard LM75 SOIC-8 and MSOP-8 footprint.

The TMP175 and TMP75 feature SMBus, Two-Wire, and I2C interface compatibility. The TMP175 device allows up to 27 devices on one bus. The TMP75 allows up to eight 8 on one bus. The TMP175 and TMP75 both feature an SMBus Alert function.

The TMP175 and TMP75 devices are ideal for extended temperature measurement in a variety of communication, computer, consumer, environmental, industrial, and instrumentation applications.

Features

  • TMP175: 27 Addresses
  • TMP75: 8 Addresses, NIST Traceable
  • Digital Output: SMBus™, Two-Wire™, and I2C
    Interface Compatibility
  • Resolution: 9 to 12 Bits, User-Selectable
  • Accuracy:
    • ±1°C (Typical) from –40°C to 125°C
    • ±2°C (Maximum) from –40°C to 125°C
  • Low Quiescent Current: 50-µA, 0.1-µA Standby
  • Wide Supply Range: 2.7 V to 5.5 V
  • Small 8-Pin MSOP and 8-Pin SOIC Packages

 

Connection

Module Connection Arduino Connection
VCC 5v
GND Gnd
SDA SDA
SCL SCL

 

Code

#include <Wire.h> 
 
byte TempHi;              // Variable hold data high byte
byte TempLo;              // Variable hold data low byte
boolean P_N;              // Bit flag for Positive and Negative
unsigned int Decimal;     // Variable hold decimal value
 
void Cal_Temp();
/*******************************************************************************
                      Setup
*******************************************************************************/ 
void setup() 
{ 
  Serial.begin(9600);
  Wire.begin();             // join i2c bus (address optional for master) 
  delay(1000);
} 
 
/*******************************************************************************
                      Main Loop
*******************************************************************************/  
void loop() 
{
  const int I2C_address = 0x37;  // I2C write address 
 
  delay(100);
  Wire.beginTransmission(I2C_address);
  Wire.write(1);             // Setup configuration register
  Wire.write(0x60);          // 12-bit
  Wire.endTransmission(); 
 
  Wire.beginTransmission(I2C_address);
  Wire.write(0);             // Setup Pointer Register to 0
  Wire.endTransmission(); 
 
  while (1)
  {
    delay(1000);
 
    // Read temperature value
    Wire.requestFrom(I2C_address, 2);
    while(Wire.available())          // Checkf for data from slave
    {                                
      TempHi = Wire.read();       // Read temperature high byte
      TempLo = Wire.read();       // Read temperature low byte
    } 
    Cal_Temp ();
 
    // Display temperature
    Serial.print("The temperature is ");
    if (P_N == 0)
      Serial.print("-");
    Serial.print(TempHi,DEC);
    Serial.print(".");
    Serial.print(Decimal,DEC);
    Serial.println(" degree C");
  }  
}
 
void Cal_Temp()
{
  if (TempHi&0x80)          // If bit7 of the TempHi is HIGH then the temperature is negative
    P_N = 0;
  else                      // Else the temperature is positive
    P_N = 1;
 
  TempHi = TempHi & 0x7F;   // Remove sign
  TempLo = TempLo & 0xF0;   // Filter out last nibble
  TempLo = TempLo >>4;      // Shift right 4 times
  Decimal = TempLo;
  Decimal = Decimal * 625;  // Each bit = 0.0625 degree C
 
}

 

Output

 

The temperature is 22.8125 degree C
The temperature is 22.8125 degree C
The temperature is 23.5625 degree C
The temperature is 23.6875 degree C
The temperature is 24.3750 degree C
The temperature is 24.6250 degree C
The temperature is 25.0 degree C
The temperature is 25.2500 degree C
The temperature is 25.4375 degree C

 

Link

1pcs CJMCU-175 TMP175 27 Address Digital Temperature Sensor

Share

Arduino and HS1011 sensor example

The HS1101 humidity sensor is a cost-effective solution for measuring relative humidity within ±5% accuracy. The sensor’s design is based on a unique capacitive cell; therefore, by using simple RC circuit wiring it is easy to interface with any Parallax microcontroller, including the BASIC Stamp® and Propeller chip.

Specifications

Power requirements: 5 to 10 VDC
Communication: Analog output of varying capacitance in response to change in relative humidity
Humidity Measuring Range: 1 to 99% RH
Operating temperature: -40 to 212 °F (-40 to 100 °C)

 

Connection

Connect 5v and Gnd to the module

I used Pin 4, you can use any I/O pin you will need to change the code below if you do

Code

/*
 
Demonstration of the Parallax HS1101 relative humidity sensor (#27920)
 
The HS1101 sensor acts as a capacitor, and uses the circuit described in the 
product documentation to derive an RC (resistor-capacitor) time delay. By
measuring the decay of the capacitor through a resistor, it is possible to
obtain the current relative humidity.
 
This demo shows the relative humidity (accuracy: +/-3.5%, as noted in product 
documentation), along with the RC delay timing. Readings repeat once every ½ 
second, and are displayed in the Arduino Serial Monitor window.
 
This example code is for the Arduino Uno and direct compatible boards, using the
Arduino 1.0 or later IDE software. It has not been tested, nor designed for, other 
Arduino boards, including the Arduino Due.
 
Please note: Environmental factors - including use indoors or outdoors, and
above and below typical room temperature ranges -- may affect the accuracy of 
the readings. The demo includes an RCdelay calibration value that can be 
adjusted against a known working humidity sensor used in the same environment.
 
Important: the result is based on the clock speed of Arduino microcontroller.
Other versions of Arduino (running at faster or slower clocks) will need
recalibration of the RCdelay value. See comment below.
 
Refer to the HS1101 product documentation for the connection diagram and
circuit. The output of the sensor is connected to Arduino pin D4.
 
Tips: The sensor is sensitive to stray capacitance. Keep lead lengths short.
Results may vary when the test circuit is built on a solderless breadboard.
Leads from sensor are slightly undersized for breadboard holes. Make sure
they make adequate contact. When taking readings avoid contact or close
proximity to sensor or bare circuit wires.
 
*/
 
int sensorPin = 4;                        // RC circuit with HS1101 sesnor connected to digital pin D4
long result = 0;
int const RHconstant = 12169;             // RH constant
 
void setup() {
   Serial.begin(9600);                   // Use Serial Monitor window at 9600 baud
   Serial.println("Humidiy reading start");
   Serial.print("RC delay");
   Serial.print("\t");
   Serial.println("Humidity");
}
void loop() {
   long RCdelay = RCTime(sensorPin);     // Take RC time reading of sensor
   Serial.print(RCdelay);                // Display RC time delay
   Serial.print("\t\t"); 
 
   RCdelay = RCdelay * 215;               // Calibation to RC time delay; experiment with literal value
   int humidity = (RCdelay - RHconstant) / 24;
   Serial.println(humidity / 100, DEC);  
   delay(500);                           // Wait 1/2 second for the next read
}
 
// Standard RC time function
long RCTime(int sensePin){
   long result = 0;
   pinMode(sensePin, OUTPUT);       // Make pin OUTPUT, and turn HIGH
   digitalWrite(sensePin, HIGH);    
   delay(1);                        // Wait 1 ms delay
   pinMode(sensePin, INPUT);        // Make sensor INPUT
   digitalWrite(sensePin, LOW);     // Turn off Arduino internal pullup resistor
   while(digitalRead(sensePin)){    // Loop until pin goes low
      result++;
   }
   return result;
}

 

Link

https://www.parallax.com/sites/default/files/downloads/27920-Humidity-Sensor-Datasheet.pdf

https://www.parallax.com/sites/default/files/downloads/27920-Humidity-Sensor-Documention-S1101-v1.0.pdf

CJMCU-1101 HS1101 humidity sensor RELATIVE, HUMIDITY, SENSOR

Share

Arduino and TEMT6000 light sensor

TEMT6000X01 ambient light sensor is a silicon NPN epitaxial planar phototransistor in a miniature transparent 1206 package for surface mounting. It is sensitive to visible light much like the human eye and has peak sensitivity at 570 nm.

Here is a picture of a module

 

Here is a schematic of the module

APPLICATIONS

Ambient light sensor for control of display backlight dimming in LCD displays and keypad backlighting of mobile devices and in industrial on/off-lighting operation.

• Automotive sensors
• Mobile phones
• Notebook computers
• PDA’s
• Cameras
• Dashboards

 

Connection

 

arduino and TEMT6000

arduino and TEMT6000

 

Code

 

#define LIGHTSENSORPIN A1 //Ambient light sensor reading
 
void setup() 
{
pinMode(LIGHTSENSORPIN, INPUT); 
Serial.begin(9600);
}
 
void loop() 
{
float reading = analogRead(LIGHTSENSORPIN); //Read light level
float square_ratio = reading / 1023.0; //Get percent of maximum value (1023)
square_ratio = pow(square_ratio, 2.0); 
Serial.println(reading); 
delay(1000); 
}

 

Output

Open the serial monitor and you should see something like this

41.00
42.00
4.00
1.00
21.00
38.00
41.00
41.00
40.00

 

Links

TEMT6000 Light Sensor

https://www.vishay.com/docs/81579/temt6000.pdf

Share

Arduino and MMA7660 accelerometer

The MMA7660FC is a digital output I²C, very low-power, low-profile capacitive micro-machined accelerometer featuring a low pass filter, compensation for zero-g offset and gain errors and conversion to six-bit digital values at a user configurable output data rate. The device can be used for sensor data changes, product orientation and gesture detection through an interrupt pin (INT).

Communication is handled through a 2 pin I2C interface, available on a wide range of microcontrollers. The I2C address by default is 0x4c.

 

Pin Description

Connection

  • Pinout for Arduino UNO
  • GND = GND
  • VCC = 5v
  • SDA = A4
  • SCL = A5

 

Code

I used this library – https://github.com/mcauser/Grove-3Axis-Digital-Accelerometer-1.5g-MMA7660FC

This is the default example

 

#include <Wire.h>
#include "MMA7660.h"
MMA7660 acc;
 
void setup()
{
acc.init();
pinMode(13, OUTPUT);
Serial.begin(115200);
}
 
void loop()
{
 
static long cnt = 0;
static long cntout = 0;
float ax,ay,az;
int8_t x, y, z;
 
acc.getXYZ(&x,&y,&z);
 
Serial.print("x = ");
Serial.println(x);
Serial.print("y = ");
Serial.println(y);
Serial.print("z = ");
Serial.println(z);
 
 
if(acc.getAcceleration(&ax,&ay,&az))
{
Serial.print("get data ok: ");
}
else
{
Serial.print("tiem out: ");
}
 
Serial.println("accleration of X/Y/Z: ");
Serial.print(ax);
Serial.println(" g");
Serial.print(ay);
Serial.println(" g");
Serial.print(az);
Serial.println(" g");
Serial.println();
delay(50);
 
}

 

Link

https://www.nxp.com/docs/en/data-sheet/MMA7660FC.pdf

1PCS NEW MMA7660 Replace MMA7260 3 Axis Triaxial accelerometer sensor module

Share