Categories

Follow Us

Arduino Uno and PAJ7620 gesture sensor example

In this example we connect a PAJ7620 gesture sensor to an Arduino Uno

The PAJ7620 integrates gesture recognition function with general I2C interface into a single chip forming an image analytic sensor system. It can recognize 9 human hand gesticulations such as moving up, down, left, right, forward, backward, circle-clockwise, circle-counter clockwise, and waving.

It also offers built-in proximity detection in sensing approaching or departing object from the sensor. The PAJ7620 is designed with great flexibility in power-saving mechanism, well suit for low power battery operated HMI devices.

The PAJ7620 is packaged into module form in-built with IR LED and optics lens as a complete sensor solution.

Gesture Mode : Single-Object Detection
Image Array Size : 60 x 60
Sampling Rate : 240fps
Operating Distance : 20cm
Output Types : 9 types of Gestures: Up, Down, Left, Right, Forward, Backward, Circle-Clockwise, Circle-Counter Clockwise, and Waving)
Cursor Mode : Yes
Interface : I2C/SPI
Light Source : Integrated IR LED with optics

 

Parts List

name Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
PAJ7620 breakout CJMCU-7620 9 Gesture Moving Recognition Sensor Module PAJ7620U2 I2C 2.8V~3.3V SC
connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Layout

An I2C device that uses 3.3v

 

Code

Again we use a library – https://www.elecrow.com/wiki/images/7/72/Paj7620.zip

#include <Wire.h>
#include "paj7620.h"
 
void setup()
{
Serial.begin(9600);
paj7620Init();
}
 
void loop()
{
uint8_t data = 0; // Read Bank_0_Reg_0x43/0x44 for gesture result.
 
paj7620ReadReg(0x43, 1, &data);
 
if (data == GES_UP_FLAG)
{
Serial.println("GES_UP_FLAG !");
}
 
if (data == GES_DOWN_FLAG)
{
Serial.println("GES_DOWN_FLAG !");
}
 
if(data == GES_FORWARD_FLAG)
{
Serial.println("GES_FORWARD_FLAG !");
}
 
if(data == GES_BACKWARD_FLAG)
{
Serial.println("GES_BACKWARD_FLAG !");
}
 
if(data == GES_RIGHT_FLAG)
{
Serial.println("GES_RIGHT_FLAG !");
}
 
if(data ==GES_LEFT_FLAG)
{
Serial.println("GES_LEFT_FLAG !");
}
 
}

 

 

Output

Open the serial monitor – this is what I saw, move your hands in various directions

INIT SENSOR…
Addr0 =20, Addr1 =76
wake-up finish.
Paj7620 initialize register finished.
GES_BACKWARD_FLAG !
GES_BACKWARD_FLAG !
GES_FORWARD_FLAG !
GES_BACKWARD_FLAG !
GES_FORWARD_FLAG !
GES_BACKWARD_FLAG !
GES_UP_FLAG !
GES_DOWN_FLAG !
GES_UP_FLAG !
GES_DOWN_FLAG !

 

Links

http://www.pixart.com.tw/upload/PAJ7620U2_GDS_v1.0_29032016_20160623194552.pdf

Share

Arduino and Si1145 sensor example

Another sensor reaches the desk, this time it is a Si1145 sensor, we will connect it to an Arduino and test it out

First the sensor

The Si1145/46/47 is a low-power, reflectance-based, infrared proximity, ultraviolet (UV) index, and ambient light sensor with I2C digital interface and programmableevent interrupt output. This touchless sensor IC includes an analog-to-digital converter, integrated high-sensitivity visible and infrared photodiodes, digital signal processor, and one, two, or three integrated infrared LED drivers with fifteen selectable drive levels. The Si1145/46/47 offers excellent performance under a wide dynamic range and a variety of light sources including direct sunlight. The Si1145/46/47 can also work under dark glass covers.

The photodiode response and associated digital conversion circuitry provide excellent immunity to artificial light flicker noise and natural light flutter noise. With two or more LEDs, the Si1146/47 is capable of supporting multiple-axis proximity motion detection. The Si1145/46/47 devices are provided in a 10-lead 2×2 mm QFN package and are capable of operation from 1.71 to 3.6 V over the –40 to +85 °C temperature range.

 

Parts List

name Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
Si1145 breakout SI1145 UV IR Visible Sensor I2C GY1145 Light Breakout Board Module
connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Layout

 

arduino and SI1145

arduino and SI1145

 

Code

This example requires the Adafruit Si1145 library, you can add this via the library manager or download from https://github.com/adafruit/Adafruit_SI1145_Library

#include <Wire.h>
#include "Adafruit_SI1145.h"
 
Adafruit_SI1145 uv = Adafruit_SI1145();
 
