#include #include #include #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the I2C bus address for an unmodified module // 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); lcd.setBacklightPin(3,POSITIVE); lcd.setBacklight(HIGH); // NOTE: You can turn the backlight off by setting it to LOW instead of HIGH lcd.begin(16, 2); lcd.clear(); } 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); dustiness = (0.17 * voltageConversion - 0.1)*1000; Serial.print("Dust concentration: "); Serial.print(dustiness); Serial.println(" ug/m3"); delay(500); lcd.setCursor(0,0); lcd.print("Dust value:"); lcd.setCursor(0,1); lcd.println(dustiness); lcd.setCursor(11,1); lcd.print("ug/m3"); } CAYENNE_OUT(V0) { Cayenne.virtualWrite(V0, dustiness); }