Air particle sensor not working with MRK WiFi 1010

Hello All,

I have had this issue with a sensor that I have never had before. I am trying to use an air particle sensor with the MRK WiFi 1010 board. I used some code that I found online and it worked perfectly while testing the sensor on my Mega 2560 outputting a value of around 500 (average air quality). However, as soon as I tried the sensor the MRK WiFi 1010 board it would spit out values of around -130 (not a valid reading). I have played around with it for around 2 hours but it won't work. I tried changing power supplies, changing pins, changing code but nothing works. To clarify, I am using the exact same code and pin setup. I know that the A1 pin is reading something, because as soon as I disconnect it the serial output jumps from -130 to around 1400. Here is my sensor and code:

Sensor: Ks0196 keyestudio PM2.5 Shield - Keyestudio Wiki


int dustPin = 1;
int ledPower = 7;

float dustVal = 0; 
float dustPart = 0;

int delayTime = 280;
int delayTime2 = 40;
float offTime = 9680;

void setup(){
pinMode(dustPin, INPUT);
void loop(){

dustPart = ((dustVal / 1024) -0.0356) * 120000 * 0.035;

Lastly, I think that the issue could be pin 7. When I disconnected pin 7 on the Mega I got the same results (around -130) as I am getting with everything connected on the MRK WiFi 1010. The only answer I can think of for this is that the MRK WiFi cannot deal with "delayMicroseconds();" but that is just a guess.

Any help would be greatly appreciated. I am gone for the next 4 days (sports meet), so I am not be able to answer any questions until I come back. Thanks for the help in advance.

analogRead() will return a value of 0-1023 scaled from 0 V to Vcc. On the Mega, Vcc is ~5 V. On the MKR WiFi 1010 Vcc is ~3.3 V. Unfortunately, keyestudio doesn't provide all the essential information about this sensor at that link, but if you look up the sensor's datasheet on Google you will see that the output is from 0-3.4 V. So it only makes sense that you will get a different reading between the two different Arduino boards. Your code is written with the assumption that Vcc is 5 V. If you look at the project 1 code at the link you provided, you'll see it has these lines:

  // 0 - 5V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (5.0 / 1024.0);

The "5.0" is the part where Vcc is assumed to be 5 V. So you can easily modify this code for a 3.3 V system.