Skip to content
Matthew Dowdell edited this page May 8, 2017 · 2 revisions

Sensly is a ruby library for converting raw sensor data. It supports the following sensors:

  • MQ2
  • MQ7
  • MQ135
  • PM

The MQ sensors can be used as follows:

require 'sensly/sensors/mq2_sensor'

# adc is the raw adc value from the sensor
# r0 is the sensors r0 value
# temp is the temperature when the reading was taken
# humidity is the relative humidity when the reading was taken
sensor = MQ2Sensor.new(adc, r0, temp, humidity)

# output the RsR0 ratio
puts sensor.rs_ro_ratio.round(4)
# output the RsR0 ratio corrected for temperature and humidity
puts sensor.corr_rs_ro_ratio.round(4)

# output the gases detected and their ppm values
sensor.gases do |gas|
    puts "#{gas[:name]} - #{gas[:ppm].round(4)}"
end

The PM sensor can be used as follows:

require 'sensly/sensor/pm_sensor'

# adc is the raw adc value
sensor = PMSensor.new(adc)

# output the particulate matter density detected
puts sensor.pm_density.round(4)

# for convenience, the pm sensor also supports the gases method
sensor.gases.each do |gas|
   puts "#{gas[:name]} - #{gas[:ppm].round(4)}"
end
Clone this wiki locally