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 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