0% found this document useful (0 votes)
28 views

Object Detection and Counting Using ESP8266 and TF Luna LiDAR (2)

The project aims to develop an object detection and counting system using an ESP8266 microcontroller and TF Luna LiDAR sensor, with a detection range of 80 cm. The system accurately counts objects based on specific conditions, such as time spent within the detection range and avoidance of false counts due to quick repositioning. Key components include the ESP8266, TF Luna LiDAR, and necessary libraries, with installation steps outlined for setting up the Arduino IDE and connecting hardware.

Uploaded by

pecec516
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Object Detection and Counting Using ESP8266 and TF Luna LiDAR (2)

The project aims to develop an object detection and counting system using an ESP8266 microcontroller and TF Luna LiDAR sensor, with a detection range of 80 cm. The system accurately counts objects based on specific conditions, such as time spent within the detection range and avoidance of false counts due to quick repositioning. Key components include the ESP8266, TF Luna LiDAR, and necessary libraries, with installation steps outlined for setting up the Arduino IDE and connecting hardware.

Uploaded by

pecec516
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Object Detection and Counting Using

ESP8266 and TF Luna LiDAR


Objective of the Project
1. To detect an object within a given range: The detection range is set to 80 cm (can be
customized).
2. To count the number of objects detected: An object is counted only if it remains
within the detection range for more than 1 second.
3. To avoid false counts when an object is removed: If the object is removed from the
detection range, the count does not increase.
4. To avoid false counts when the object is repositioned quickly: If the object is
repositioned within 1 second of removal, even if it remains in the detection range for
more than 1 second, the count does not increase.
5. To count objects accurately when repositioned after sufficient time: If the object is
repositioned after 1 second of removal and remains in the detection range for more than
1 second, the count increases.
6. To avoid re-triggering issues: The system ensures stable and reliable object detection
and counting.

Required Components
 ESP8266 Microcontroller: A low-cost Wi-Fi microcontroller used to process data
from the TF Luna LiDAR sensor and communicate results.
 TF Luna LiDAR Sensor: A compact LiDAR sensor capable of measuring distances
with high accuracy.
 Arduino IDE: Development software for programming and uploading code to the
ESP8266 microcontroller.
 USB Cable: For powering the ESP8266 and uploading code.
 Connecting Wires: To establish connections between the ESP8266 and the TF Luna
LiDAR sensor.
 Power Supply: A suitable power source to ensure stable operation of both the
ESP8266 and the LiDAR sensor.

Required Libararies
1. Wire Library: For I2C communication between the ESP8266 and TF Luna LiDAR.
o Pre-installed in the Arduino IDE.
2. TFLI2C Library: For interfacing with the TF Luna LiDAR sensor.
o Download the TFLI2C Library
3. ArduinoJson Library: For handling JSON serialization and deserialization.
o Download ArduinoJson Library
Installation Steps
1. Set Up Arduino IDE
o Install the latest version of the Arduino IDE from arduino.cc.
o Install the ESP8266 board support package in Arduino IDE.
 Go to File > Preferences.
 Add the following URL to the "Additional Board Manager URLs":
http://arduino.esp8266.com/stable/package_esp8266com_inde
x.json

Go to Tools > Board > Board Manager and search for "ESP8266".

Click Install.
2. Install Required Libraries
o Open Arduino IDE.
o Go to Sketch > Include Library > Manage Libraries.
o Search for TFLI2C and install it.
o Search for ArduinoJson and install it.
3. Connect Hardware
o Connect the TF Luna LiDAR sensor to the ESP8266 using I2C (SDA and SCL
pins).
o Power the ESP8266 and LiDAR using a suitable power source.
4. Upload Code
o Open the provided code in the Arduino IDE.
o Select the correct board and port under Tools > Board and Tools > Port.
o Click Upload to upload the code to the ESP8266.

Program
#include <Wire.h>

#include <TFLI2C.h>

#include "ArduinoJson.h"

TFLI2C tfli2c;

int16_t tfDist;

int16_t tfAddr = TFL_DEF_ADR;

const int THRESHOLD_LIMIT = 80;

const unsigned long MIN_DETECTION_TIME = 1000;


const unsigned long MIN_RETRIGGER_TIME = 1000;

unsigned long objectDetectedTime = 0;

unsigned long objectLeaveTime = 0;

unsigned long lastDetectionTime = 0;

int detectionCount = 0;

bool isObjectDetected = false;

bool isReappearedTooQuickly = false;

StaticJsonDocument<200> doc;

void setup() {

Serial.begin(9600);

Wire.begin();

void loop()

if (tfli2c.getData(tfDist, tfAddr))

if (tfDist <= THRESHOLD_LIMIT)

if (!isObjectDetected)

objectDetectedTime = millis();

isObjectDetected = true;

if (millis() - objectLeaveTime < MIN_RETRIGGER_TIME)

isReappearedTooQuickly = true;

else
{

isReappearedTooQuickly = false;

if (isObjectDetected && (millis() - objectDetectedTime >= MIN_DETECTION_TIME))

if (!isReappearedTooQuickly && millis() - lastDetectionTime >= MIN_RETRIGGER_TIME)

detectionCount++;

lastDetectionTime = millis();

objectLeaveTime = millis();

isObjectDetected = false;

else

if (isObjectDetected)

objectLeaveTime = millis();

isObjectDetected = false;

String jsonOutput= GetJSONString(detectionCount,tfDist);

Serial.println(jsonOutput);
delay(100);

String GetJSONString(int a,int b)

StaticJsonDocument<1024> staticJsonDocument;

staticJsonDocument["Count"] = a;

staticJsonDocument["Dist"] = b;

char docBuf[1024];

serializeJson(staticJsonDocument, docBuf);

return String(docBuf);

How It Works
1. The TF Luna LiDAR sensor continuously measures the distance to objects in its line of
sight.
2. If an object is detected within the defined threshold limit (80 cm):
o The system checks if the object remains within the range for more than 1 second
before counting it.
o If the object is removed and repositioned too quickly, the system avoids
incrementing the count to prevent false triggering.
3. The object count and distance data are serialized into a JSON string and printed to the
Serial Monitor.

Features
 Real-time object detection and counting.
 JSON output for easy integration with other systems.
 Configurable detection thresholds and timing parameters.

Applications
 Smart home automation.
 Industrial object counting systems.
 Robotics and automation.
Output
1.When Object is detected within range for more than 1 second (Count +1)

2.When objected is detected beyond the range (Count does not increase)

3.When objected is removed and re positioned within 1 sec for more than 1 sec (Count does
not increase)
4.When objected is removed and re positioned after 1 sec for more than 1 sec (Count +1)

You might also like