Automation system

I have been did my project that i can control LED, FAN, SOLENOID DOOR LOCK, and monitor Temperature sensor using TM35 and DHT11

This is my circuit

And this is the cayenne dashboard

The led , and motion sensor is working fine but the other is not

Could you ppppllease help me

Here is the code

When i compile there is no error but i cant control remotely

can you copy and paste the code rather than sending a screenshot.

  #include <DHT.h>
#include <DHT_U.h>

#define CAYENNE_DEBUG      
//#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneTemperature.h>
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

#define VIRTUAL_CHANNEL_LED2 2
#define ACTUATOR_PIN_LED2 2
#define VIRTUAL_CHANNEL_LED3 3
#define ACTUATOR_PIN_LED3 3

#define VIRTUAL_CHANNEL_FAN1 4
#define ACTUATOR_PIN_FAN1 4

#define VIRTUAL_CHANNEL_Temp 1 //is temp 36 sensor 

//#define VIRTUAL_CHANNEL_DHT2 2
#define DHTPIN 8
#define DHTTYPE DHT11
#define TEMPERATURE_VIRTUAL_CHANNEL 12
#define HUMIDITY_VIRTUAL_CHANNEL 11

#define SENSOR_PIN_Motion 9 
#define VIRTUAL_CHANNEL_Motion 9

#define VIRTUAL_CHANNEL_DOORLOCK 10
#define ACTUATOR_PIN_DOORLOCK 10

//Motion Sensor
int previousState = -1;
int currentState = -1;
unsigned long previousMillis = 0;


// Analog pin the TMP36 is connected to.
const int tmpPin = 0;

const float voltage = 5.0;

TMP36 tmpSensor(tmpPin, voltage);

//DHT SENSOR
DHT dht(DHTPIN, DHTTYPE);


void setup() {
  pinMode(SENSOR_PIN_Motion, INPUT);
  Serial.begin(9600);
  pinMode(ACTUATOR_PIN_LED2, OUTPUT);
  pinMode(ACTUATOR_PIN_LED3, OUTPUT);
  pinMode(ACTUATOR_PIN_DOORLOCK, OUTPUT);

  Cayenne.begin(username, password, clientID);
  dht.begin();
}


void loop() {
  Cayenne.loop();
  checkSensor();
}


//Temp sensor
CAYENNE_OUT(VIRTUAL_CHANNEL_Temp)
{
  // This command writes the temperature in Celsius to the Virtual Channel.
 Cayenne.celsiusWrite(VIRTUAL_CHANNEL_Temp, tmpSensor.getCelsius());
  // To send the temperature in Fahrenheit or Kelvin use the corresponding code below.
 // Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL_Temp, tmpSensor.getFahrenheit());
  //Cayenne.kelvinWrite(VIRTUAL_CHANNEL_Temp, tmpSensor.getKelvin());
}


//motion sensor
void checkSensor()
{
  unsigned long currentMillis = millis();
  // Check sensor data every 250 milliseconds
  if (currentMillis - previousMillis >= 250) {
    // Check the sensor state and send data when it changes.
    currentState = digitalRead(SENSOR_PIN_Motion);
    if (currentState != previousState) {
      Cayenne.virtualWrite(VIRTUAL_CHANNEL_Motion, currentState, "digital_sensor", "d");
      previousState = currentState;
    }
    previousMillis = currentMillis;
  }
}


//LED2
CAYENNE_IN(VIRTUAL_CHANNEL_LED2)
{
  int value = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_LED2, ACTUATOR_PIN_LED2, value);
  // Write the value received to the digital pin.
  digitalWrite(ACTUATOR_PIN_LED2, value);
}

//LED3
CAYENNE_IN(VIRTUAL_CHANNEL_LED3)
{
  int value = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_LED3, ACTUATOR_PIN_LED3, value);
  // Write the value received to the digital pin.
  digitalWrite(ACTUATOR_PIN_LED3, value);
}

//FAN
CAYENNE_IN(VIRTUAL_CHANNEL_FAN1)
{
  int value = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_FAN1, ACTUATOR_PIN_FAN1, value);
  // Write the value received to the digital pin.
  digitalWrite(ACTUATOR_PIN_FAN1, value);
}


//DHT SENSOR
CAYENNE_OUT(TEMPERATURE_VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite(TEMPERATURE_VIRTUAL_CHANNEL, dht.readTemperature(), "temp", "c");
}
CAYENNE_OUT(HUMIDITY_VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite(HUMIDITY_VIRTUAL_CHANNEL, dht.readHumidity(), "rel_hum", "p");
}



//DOORLOCK


CAYENNE_IN(VIRTUAL_CHANNEL_DOORLOCK)
{
  int value = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL_DOORLOCK, ACTUATOR_PIN_DOORLOCK, value);
  // Write the value received to the digital pin.
  digitalWrite(ACTUATOR_PIN_DOORLOCK, value);
}

Arduino uses digital pins 10, 11, 12, and 13 (SPI) to communicate with the W5100 on the ethernet shield. so do not use it.
Other then this, i have not found any issue in the code.

Yes I change it and It work fine, but a little slow,

what about the fan and Temperature sensor

is your arduino capable of powering the fan directly?

For temperature you can run the basic code to see if any fault with the sensor DHT-sensor-library/DHTtester.ino at master · adafruit/DHT-sensor-library · GitHub

I will try the DHT code,

I’m using the Arduino Uno

i know you are using arduino uno, but is your arduino uno capable to supply enough power to the fan? You might want to check the specs of both arduino uno pins and the fan.
if you want to check, add the #define CAYENNE_PRINT Serial back in your code and check the serial monitor if you are receiving the data from cayenne when the button is pressed.

When i add the #define CAYENNE_PRINT Serial Still not working

it wont work, i said if you want to see if the cayenne data is received to enable the serial print option.

@AdwaaBukh If your fan runs at 5V, you must power it externally too using a relay as you did for door lock.

1 Like