Greenhouse automation

Hi everyone

I´m developing a project that´s consist on automating a greenhouse ,i´m new at this and i start exploring cayenne one week ago and so far i was able to control temperature and humidity and luminosity through a dht11 sensor and a ldr sensor but now i was starting to explore lighting up a led by clicking a button but when i click it doesn´t light up and after a while it lights itselfs and shut down it self, but if i put it individually it works perfectly and i can put it on and off corectly. I can´t understand where is the problem . Can someone help me please ?? Thanks

Hello,
Can you please provide more information about the board and devices that you are using. Also some code to provide? I am also making an greenhouse automation and I have implemented all the functionalities that you have listed.

Yes sure I´m using a dht11 sensor to read temperature and humidity and a ldr sensor, i´ve created 4 virtual pins two for showing the value and another two to show the graphs. But after that i wanted to try turn on a led when the temperature reaches 30º so i created a new widget that is a button to turn on and off the led connected to the port 8. Below is the code i use.

//--------------------------------------------------------------------------->>>>>>>>>>>>>>>>>>>>>>>


#include <dht.h>
#define CAYENNE_DEBUG         // Cayenne Code Uncomment to show debug messages
#define DHT11_PIN A1            // what digital pin we're connected to
#define CAYENNE_PRINT Serial  // Cayenne Code Comment this out to disable prints and save space
#include <CayenneEthernet.h>  // Cayenne Code Change this to use a different communication device. See Communications examples.


char token[] = "dr1fhuithq";


dht DHT;

#define VIRTUAL_PIN V1
#define VIRTUAL_PIN V2
#define VIRTUAL_PIN V3
#define VIRTUAL_PIN V4




void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");
  Cayenne.begin(token);


  DHT.temperature = 0;
}

void loop() {

  int chk = DHT.read11(DHT11_PIN);
  Cayenne.run();

  // Wait a few seconds between measurements.
  delay(5000);

 
  float t = DHT.temperature;
  
  float h = DHT.humidity;


  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }


  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);

  delay(10);

}


CAYENNE_OUT(V1)
{
  Cayenne.virtualWrite(V1, DHT.temperature);
}

CAYENNE_OUT(V2)
{
  Cayenne.virtualWrite(V2, DHT.humidity);
}

CAYENNE_OUT(V3)
{
  Cayenne.virtualWrite(V3, DHT.temperature, TEMPERATURE, CELSIUS);

}
CAYENNE_OUT(V4)
{
  Cayenne.virtualWrite(V4, DHT.humidity);

}

Okey, can you just send the code in .txt file. I will modify it for you and then tell you on which port to plug the switch and how to add it in Cayenne ?

How can i send it to you in text file ?

You can just drag it to the edit window like this.

secret.txt.txt (6 Bytes)

The file only says secret inside.

I saw that you have edited your post. I will give you new source code to test. I will post it later when i get back :slight_smile:

Ok no problem. Thanks

Okey, here is the code:

I define digital pin number 8 to connect your led (you can change it but don’t use 1 or 2!! ).
After that you can add custom widget (actuator to virtual pin 5) to trigger on/off your led. Please test it and if everything is ok we can make to turn this led on at 30 degrees by two ways

  1. Adding a trigger in cayenne

  2. Hardcode it in arduino sketch

    #include <dht.h>
    #define CAYENNE_DEBUG // Cayenne Code Uncomment to show debug messages
    #define DHT11_PIN A1 // what digital pin we’re connected to
    #define CAYENNE_PRINT Serial // Cayenne Code Comment this out to disable prints and save space
    #include <CayenneEthernet.h> // Cayenne Code Change this to use a different communication device. See Communications examples.

    char token = “dr1fhuithq”;

    dht DHT;

    #define VIRTUAL_PIN V1
    #define VIRTUAL_PIN V2
    #define VIRTUAL_PIN V3
    #define VIRTUAL_PIN V4
    #define LED_VIRTUAL_PIN V5
    #define LED_DIGITAL_PIN 8

    void setup() {
    Serial.begin(9600);
    Serial.println(“DHTxx test!”);
    Cayenne.begin(token);

    DHT.temperature = 0;
    }

    void loop() {

    int chk = DHT.read11(DHT11_PIN);
    Cayenne.run();

    // Wait a few seconds between measurements.
    delay(5000);

    float t = DHT.temperature;

    float h = DHT.humidity;

    if (isnan(t) || isnan(h)) {
    Serial.println(“Failed to read from DHT sensor!”);
    return;
    }

    Serial.print(“Humidity: “);
    Serial.print(h);
    Serial.print(” %\t”);
    Serial.print("Temperature: ");
    Serial.print(t);

    delay(10);

    }

    CAYENNE_OUT(V1)
    {
    Cayenne.virtualWrite(V1, DHT.temperature);
    }

    CAYENNE_OUT(V2)
    {
    Cayenne.virtualWrite(V2, DHT.humidity);
    }

    CAYENNE_OUT(V3)
    {
    Cayenne.virtualWrite(V3, DHT.temperature, TEMPERATURE, CELSIUS);

    }
    CAYENNE_OUT(V4)
    {
    Cayenne.virtualWrite(V4, DHT.humidity);

    }

    CAYENNE_IN(V5) {
    int enabled = getValue.asInt();
    if (enabled == 1) {
    digitalWrite(LED_DIGITAL_PIN, HIGH);
    }
    else {
    digitalWrite(LED_DIGITAL_PIN, LOW);
    }
    }

Hi

It does not work but i realise i can just code it on the arduino because it´s simplier and use cayenne just to show values. Thanks anyway for your time and sorry for something

Yes, It does not work because I forgot to add the specification of the pin that needs to be output. Can you please add this code in the void setup fragment:

pinMode(LED_DIGITAL_PIN, OUTPUT);

yes i had and its still doesn´t work but dont worry I will only use cayenne for showing values. Thanks anyway

Seems strange… Yes but I is still good to use the full functionalities of Cayenne. Yes I agree that right now is a Cloud based solution but soon it will be available also in offline mode I believe :slight_smile:

Yes great :slight_smile: