/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/eb0db055-5fbb-4fbb-94bc-022c40225b44
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float air_quality;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <ESP8266WiFi.h>
#include "MQ135.h"
const char* ssid = "UniMAP-WiFi";
const char* password = "211151334";
const int air_quality1 = A0;
const int BuzzerPin = 8;
const int G_LED = 9;
const int Y_LED = 10;
const int R_LED = 13;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(15);
pinMode (air_quality1, OUTPUT);
pinMode (BuzzerPin, OUTPUT);
pinMode (G_LED, OUTPUT);
pinMode (Y_LED, OUTPUT);
pinMode (R_LED, OUTPUT);
digitalWrite(G_LED, LOW);
digitalWrite(Y_LED, LOW);
digitalWrite(R_LED, LOW);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
MQ135 gasSensor = MQ135(A0);
float air_quality1 = gasSensor.getPPM ();
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
}
/*
Since AirQuality is READ_WRITE variable, onAirQualityChange() is
executed every time a new value is received from IoT Cloud.
*/
void onAirQualityChange() {
// Add your code here to act upon AirQuality change
if (air_quality <= 100)
{
Serial.println ("FRESH AIR");
digitalWrite (BuzzerPin, LOW);
digitalWrite (G_LED, HIGH);
}
else if (air_quality <= 150 && air_quality >= 101)
{
Serial.println ("POOR AIR");
digitalWrite (BuzzerPin, LOW);
digitalWrite (Y_LED, HIGH);
}
else if (air_quality <= 300 && air_quality >= 151)
{
Serial.println ("UNHEALTHY AIR");
digitalWrite (BuzzerPin, LOW);
digitalWrite (Y_LED, HIGH);
}
else if (air_quality >= 301)
{
Serial.println ("DANGER!");
digitalWrite (BuzzerPin, HIGH);
digitalWrite (R_LED, HIGH);
}
Serial.println ("Air quality value: ");
Serial.print (air_quality1);
Serial.print (" PPM");
delay (500);
}
When i tried to upload it, these errors came out:
error: espcomm_upload_mem failed
Executing command: exit status 2