Categories

Arduino and US – 100 ultrasonic ranging module serial data mode example

US – 100 ultrasonic ranging module can be realized 2cm ~ 450cm of non-contact distance measurement function, with 2.4V to 4.5V wide voltage input range, the static function GPIO, serial variety of communication methods, within the band watchdog, stable and reliable.

This module is improved, the module itself has temperature compensation, the accuracy of the highest module now clean out treasure, absolute stable, economical, practical 20 * 45 mm module circuit 15 mm thick
US-100 ultrasonic ranging module can realize 2 cm ~ 4.5 m non-contact ranging function, with a 2.4 ~ 5.5 V of wide voltage input range, static power consumption less than 2 mA, bring their own temperature sensor calibration on the ranging results, and has GPIO, serial ports and so on many kinds of communication mode, inside take watchdog, stable and reliable.

Specification:

Voltage: DC 2.4V – 5V
Quiescent current: < 2mA
Output mode: level or UART
Induction angle: < 15°
Detection distance: 2cm – 450cm
Precision: 0.3cm ± 1%
Working temperature: -20°C to +70°C
Size: 45 x 20 x 1.6mm

 

1. VCC: 5V DC
2. Trig: trigger input
3. Echo: pulse output
4. GND: ground
5. GND: ground

 

Connection

Module Connection Arduino Connection
VCC 5v
GND GND
Trig TX (Pin 1)
Echo RX (Pin 0)

 

Code

// RX (Pin 0 of Arduino digital IO) to Echo
// TX (Pin 1 of Arduino digital IO) to Trig 
unsigned int HighLen = 0;
unsigned int LowLen  = 0;
unsigned int Len_mm  = 0;
 
void setup() 
{   
    Serial.begin(9600);                         
}
 
void loop() 
{
    Serial.flush();                               
    Serial.write(0X55);                           // trig US-100 begin to measure the distance
    delay(500);                                   
    if(Serial.available() >= 2)                   // receive 2 bytes 
    {
        HighLen = Serial.read();                   // High byte of distance
        LowLen  = Serial.read();                   // Low byte of distance
        Len_mm  = HighLen*256 + LowLen;            // Calculate the distance
        if((Len_mm > 1) && (Len_mm < 10000))       // normal distance should between 1mm and 10000mm (1mm, 10m)
        {
            Serial.print("Present Length is: ");   
            Serial.print(Len_mm, DEC);             
            Serial.println("mm");                  
        }
    }
    delay(500);                                   
}

 

Output

UUUPresent Length is: 58mm
UPresent Length is: 57mm
UPresent Length is: 58mm
UPresent Length is: 58mm
UUUUPresent Length is: 53mm
UPresent Length is: 57mm
UUUUPresent Length is: 78mm

 

Link

1 pc US-100 Ultrasonic Sensor Module With Temperature Compensation Range Distance 450cm For Arduino

Share

Arduino and MMA8653 example

The NXP® MMA8653FC 10-bit accelerometer has industry leading performance in a small DFN package. Packed with embedded functions that include:

Flexible user-programmable options and two configurable interrupt pins
Overall power savings through inertial wake-up interrupt signals that monitor events and remain in a low-power mode during periods of inactivity

Features
Low-profile 2 x 2 x 1.0 mm DFN package
High sensitivity: 1 mg per LSB
Low noise: 150 micro g per root Hertz (independent of resolution)
Low-power mode: 7 micro amps
Interrupt and IIC interface supply: 1.62 to 3.6 V
Supply voltage : 1.95 to 3.6 V
Output data rate: 1.5 to 800 Hz

Code

 

#include <Wire.h>
 
// I2C BUS: already defined in "wire" librairy
// SDA: PIN 2 with pull up 4.7K to 3.3V on arduino Micro
// SCL: PIN 3 with pull up 4.7K to 3.3V on arduino Micro
// Accelerometer connected to +3.3V of arduino DO NOT CONNECT TO 5V (this will destroy the accelerometer!)
// all GND Pin of accelerometer connected to gnd of arduino
 
/********************ACCELEROMETER DATAS************/
// adresss of accelerometer
int adress_acc=0X1D; // MMA8653FC and MMA8652FC
// adress of registers for MMA8653FC
int ctrl_reg1 = 0x2A;
int ctrl_reg2 = 0x2B;
int ctrl_reg3 = 0x2C;
int ctrl_reg4 = 0x2D;
int ctrl_reg5 = 0x2E;
int int_source = 0x0C;
int status_ = 0x00;
int f_setup = 0x09;
int out_x_msb = 0x01;
int out_y_msb = 0x03;
int out_z_msb = 0x05;
int sysmod = 0x0B;
int xyz_data_cfg = 0x0E;
 
