#define CAYENNE_DEBUG // Uncomment to show debug messages #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include #include "DHT.h" #include #define DHTPIN 2 //Sensor DHT #define DHTTYPE DHT11 //DHT22 (AM2302), AM232 #define RELAY_DIGITAL_PIN3 3 //Luz garagem superior #define RELAY_DIGITAL_PIN4 4 //Luz quartinho #define TIP_DIGITAL_PIN5 5 //Resistencia boiler #define RELAY_DIGITAL_PIN6 6 //Persiana Mateo #define RELAY_DIGITAL_PIN7 7 //Persiana Mateo // Analog pin the thermistor is connected to. const int thermistorPin = 0; // Resistance of the resistor. Currently set to 10k but this can be set to the measured resistance of your // resistor for greater accuracy. const float resistance = 10000; // Cayenne authentication token. This should be obtained from the Cayenne Dashboard. char token[] = "1384addwa9"; Thermistor thermistor(thermistorPin, resistance); DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); Cayenne.begin(token); dht.begin(); pinMode(RELAY_DIGITAL_PIN3, OUTPUT); pinMode(RELAY_DIGITAL_PIN4, OUTPUT); pinMode(TIP_DIGITAL_PIN5, OUTPUT); pinMode(RELAY_DIGITAL_PIN6, OUTPUT); pinMode(RELAY_DIGITAL_PIN7, OUTPUT); } void loop() { Cayenne.run(); } //Sensor DHT11 - Temperatura, Umidade CAYENNE_OUT(V0) { float t = dht.readTemperature(); float f = dht.readTemperature(true); Cayenne.celsiusWrite(V0, t); //virtual pin } CAYENNE_OUT(V1) { float h = dht.readHumidity(); Cayenne.celsiusWrite(V1, h); //virtual pin } CAYENNE_OUT(V7) { // Compute heat index // Must send in temp in Fahrenheit! float f = dht.readTemperature(true); float h = dht.readHumidity(); float hi = dht.computeHeatIndex(f, h); float hiDegC = dht.convertFtoC(hi); Cayenne.celsiusWrite(V7, hiDegC); //virtual pin } //Controle do rele luz garagem superior CAYENNE_IN(V2) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(RELAY_DIGITAL_PIN3, HIGH); } else { digitalWrite(RELAY_DIGITAL_PIN3, LOW); } } CAYENNE_IN(V3) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(RELAY_DIGITAL_PIN3, HIGH); } else { digitalWrite(RELAY_DIGITAL_PIN3, LOW); } } //Controle do rele luz quartinho CAYENNE_IN(V4) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(RELAY_DIGITAL_PIN4, HIGH); } else { digitalWrite(RELAY_DIGITAL_PIN4, LOW); } } CAYENNE_IN(V5) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(RELAY_DIGITAL_PIN4, HIGH); } else { digitalWrite(RELAY_DIGITAL_PIN4, LOW); } } //Temperatura Boiler CAYENNE_OUT(V6) { // This command writes the temperature in Celsius to the Virtual Pin. Cayenne.celsiusWrite(V6, thermistor.getCelsius()); // To send the temperature in Fahrenheit or Kelvin use the corresponding code below. //Cayenne.fahrenheitWrite(VIRTUAL_PIN, thermistor.getFahrenheit()); //Cayenne.kelvinWrite(VIRTUAL_PIN, thermistor.getKelvin()); // Serial.print("Thermistor resistance "); // Serial.println(thermistor.getCelsius()); delay(1000); } //Acionar resistência do Boiler CAYENNE_IN(V8) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(TIP_DIGITAL_PIN5, HIGH); } else { digitalWrite(TIP_DIGITAL_PIN5, LOW); } } CAYENNE_IN(V9) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(TIP_DIGITAL_PIN5, HIGH); } else { digitalWrite(TIP_DIGITAL_PIN5, LOW); } } CAYENNE_OUT(V10) { { int SensorValue = analogRead(A1); //take a sample //Serial.print(SensorValue); Serial.print(" - "); if(SensorValue >= 1000) { //Serial.println("Sensor is not in the Soil or DISCONNECTED"); } if(SensorValue < 1000 && SensorValue >= 800) { // Serial.println("Soil is DRY"); } if(SensorValue < 800 && SensorValue >= 550) { //Serial.println("Soil is HUMID"); } if(SensorValue < 550) { //Serial.println("Sensor in WATER"); } delay(50); int soilMoisture = map(SensorValue, 500, 1023, 0, 100); analogWrite(V10, soilMoisture); delay(1000); } } //Controle da persiana quarto Mateo CAYENNE_IN(V11) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(RELAY_DIGITAL_PIN6, HIGH); delay (10000); digitalWrite(RELAY_DIGITAL_PIN6, LOW); } else { digitalWrite(RELAY_DIGITAL_PIN6, LOW); } } CAYENNE_IN(V12) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(RELAY_DIGITAL_PIN7, HIGH); } else { digitalWrite(RELAY_DIGITAL_PIN7, LOW); } }