PrePAN

Sign in to PrePAN

Device::SDS011 Module to work with SDS011 particulate matter sensor

Good

Synopsis

use Device::SDS011;

my $sensor = Device::SDS011->new('/dev/ttyUSB0');

$sensor->sensor_mode(1);    # wake up (if in sleeping mode)
sleep 5;
$sensor->reporting_mode(1); # 1 = Report query mode
$sensor->working_period(0); # 0 = Continuous mode

while (1) {
    my ($pm25, $pm10);
    for (1..3) {
        my ($pm25_tmp,$pm10_tmp) = @{$sensor->query_data};
        $pm25 += $pm25_tmp;
        $pm10 += $pm10_tmp;
        sleep 3;
    }
    printf "PM25:%.2f, PM10:%.2f\n", $pm25/3, $pm10/3;
    $sensor->sensor_mode(0); # enter sleep mode
    sleep 60 * 15;
}

Description

Module to receive data from, and control SDS011 particulate matter sensor. The module uses Device::SerialPort for communicating with sensor. Laser Dust Sensor Control Protocol v1.3 is implemented.

Comments

Please sign up to post a review.