PatriotUltrasonic (community library)


Name Value
Name PatriotUltrasonic
Version 2.0.0
Installs 487
License BSD
Author Ron Lisle
Download .tar.gz
All Versions 2.0.0, 1.0.1

Extend Patriot IoT to support ultrasonic proximity detectors. Patriot provides support for controlling IoT devices using Alexa and iOS devices. This plugin adds the ability to use ultrasonic proximity detectors to control those devices wirelessly also.

Example Build Testing

Device OS Version:

This table is generated from an automated build. Success only indicates that the code compiled successfully.

Library Read Me

This content is provided by the library maintainer and has not been validated or approved.


A Patriot plugin to support ultrasonic proximity detector devices.

This library is used to support HC-SR04 ultrasonic proximity devices. Any 2 Photon I/O pins may be used to provide pulse trigger and echo status.


Include this library in any Photon sketch that needs to support an ultrasonic proximity sensor such as the HC-SR04. These are inexpensive devices that generate an ultrasonic pulse when triggered, and raise an echo line when that pulse is detected. Distance is calculated by measuring the time between the trigger and the received echo. Refer to the more complex examples in the main Patriot IoT examples directory.

This example creates a single ultrasonic proximity device connected to pins A1 and A0.

When the state of the input D4 pin changes, an event named "switch" will be published. Other device can define a behavior that uses this event.

You can use the console to monitor these events.

#include <IoT.h>
#include <PatriotUltrasonic.h>

IoT *iot;

void setup() {
iot = IoT::getInstance();

// Create the HC-SR04 sensor device
Ultrasonic *ultra1 = new Ultrasonic(A1, A0, "Proximity");

// Add it to IoT

void loop() {


Refer to the Patriot Github repository and documentation for more information.


Here's how you can make changes to this library and eventually contribute those changes back.

To get started, clone the library from GitHub to your local machine.

Change the name of the library in to something different. You can add your name at then end.

Modify the sources in and with the new behavior.

To compile an example, use particle compile examples/usage command in Particle CLI or use our Desktop IDE.

After your changes are done you can upload them with particle library upload or Upload command in the IDE. This will create a private (only visible by you) library that you can use in other projects. Do particle library add IoT_myname to add the library to a project on your machine or add the IoT_myname library to a project on the Web IDE or Desktop IDE.

At this point, you can create a GitHub pull request with your changes to the original library.

If you wish to make your library public, use particle library publish or Publish command.


Copyright 2017 Ron Lisle

Refer to the included LICENSE file.

Browse Library Files