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
Code:
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.