void setup() {
  Serial.begin(9600);
 
  Serial.println("Adafruit SI1145 test");
 
  if (! uv.begin()) {
    Serial.println("Didn't find Si1145");
    while (1);
  }
 
  Serial.println("OK!");
}
 
void loop() {
  Serial.println("===================");
  Serial.print("Vis: "); Serial.println(uv.readVisible());
  Serial.print("IR: "); Serial.println(uv.readIR());
 
  // Uncomment if you have an IR LED attached to LED pin!
  //Serial.print("Prox: "); Serial.println(uv.readProx());
 
  float UVindex = uv.readUV();
  // the index is multiplied by 100 so to get the
  // integer index, divide by 100!
  UVindex /= 100.0;  
  Serial.print("UV: ");  Serial.println(UVindex);
 
  delay(1000);
}

 

Output

Open the serial monitor window and you will see something like this

Vis: 261
IR: 293
UV: 0.02
===================
Vis: 261
IR: 295
UV: 0.02
===================
Vis: 261
IR: 263
UV: 0.02
===================

Link

https://www.silabs.com/documents/public/data-sheets/Si1145-46-47.pdf

Share

Arduino and TMP102 digital sensor example

In this article we look at the TMP102 digital sensor and we will connect it up to an Arduino – lets start with some technical info about this sensor

The TMP102 device is a digital temperature sensor ideal for NTC/PTC thermistor replacement where high accuracy is required. The device offers an accuracy of ±0.5°C without requiring calibration or external component signal conditioning. Device temperature sensors are highly linear and do not require complex calculations or lookup tables to derive the temperature. The on-chip 12-bit ADC offers resolutions down to 0.0625°C.

The TMP102 device features SMBus™, two-wire and I2C interface compatibility, and allows up to four devices on one bus. The device also features an SMBus alert function. The device is specified to operate over supply voltages from 1.4 to 3.6 V with the maximum quiescent current of 10 µA over the full operating range.

The TMP102 device is ideal for extended temperature measurement in a variety of communication, computer, consumer, environmental, industrial, and instrumentation applications. The device is specified for operation over a temperature range of –40°C to 125°C.

 

Layout

 

arduino and tmp102

arduino and tmp102

 

Parts List

Name Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
TMP102 breakout TMP102 Digital Temperature Sensor Breakout Board Module 12-bit 1.4V To 3.6VDC Sensor Module Temperature Module
connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Code

This is from the Arduino site with a few tweaks

#include "Wire.h"
#define TMP102_I2C_ADDRESS 72 /* This is the I2C address for our chip. This value is correct if you tie the ADD0 pin to ground. See the datasheet for some other values. */
 
 
void setup() 
{
  Wire.begin(); // start the I2C library
  Serial.begin(115200); //Start serial communication at 115200 baud
}
 
 
void loop() 
{
  getTemp102();
  delay(5000); //wait 5 seconds before printing our next set of readings. 
}
 
void getTemp102()
{
  byte firstbyte, secondbyte; //these are the bytes we read from the TMP102 temperature registers
  int val; /* an int is capable of storing two bytes, this is where we "chuck" the two bytes together. */ 
  float convertedtemp; /* We then need to multiply our two bytes by a scaling factor, mentioned in the datasheet. */ 
  float correctedtemp; 
 
  /* Reset the register pointer (by default it is ready to read temperatures)
You can alter it to a writeable register and alter some of the configuration - 
the sensor is capable of alerting you if the temperature is above or below a specified threshold. */
 
  Wire.beginTransmission(TMP102_I2C_ADDRESS); //Say hi to the sensor. 
  Wire.write(0x00);
  Wire.endTransmission();
  Wire.requestFrom(TMP102_I2C_ADDRESS, 2);
  Wire.endTransmission();
 
 
  firstbyte      = (Wire.read()); 
  /*read the TMP102 datasheet - here we read one byte from
   each of the temperature registers on the TMP102*/
  secondbyte     = (Wire.read()); 
  /*The first byte contains the most significant bits, and 
   the second the less significant */
    val = firstbyte;
    if ((firstbyte & 0x80) > 0) 
    {
      val |= 0x0F00;
    } 
    val <<= 4; 
 /* MSB */
    val |= (secondbyte >> 4);    
/* LSB is ORed into the second 4 bits of our byte.
Bitwise maths is a bit funky, but there's a good tutorial on the playground*/
    convertedtemp = val*0.0625;
    correctedtemp = convertedtemp - 5; 
    /* See the above note on overreading */
 
 
  Serial.print("firstbyte is ");
  Serial.print("\t");
  Serial.println(firstbyte, BIN);
  Serial.print("secondbyte is ");
  Serial.print("\t");
  Serial.println(secondbyte, BIN);
  Serial.print("Concatenated byte is ");
  Serial.print("\t");
  Serial.println(val, BIN);
  Serial.print("Converted temp is ");
  Serial.print("\t");
  Serial.println(val*0.0625);
  Serial.print("Corrected temp is ");
  Serial.print("\t");
  Serial.println(correctedtemp);
  Serial.println();
}

 

