Same sketch different reading on Yun and Uno (pulsein() / millis())

Hello All,

My goal is to use an arduino yun and the dust grove sensor to send the air quality data to a server. The dust grove sensor is connected via pin 8 for data and Vcc and GND to the arduino. The arduino is connected via USB to my laptop. The downloaded sketch uses pulsin() and millis() to calculate the sampletime and the duration that pin 8 is low. I've noticed that I have totally different readings on a Yun and an Uno. Which is now correct? Any thoughts that pulsin() or millis () function act different on a Yun/Uno or is this a volltage relarted issues? If you have any suggestions, please let me know!

/*
Grove - Dust Sensor Demo v1.0
 Interface to Shinyei Model PPD42NS Particle Sensor
 Program by Christopher Nafis 
 Written April 2012

 http://www.seeedstudio.com/depot/grove-dust-sensor-p-1050.html
 http://www.sca-shinyei.com/pdf/PPD42NS.pdf

 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 = 2000;//sampe 30s ;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;

void setup() {
  Serial.begin(9600);
  pinMode(8,INPUT);
  starttime = millis();//get the current time;
}

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

  if ((millis()-starttime) >= sampletime_ms)//if the sampel time = = 30s
  {
    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("concentration = ");
    Serial.print(concentration);
    Serial.println(" pcs/0.01cf");
    Serial.println("\n");
    lowpulseoccupancy = 0;
    starttime = millis();
  }
}

Output: Yun concentration = 13159.19 pcs/0.01cf concentration = 5805.76 pcs/0.01cf concentration = 3485.70 pcs/0.01cf concentration = 4129.98 pcs/0.01cf concentration = 3826.19 pcs/0.01cf concentration = 3605.94 pcs/0.01cf

Uno concentration = 45.30 pcs/0.01cf concentration = 0.62 pcs/0.01cf concentration = 0.62 pcs/0.01cf concentration = 0.62 pcs/0.01cf concentration = 0.62 pcs/0.01cf concentration = 0.62 pcs/0.01cf

Getting Started with the Arduino Yún

The Arduino Yún is an Arduino board unlike any other. While programming it is very similar to the Arduino Leonardo and uses the same processor, the Atmel ATmega32U4 (...)

In addition, they both different processor clocks. Read the spec sheets.

FWIW: the Yun has an entire server on the package. It is running a Linux variant - OpenWrt.

Jesse

Issue has been solved. I connected the sensor to an external 5v and now the same values are given on the yun as on thae uno. It seems that the yun had a lower 5v then the uno.

Feedback: Issue has been solved. I connected the sensor to an external 5v and now the same values are given on the yun as on thae uno. It seems that the yun had a lower 5v then the uno.

@Feedback, yes, that is correct. Yun has a reference of 4.8v - if I am not mistaken. Yes it is a constant issue for developers.

Best of Luck Jesse