- Introduction
- Components
- Circuit Diagram
- Getting Started
- Usage
- Use case 1 - Connected furniture
- License
- Acknowledgements
Raspberry PI distance calculator is a simple python project that can be used to measure distance between two points and forward the events to Splunk for further analysis.
It uses GPIO modules of Raspberry PI to trigger an ultrasonic sensor and calculate the difference between send and recieve timestamps.
Ultra Sonic Sensor
An ultrasonic sensor is an electronic device that measures the distance of a target object by emitting ultrasonic sound waves, and converts the reflected sound into an electrical signal.
In order to calculate the distance between the sensor and the object, the sensor measures the time it takes between the emission of the sound by the transmitter to its contact with the receiver.
The formula for this calculation is D = ½ T x C (where D is the distance, T is the time, and C is the speed of sound ~ 343 meters/second).
Following acronyms will be used from here onwards- RPI = Raspberry PI
- GPIO = general-purpose input/output
- Raspberry PI (3 & 4 tested)
- HC-SR04 Ultrasonic Sensor
- Resistor : 330Ω
- Resistor : 470Ω
- Python
- Splunk
Connections from the sensor and components are as below.
For detailed information about the GPIO Pins and description, please check GPIO
- VCC -> Pin 2 of RPI
- GND -> Pin 6 of RPI
- TRIG -> Pin 12 of RPI
- ECHO -> Pin 18 of RPI through 330Ω Resistor
- 330Ω -> Pin 6 of RPI through 470Ω Resistor
Follow the steps to configure and start the project.
RPI Distance Calculator uses Splunk HTTP Collector to send data data to Splunk and then to analyse and visualize data.
Follow the Splunk HEC Documentation to set up Splunk HTTP Event Collector.
If Splunk set up is not available , you may switch off Splunk connections by setting following configuration in config.ini
[ splunk ]
disable = True
-
Install Python3
-
Intall the dependencies
pip3 install configparser pip3 install argparse pip3 install git+git://github.com/georgestarcher/Splunk-Class-httpevent.git
-
Clone or download the repo to raspberry PI
git clone https://github.com/rcpnair/rpi_distance_calc.git
-
Configure config.ini
-
Run the distance.py Add execution permission to the file and run
./distance.py
Program uses config.ini configuration file to get all required parameters.
If any of the parameters are not available, it uses the default values
By default, it looks in the current working directory of the program for config.ini file
You may override it and supply config from other locations using _--config_ or _-c_ parametert from the command line.
./distance.py --config /path/to/config_file_in_ini_format/
Using the distance calculator, height of an adjustable table can be measured and send data to splunk for further analysis.
Distributed under the MIT License. See LICENSE for more information.
Thanks to georgestarcher for an awesome and easy to use Python Class for Splunk HEC