Go Down

Topic: Air particle sensor not working with MRK WiFi 1010 (Read 105 times) previous topic - next topic

CaedmonS

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: https://wiki.keyestudio.com/Ks0196_keyestudio_PM2.5_Shield

Code:
Code: [Select]
int dustPin = 1;
int ledPower = 7;

float dustVal = 0;
float dustPart = 0;

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

void setup(){
Serial.begin(9600);
pinMode(ledPower,OUTPUT);
pinMode(dustPin, INPUT);
}
 
void loop(){

digitalWrite(ledPower,LOW);
delayMicroseconds(delayTime);
dustVal=analogRead(dustPin);
delayMicroseconds(delayTime2);
digitalWrite(ledPower,HIGH);
delayMicroseconds(offTime);
 
delay(1000);
dustPart = ((dustVal / 1024) -0.0356) * 120000 * 0.035;
Serial.println(dustPart);
}


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.

pert

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:
Code: [Select]
  // 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.

Go Up