loading

TMD26721 is an infrared digital proximity detector which provides a complete proximity detection system and digital interface logic in a single 8-pin surface mount module.The proximity detection includes improved signal-to-noise and accuracy. A proximity offset register allows compensation for optical system crosstalk between the IR LED and the sensor. Here is its demonstration with raspberry pi using java code.

Step 1: What You Need..!!

1. Raspberry Pi

2. TMD26721

LINK : https://www.controleverything.com/content/Proximity?sku=TMD26721_I2CS

3. I²C Cable

LINK : https://www.controleverything.com/content/I2C-Cables?sku=I2CAFF3

4. I²C Shield for Raspberry Pi

LINK : https://www.controleverything.com/content/I2C-Master?sku=TOUTPI2

5. Ethernet Cable

Step 2: Connections:

Take an I2C shield for raspberry pi and gently push it over the gpio pins of raspberry pi.

Then connect the one end of I2C cable to TMD26721 sensor and the other end to the I2C shield.

Also connect the Ethernet cable to the pi or you can use a WiFi module.

Connections are shown in the picture above.

Step 3: Code:

The java code for TMD26721 can be downloaded from our github repository- ControlEverythingCommunity

Here is the link for the same :

https://github.com/ControlEverythingCommunity/TMD2...

The datasheet of TMD26721 can be found here:

https://s3.amazonaws.com/controleverything.media/c...

We have used pi4j library for java code, the steps to install pi4j on raspberry pi is described here:

http://pi4j.com/install.html

You can also copy the code from here, it is given as follows:

// Distributed with a free-will license.

// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.

// TMD26721

// This code is designed to work with the TMD26721_I2CS I2C Mini Module available from ControlEverything.com.

// https://www.controleverything.com/content/Proximi...

import com.pi4j.io.i2c.I2CBus;

import com.pi4j.io.i2c.I2CDevice;

import com.pi4j.io.i2c.I2CFactory;

import java.io.IOException;

public class TMD26721

{

public static void main(String args[]) throws Exception

{

// Create I2C bus

I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);

// Get I2C device, TMD26721 I2C address is 0x39(57)

I2CDevice device = bus.getDevice(0x39);

// Select proximity time register OR with command register

// Ptime = 2.73 ms

device.write(0x02 | 0x80, (byte)0xFF);

// Select wait time register OR with command register

// Wtime = 2.73 ms

device.write(0x03 | 0x80, (byte)0xFF);

// Select pulse count register OR with command register

// Pulse count = 32

device.write(0x0E | 0x80, (byte)0x20);

// Select control register OR with command register

// 100 mA LED strength, proximtiy uses CH1 diode, 1x PGAIN, 1x AGAIN

device.write(0x0F | 0x80, (byte)0x20);

// Select enable register OR with command register

// Set Power ON, proximity and wait enabled

device.write(0x00 | 0x80, (byte)0x0D);

Thread.sleep(800);

// Read 2 bytes of data from address 0x18(24)

// proximity lsb, proximity msb

byte[] data = new byte[2];

device.read(0x18 | 0x80, data, 0, 2);

// Convert the data

int proximity = (((data[1] & 0xFF) * 256)+ (data[0] & 0xFF));

// Output data to screen

System.out.printf("Proximity Of the Device : %d %n", proximity);

}

}

Step 4: Applications:

TMD26721 is an infrared digital proximity sensor which can be incorporated in Mobile Handset Touchscreen Control and Automatic Speakerphone Enable. It can also provide Mechanical Switch Replacement as well as Paper Alignment. Its high efficiency and reliability makes it suitable for various proximity sensing applications.

About This Instructable

81views

0favorites

More by Dcube Tech Ventures:Home Automation with Raspberry Pi using Relay board Motion Control with Raspberry Pi and LIS3DHTR, 3-Axis Accelerometer, using Python 3-Axis Accelerometer, ADXL345 with Raspberry Pi using Python 
Add instructable to: