Skip to content

Commit

Permalink
PIR Sensor Documentation- fixes issue #200 (#216)
Browse files Browse the repository at this point in the history
* pirsensor documentation draft

* pir sensor documentation

* fixed improve this doc link for pir

* fix spaces per request

Signed-off-by: Adrian Swindle <[email protected]>

---------

Signed-off-by: Adrian Swindle <[email protected]>
  • Loading branch information
SwindleA authored Mar 27, 2024
1 parent ac620b3 commit 117775e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,28 @@
/**
* The PIRSensorController class is used with the PIRSensorHelper class and RGBHelper class to implement a PIR motion sensor with an RGB LED light.
*/

//tag::ex[]
@Controller("/pirSensor")
public class PIRSensorController {

private final PIRSensorHelper pirSensorHelper;

private final RGBLEDHelper rgbledHelper;

/**
* The PirSensorController constructor.
* @param pirSensor A Pi4J DigitalInput object.
* @param rgbLed A MultiPinConfiguration object.
*/
public PIRSensorController(@Named("pir-sensor")DigitalInput pirSensor,
@Named("rgb-led-2") MultiPinConfiguration rgbLed) {
public PIRSensorController(@Named("pir-sensor") DigitalInput pirSensor, @Named("rgb-led-2") MultiPinConfiguration rgbLed) {
this.pirSensorHelper = new PIRSensorHelper(pirSensor);
this.rgbledHelper = new RGBLEDHelper(rgbLed);
}

/**
* Enables the PIR sensor by adding an event listener which sets the RGB LED to red when movement is detected and green otherwise.
*/
@Get("/enable")
public void enablePIRSensor() {

int[] red = {255,0,0};
int[] green = {0,255,0};

pirSensorHelper.addEventListener(e -> {
if (pirSensorHelper.isMoving) {
rgbledHelper.setColor(red);
Expand All @@ -47,7 +42,6 @@ public void enablePIRSensor() {
}
});
}

/**
* Disables the controller by removing the event listener and turning off the RGB LED.
*/
Expand All @@ -56,5 +50,5 @@ public void disablePIRSensor() {
pirSensorHelper.removeEventListener();
rgbledHelper.ledOff();
}

}
}
//end::ex[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
:imagesdir: img/

ifndef::rootpath[]
:rootpath: ../../
endif::rootpath[]

ifdef::rootpath[]
:imagesdir: {rootpath}{imagesdir}
endif::rootpath[]

==== PIR Sensor
[.text-right]
https://github.com/oss-slu/Pi4Micronaut/edit/develop/pi4micronaut-utils/src/docs/asciidoc/components/inputComponents/pirSensor.adoc[Improve this doc]


===== Overview

This section provides details of the PIR Sensor, including the components and assembly instructions. A Passive Infrared Sensor measures infrared light radiating from objects to detect motion.

===== Components

* PIR Sensor
* Breadboard
* T-Extension Board
* Jumper wires x 3
* Power source (5V)
* 3 x 220Ω resistors
* RGB LED

===== Assembly Instructions
When looking at the bottom of PIR, the pins from left to right are:

. Power: connect the left pin on the PIR to 5V0 on the breadboard
. I/O: connect the middle pin on the PIR to GPIO 13 on the breadboard
. Ground: connect right pin on the PIR to GND on the breadboard
. Set up the RGB LED

===== Circuit Diagram

image::PIR_Sensor_Circuit.png[]


===== Functionality

Use `curl http://localhost:8080/pirSensor/enable` to enable the sensor. Once the sensor is enabled, anytime the sensor detects motion, the RGB LED will turn red. If no motion is detected, the RGB LED will be green.

Use `curl http://localhost:8080/pirSensor/disable` to disable the sensor.


===== Troubleshooting
- Sensor not detecting something:
* Make sure the object is moving. The sensor only detects movement. Once an object stops moving, it is no longer detected.


===== YAML
[source, yaml]

----
pir-sensor:
name: PIR Sensor
address: 13
pull: PULL_DOWN
debounce: 30000
provider: pigpio-digital-input
----

===== Constructor and Methods
The constructor and the methods within the PIRSensorHelper class can be seen in our javadoc link:https://oss-slu.github.io/Pi4Micronaut/javadoc/com/opensourcewithslu/inputdevices/PIRSensorHelper.html[here].

===== Example Controller

====== This controller uses the PIR Sensor to turn an RGB LED red if motion is detected, green otherwise
[source, java]
include::../../../../../../components/src/main/java/com/opensourcewithslu/components/controllers/PIRSensorController.java[tag=ex]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions pi4micronaut-utils/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ include::components/inputComponents/ultraSonicSensor.adoc[]

include::components/inputComponents/touchSwitch.adoc[]

include::components/inputComponents/pirSensor.adoc[]

include::components/outputComponents.adoc[]

Expand Down

0 comments on commit 117775e

Please sign in to comment.