Skip to content

Commit

Permalink
Class and example for simple AS312 PIR motion sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
vickash committed Oct 8, 2023
1 parent c681117 commit a1ae5bc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion HARDWARE.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Polling and reading follow a call and response pattern.
| :--------------- | :------: | :-------- | :--------------- |------ |
| BH1750 | :heart: | Digital In | `Sensor::BH1750` | Ambient Light
| HC-SR501 | :yellow_heart: | Digital In | `DigitalIO::Input` | PIR. Needs class: `Sensor::HC-SR501`
| AS312 | :heart: | I2C | `Sensor::AS312` | PIR
| AS312 | :green_heart: | I2C | `Sensor::AS312` | PIR (based on `DigitalIO::Input`)
| TCS34725 | :heart: | I2C | `Sensor::TCS34725` | RGB
| APDS9960 | :heart: | I2C | `Sensor::APDS9960` | Proximity, RGB, Gesture

Expand Down
16 changes: 16 additions & 0 deletions examples/sensor/as312.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Example using AS312 PIR motion sensor.
#
require 'bundler/setup'
require 'denko'

board = Denko::Board.new(Denko::Connection::Serial.new)
sensor = Denko::Sensor::AS312.new(board: board, pin: 8)

sensor.on_motion_start { print "Motion detected! \r" }
sensor.on_motion_stop { print "No motion detected...\r" }

# Trigger an initial read.
sensor.read

sleep
1 change: 1 addition & 0 deletions lib/denko/sensor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ module Sensor
autoload :SHT3X, "#{__dir__}/sensor/sht3x"
autoload :QMP6988, "#{__dir__}/sensor/qmp6988"
autoload :RCWL9620, "#{__dir__}/sensor/rcwl9620"
autoload :AS312, "#{__dir__}/sensor/as312"
end
end
8 changes: 8 additions & 0 deletions lib/denko/sensor/as312.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Denko
module Sensor
class AS312 < DigitalIO::Input
alias :on_motion_stop :on_low
alias :on_motion_start :on_high
end
end
end

0 comments on commit a1ae5bc

Please sign in to comment.