dust sensor shinyei ppd42ns

Post your requests and ideas for the mikroElektronika website & forums.
Post Reply
Author
Message
amar
Posts: 1
Joined: 21 May 2015 09:08

dust sensor shinyei ppd42ns

#1 Post by amar » 21 May 2015 09:20

can anyone help how to translate coding from arduino to microC. should i use timer 0 or counter mode to detect low pulse for pwm?

Image
JST Pin 1 (Black Wire) => Arduino GND
JST Pin 3 (Red wire) => Arduino 5VDC
JST Pin 4 (Yellow wire) => Arduino Digital Pin 8


int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;

void setup() {
Serial.begin(9600);
pinMode(8,INPUT);
starttime = millis();
}

void loop() {
duration = pulseIn(pin, LOW);
lowpulseoccupancy = lowpulseoccupancy+duration;

if ((millis()-starttime) > sampletime_ms)
{
ratio = lowpulseoccupancy/(sampletime_ms*10.0); // Integer percentage 0=>100
concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
Serial.print(lowpulseoccupancy);
Serial.print(",");
Serial.print(ratio);
Serial.print(",");
Serial.println(concentration);
lowpulseoccupancy = 0;
starttime = millis();
}
}

User avatar
Aleksandar.Mitrovic
mikroElektronika team
Posts: 1697
Joined: 11 Mar 2015 12:48

Re: dust sensor shinyei ppd42ns

#2 Post by Aleksandar.Mitrovic » 29 May 2015 09:43

Hi,

Yes you can use Timer to detect low pulse for PWM.

On this topic you can find some solution for that:
http://www.mikroe.com/forum/viewtopic.p ... se+for+pwm

Best regards,
Aleksandar

Post Reply

Return to “Website & Forums Wishlist”