Skip to content

A demo app that integrates an HCSR04 proximity sensor on a Raspberry PI with an MQTT publisher

Notifications You must be signed in to change notification settings

solacese/raspberry-pi-ultrasonic-sensor-mqtt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

raspberry-pi-ultrasonic-sensor-mqtt

A demo app that integrates an HCSR04 proximity sensor on a Raspberry PI with an MQTT publisher

Setup instructions

The following items will need to be purchased to assemble this kit:

Assembly instructions

Use the following diagram to connect the sensor to the Raspberry PI Breadboard Diagram

(Note the diagram is based on a Raspberry Pi 2 - take note of the pin positions and map it to the Raspberry PI that you have purchased)

Setting up the code

Clone the repo to your pi and install dependencies using the following commands:

git clone https://github.com/solacese/raspberry-pi-ultrasonic-sensor-mqtt.git
cd raspberry-pi-ultrasonic-sensor-mqtt
npm i

do the following:

  • Rename .EDIT-ME.env to .env
  • Fill in the Solace connectivity in the .env file with details from Solace Cloud Console's Connection tab Solace Cloud Details
  • Specify the range (in centimeters) that you would want to have an event be published onto Solace in the .env file as well

Running the code

Use the following command to run the application,

sudo npm run start

If successful, you should see the following output:

=== Starting MQTT producer ===
Connecting MQTT client to Solace...
MQTT client connected to Solace.
Connecting to board...
1583858715516 Available Pi-IO
1583858715614 Connected Pi-IO
1583858715619 Repl Initialized
>> Connected to the board!
Enabling range of proxmity dection to be [10,50]cms
Distance measurement: {"cm":18.299,"centimeters":18.299,"in":7.14,"inches":7.14}

In addition, the distance will be published on the topic SOLACE/DISTANCE/MEASUREMENT for applications to subscribe to.

About

A demo app that integrates an HCSR04 proximity sensor on a Raspberry PI with an MQTT publisher

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published