#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include // Cayenne authentication token. This should be obtained from the Cayenne Dashboard. char token[] = "token"; int measuringPin = A0; int ledPin = 2; const int timeMeasuring = 280; const int timeStabilization = 40; const int timeSleep = 9680; float voltageAnalog = 0; float voltageConversion = 0; float dustiness = 0; void setup() { Serial.begin(9600); pinMode(ledPin,OUTPUT); Cayenne.begin(token); } void loop() { Cayenne.run(); digitalWrite(ledPin,LOW); delayMicroseconds(timeMeasuring); voltageAnalog = analogRead(measuringPin); delayMicroseconds(timeStabilization); digitalWrite(ledPin,HIGH); delayMicroseconds(timeSleep); voltageConversion = voltageAnalog * (4.6 / 1024.0); //voltage on 5V pin dustiness = (0.17 * voltageConversion - 0.1)*1000; Serial.print("Dust concentration: "); Serial.print(dustiness); Serial.println(" ug/m3"); delay(1000); } CAYENNE_OUT(V0) { Cayenne.virtualWrite(V0, dustiness); }