Output

Open the serial monitor window and you should see something like this

firstbyte is 10110
secondbyte is 11000000
Concatenated byte is 101101100
Converted temp is 22.75
Corrected temp is 17.75

firstbyte is 11100
secondbyte is 10110000
Concatenated byte is 111001011
Converted temp is 28.69
Corrected temp is 23.69

 

Link

http://www.ti.com/lit/gpn/tmp102

Share

Arduino and MPU-9255 sensor example

In this article we look at the MPU-9255 and an Arduino, lets look at some information about the sensor

MPU-9255 is a multi-chip module (MCM) consisting of two dies integrated into a single QFN package. One die houses the 3-Axis gyroscope and the 3-Axis accelerometer. The other die houses the AK8963 3-Axis magnetometer from Asahi Kasei Microdevices Corporation. Hence, the MPU-9255 is a 9-axis MotionTracking device that combines a 3-axis gyroscope, 3-axis accelerometer, 3-axis magnetometer and a Digital Motion Processor™ (DMP) all in a small 3x3x1mm package available as a pin-compatible upgrade from the MPU-6515.

With its dedicated I2C sensor bus, the MPU-9255 directly provides complete 9-axis MotionFusion™ output. The MPU-9255 MotionTracking device, with its 9-axis integration, on-chip MotionFusion™, and run-time calibration firmware, enables manufacturers to eliminate the costly and complex selection, qualification, and system level integration of discrete devices, guaranteeing optimal motion performance for consumers. MPU-9255 is also designed to interface with multiple non-inertial digital sensors, such as pressure sensors, on its auxiliary I2C port.

MPU-9255 features three 16-bit analog-to-digital converters (ADCs) for digitizing the gyroscope outputs, three 16-bit ADCs for digitizing the accelerometer outputs, and three 16-bit ADCs for digitizing the
magnetometer outputs. For precision tracking of both fast and slow motions, the parts feature a user programmable gyroscope full-scale range of ±250, ±500, ±1000, and ±2000°/sec (dps), a user programmable accelerometer full-scale range of ±2g, ±4g, ±8g, and ±16g, and a magnetometer full-scale range of ±4800µT.

Other industry-leading features include programmable digital filters, a precision clock with 1% drift from -40°C to 85°C, an embedded temperature sensor, and programmable interrupts. The device features I2C and SPI serial interfaces, a VDD operating range of 2.4V to 3.6V, and a separate digital IO supply, VDDIO from 1.71V to VDD.

Communication with all registers of the device is performed using either I2C at 400kHz or SPI at 1MHz. For applications requiring faster communications, the sensor and interrupt registers may be read using SPI at 20MHz.

 

Parts List

Name Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
MPU9255 sensor 1Set IIC/I2C MPU-9255 MPU9255 Three-Axis Gyroscope+Accelerator+Magnetometer Sensor Board Module
connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Schematic/Layout

 

arduino and mpu

arduino and mpu

 

Code

You need to import the https://github.com/Bill2462/MPU9255-Arduino-Library

/*
Raw data example
This example reads raw readings from the magnetometer gyroscope and the accelerometer and then
displays them in serial monitor.
*/
 
#include <MPU9255.h>//include MPU9255 library
 
MPU9255 mpu;
 
void setup() {
  Serial.begin(115200);//initialize Serial port
 
  if(mpu.init())
  {
  Serial.println("initialization failed");
  }
  else
  {
  Serial.println("initialization succesful!");
  }
 
}
 
void loop() {
  mpu.read_acc();//get data from the accelerometer
  mpu.read_gyro();//get data from the gyroscope
  mpu.read_mag();//get data from the magnetometer
 
  //print all data in serial monitor
  Serial.print("AX: ");
  Serial.print(mpu.ax);
  Serial.print(" AY: ");
  Serial.print(mpu.ay);
  Serial.print(" AZ: ");
  Serial.print(mpu.az);
  Serial.print("    GX: ");
  Serial.print(mpu.gx);
  Serial.print(" GY: ");
  Serial.print(mpu.gy);
  Serial.print(" GZ: ");
  Serial.print(mpu.gz);
  Serial.print("    MX: ");
  Serial.print(mpu.mx);
  Serial.print(" MY: ");
  Serial.print(mpu.my);
  Serial.print(" MZ: ");
  Serial.println(mpu.mz);
  delay(100);
}

 

Output

 

List

https://store.invensense.com/datasheets/invensense/PS-MPU-9255.pdf

Share