In this tutorial, we’ll learn how to measure distance and gesture by using the SparkFun ZX sensor and Arduino. Movement can be difficult to predict. However, advanced computer technology and artificial intelligence (AI) can detect gestures with ease. One of the least costly ways, however, is via an infrared (IR) sensor.
The IR receiver on the SparkFun ZX sensor offers the ability to recognize and interpret IR radiations. Two IR-emitter LEDs on either side of the ZX’s receiver continuously emit IR radiations. So, whenever an object comes in contact with these IR radiations, they essentially radiate or reflect backward. The IR receiver, then, interprets this occurrence as an object.
The distance between the object and the ZX’s receiver is calculated by recording the time from when the IR is emitted and then reflected back. This is similar to the distance measurement of an ultrasonic sensor but for an IR sensor, the distance range is limited to only 15 cm.
For this project, we’re using a software serial for the sensor interface and Arduino’s main serial monitor for the message printing. You’ll need to first include the software serial library in the code. Then, import the ZX_sensor header file. This file contains type identifiers and constants that correspond with the sensor’s output and settings.
Next, declare the software serial pins (Arduino pins #10 and 11). In the setup function, Arduino’s main serial and the software serial ports must both be initialized and activated at a 115,200bps baud rate.
Data is read and interpreted in the loop function. First, the type of data is read, which is followed by the actual readings. In this case, we’re only checking if the data related to a gesture is available while ignoring all of the other types. If a gesture is found, then the next bytes represent the actual gesture readings.
The data types or message headers for the UART are defined in the ZX_sensor library.
The ZX_UART_Z notes the distance of an object from the sensor. The ZX_UART_X notes the exact location of the object — either to the right or left of the receiver. For this project, we used: ZX_UART_GESTURE. The supported gestures are listed under the structure.
Connect Arduino’s software serial pins with the sensor’s UART port. The sensor is powered through Arduino’s regulator output. To view the output, open Arduino’s serial monitor. You can slide or place the object above the sensor to see the output.
The sensor can be used to lift, release, or move the object sideways in a non-intrusive manner. A video game controller can also be made with this technique.
Where to purchase the parts?
You may also like:
Filed Under: Microcontroller Projects