/******PROGRAM DATAS**********/
int result [3];
int axeXnow ;
int axeYnow ;
int axeZnow ;
 
 
void setup(){
Wire.begin(); // start of the i2c protocol
Serial.begin(9600); // start serial for output
ACC_INIT(); // initialize the accelerometer by the i2c bus. enter the sub to adjust the range (2g, 4g, 8g), and the data rate (800hz to 1,5Hz)
}
 
//------------------------------------------------------------------
 
void loop()
{
I2C_READ_ACC(0x00);
Serial.print(axeXnow); 
Serial.print(";");
Serial.print(axeYnow); 
Serial.print(";");
Serial.print(axeZnow); 
Serial.print(";");
Serial.println();
delay(500);
}
 
//------------------------------------------------------------------
 
void ACC_INIT()
{
I2C_SEND(ctrl_reg1 ,0X00); // standby to be able to configure
delay(10);
 
I2C_SEND(xyz_data_cfg ,B00000000); // 2G full range mode
delay(1);
// I2C_SEND(xyz_data_cfg ,B00000001); // 4G full range mode
// delay(1);
// I2C_SEND(xyz_data_cfg ,B00000010); // 8G full range mode
// delay(1);
 
I2C_SEND(ctrl_reg1 ,B00000001); // Output data rate at 800Hz, no auto wake, no auto scale adjust, no fast read mode
delay(1);
// I2C_SEND(ctrl_reg1 ,B00100001); // Output data rate at 200Hz, no auto wake, no auto scale adjust, no fast read mode
// delay(1);
// I2C_SEND(ctrl_reg1 ,B01000001); // Output data rate at 50Hz, no auto wake, no auto scale adjust, no fast read mode
// delay(1);
// I2C_SEND(ctrl_reg1 ,B01110001); // Output data rate at 1.5Hz, no auto wake, no auto scale adjust, no fast read mode
// delay(1); 
}
 
//------------------------------------------------------------------
 
void I2C_SEND(unsigned char REG_ADDRESS, unsigned char DATA) //SEND data to MMA7660
{
 
Wire.beginTransmission(adress_acc);
Wire.write(REG_ADDRESS);
Wire.write(DATA);
Wire.endTransmission();
}
 
//------------------------------------------------------------------
 
void I2C_READ_ACC(int ctrlreg_address) //READ number data from i2c slave ctrl-reg register and return the result in a vector
{
byte REG_ADDRESS[7];
int accel[4];
int i=0; 
Wire.beginTransmission(adress_acc); //=ST + (Device Adress+W(0)) + wait for ACK
Wire.write(ctrlreg_address); // store the register to read in the buffer of the wire library
Wire.endTransmission(); // actually send the data on the bus -note: returns 0 if transmission OK-
Wire.requestFrom(adress_acc,7); // read a number of byte and store them in wire.read (note: by nature, this is called an "auto-increment register adress")
 
for(i=0; i<7; i++) // 7 because on datasheet p.19 if FREAD=0, on auto-increment, the adress is shifted
{
REG_ADDRESS[i]=Wire.read(); //each time you read the write.read it gives you the next byte stored. The couter is reset on requestForm
}
 
for (i=1;i<7;i=i+2)
{
accel[0] = (REG_ADDRESS[i+1]|((int)REG_ADDRESS[i]<<8))>>6; // X
if (accel[0]>0x01FF) {accel[1]=(((~accel[0])+1)-0xFC00);} // note: with signed int, this code is optional
else {accel[1]=accel[0];} // note: with signed int, this code is optional
switch(i){
case 1: axeXnow=accel[1];
break;
case 3: axeYnow=accel[1];
break;
case 5: axeZnow=accel[1];
break;
}
}
 
}
 
//------------------------------------------------------------------
 
void I2C_READ_REG(int ctrlreg_address) //READ number data from i2c slave ctrl-reg register and return the result in a vector
{
unsigned char REG_ADDRESS;
int i=0; 
Wire.beginTransmission(adress_acc); //=ST + (Device Adress+W(0)) + wait for ACK
Wire.write(ctrlreg_address); // register to read
Wire.endTransmission();
Wire.requestFrom(adress_acc,1); // read a number of byte and store them in write received
}

 

 

Output

 

107;-65281;191;
-65488;511;89;
-65387;15;87;
-65491;511;-65443;
-65364;-65423;-65470;
229;74;-65269;
237;-65511;64;
-65355;-65347;73;
-65360;132;14;
-65481;-65263;-65323;
-65453;228;-65448;
-65354;94;215;
55;-65464;276;

Links

Share

Arduino and MS5611 barometric pressure sensor example

This barometric pressure sensor is optimized for altimeters and variometers with an altitude resolution of 10 cm. The sensor module includes a high linearity pressure sensor and an ultra-low power 24 bit ΔΣ ADC with internal factory calibrated coefficients. It provides a precise digital 24 Bit pressure and temperature value and different operation modes that allow the user to optimize for conversion speed and current consumption. A high resolution temperature output allows the implementation of an altimeter/thermometer function without any additional sensor. The MS5611-01BA can be interfaced to virtually any microcontroller. The communication protocol is simple, without the need of programming internal registers in the device.

Small dimensions of only 5.0 mm x 3.0 mm and a height of only 1.0 mm allow for integration in mobile devices. This new sensor module generation is based on leading MEMS technology and latest benefits from MEAS Switzerland proven experience and know-how in high volume manufacturing of altimeter modules, which have been widely used for over a decade. The sensing principle employed leads to very low hysteresis and high stability of both pressure and temperature signal.

features

 

  • High resolution module, 10 cm
  • Fast conversion down to 1 ms
  • Low power, 1 µA (standby < 0.15 µA)
  • QFN package 5.0 x 3.0 x 1.0 mm3
  • Supply voltage 1.8 to 3.6 V
  • Integrated digital pressure sensor (24 bit ΔΣ ADC)
  • Operating range: 10 to 1200 mbar, -40 to +85 °C
  • I2C and SPI interface up to 20 MHz
  • No external components (Internal oscillator)
  • Excellent long term stability

 

 

Connection

Arduino Module connection
5v Vcc
Gnd Gnd
SCL SCL
SDA SDA

 

Code

This example comes from the https://github.com/jarzebski/Arduino-MS5611 library

#include <Wire.h>
#include <MS5611.h>
 
MS5611 ms5611;
 
double referencePressure;
 
void setup() 
{
  Serial.begin(9600);
 
  // Initialize MS5611 sensor
  Serial.println("Initialize MS5611 Sensor");
 
  while(!ms5611.begin())
  {
    Serial.println("Could not find a valid MS5611 sensor, check wiring!");
    delay(500);
  }
 
  // Get reference pressure for relative altitude
  referencePressure = ms5611.readPressure();
 
  // Check settings
  checkSettings();
}
 
void checkSettings()
{
  Serial.print("Oversampling: ");
  Serial.println(ms5611.getOversampling());
}
 
void loop()
{
  // Read raw values
  uint32_t rawTemp = ms5611.readRawTemperature();
  uint32_t rawPressure = ms5611.readRawPressure();
 
  // Read true temperature & Pressure
  double realTemperature = ms5611.readTemperature();
  long realPressure = ms5611.readPressure();
 
  // Calculate altitude
  float absoluteAltitude = ms5611.getAltitude(realPressure);
  float relativeAltitude = ms5611.getAltitude(realPressure, referencePressure);
 
  Serial.println("--");
 
  Serial.print(" rawTemp = ");
  Serial.print(rawTemp);
  Serial.print(", realTemp = ");
  Serial.print(realTemperature);
  Serial.println(" *C");
 
  Serial.print(" rawPressure = ");
  Serial.print(rawPressure);
  Serial.print(", realPressure = ");
  Serial.print(realPressure);
  Serial.println(" Pa");
 
  Serial.print(" absoluteAltitude = ");
  Serial.print(absoluteAltitude);
  Serial.print(" m, relativeAltitude = ");
  Serial.print(relativeAltitude);    
  Serial.println(" m");
 
  delay(1000);
}

 

Output

Open the serial monitor and you will see something like this

rawTemp = 8422100, realTemp = 23.74 *C
rawPressure = 8600108, realPressure = 99667 Pa
absoluteAltitude = 138.96 m, relativeAltitude = -0.17 m

rawTemp = 8422252, realTemp = 23.75 *C
rawPressure = 8600084, realPressure = 99667 Pa
absoluteAltitude = 138.96 m, relativeAltitude = -0.17 m

rawTemp = 8471308, realTemp = 25.38 *C
rawPressure = 8583196, realPressure = 99682 Pa
absoluteAltitude = 137.69 m, relativeAltitude = -1.44 m

rawTemp = 8545740, realTemp = 27.80 *C
rawPressure = 8558564, realPressure = 99688 Pa
absoluteAltitude = 137.19 m, relativeAltitude = -1.95 m

rawTemp = 8580420, realTemp = 28.93 *C
rawPressure = 8546820, realPressure = 99691 Pa
absoluteAltitude = 136.94 m, relativeAltitude = -2.20 m

 

Link

GY-63 MS5611-01BA03 Precision MS5611 Atmospheric Pressure Sensor Module Height Sensor Module

Share

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