Camera and temp controllin relay

Hi maybe someone can help me. I want to control a relay when (camera && temperature) are true... relay is turns on. When both are true but I can't get the code right. I'm using a DHT11 temp sensor and processing for camera.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

We cannot give you advise until we see your code.

Thanks .. Tom... :slight_smile:

sorry my bad…

#include <dht.h>

int greenPin = 6;  
int redPin = 5;
int bluePin = 9;
int relayPin = 7:
dht DHT;



void setup(){
    Serial.begin(9600);

    pinMode(bluePin, OUTPUT);    //initialize LED output 
  
}
void loop()
{
  if(Serial.available() >0)    //if some data is available of in the serial port
    {   
    char bluePinState = Serial.read();   //read the value
    if(bluePinState == '1')
                 //if statement will be true(1)
      digitalWrite(relayPin, HIGH);       //turn ON the LED
    
    if(bluePinState == '0')
                 //if statement will be false(0)
      digitalWrite(relayPin, LOW);        //turn OFF the LED
    } 
 
 if (DHT.temperature <= 24 )
   {
    digitalWrite(bluePin, LOW);  
   }
 else 
  {
   digitalWrite(bluePin, HIGH);
   delay(5000);
  }
           
  
  
}

Hi,
Can you get the relay to operate using serial?

Tom… :slight_smile:

Hi,

int relayPin = 7:

should be

int relayPin = 7;

a ; instead of a :

Easily done, see if that fixes it.

Tom.... :slight_smile:

I can get serial to operate the relay but what ends up happening is the serial seems to override the temperature no matter what. negating the function.

Hi, I cleaned up the code a bunch but camera still seems to trigger the relay no matter the state of the temperature.

#include <dht.h>

int airtempPin = 6;    //temperature of the air
int coiltempPin = 5;  // temperature of the heating coil
int relayPin = 7;     // turns on by camera and air temperature
int bluePinState;
dht DHT;              // needed for temperature



void setup()
{
    Serial.begin(9600);                   // start serial at 9600
        pinMode(relayPin, OUTPUT);        //initialize relay output
}

void loop(){
{
  int chk = DHT.read11(airtempPin);            // checks the air temperature of airtempPin
  delay(2000);
}
           if(Serial.available() >0)                            //if some data is available of in the serial port
 { 
  char bluePinState = Serial.read();                            //read the value
           if(bluePinState == '1' && DHT.temperature <=18)      //if statement will be true(1) 
              digitalWrite(relayPin, HIGH);                     //turn ON the relay
           if(bluePinState == '0')                              //if statement will be false(0)
              digitalWrite(relayPin, LOW);                      //turn OFF the relay
 }
  
}

How do you know? I'd try displaying the temperature you're reading from the sensor on the serial port to start the debugging process.

I changed temp from >= 18C to <=17C and it didn’t change the state of the relay. in this statement <=17 and air temp is above 18C it would make the statement false. but if i set the trigger to be >=18C and air temp is above this should make statement true thus triggering the relay???

Hi,
I ASSUME that the serial input is the camera input?

I don’t know if this is exactly what you want.

#include <dht.h>

int airtempPin = 6;    //temperature of the air
int coiltempPin = 5;  // temperature of the heating coil
int relayPin = 7;     // turns on by camera and air temperature
char bluePinState = "0";
dht DHT;              // needed for temperature
int airTemperature;
bool airTLow;


void setup()
{
  Serial.begin(9600);                   // start serial at 9600
  pinMode(relayPin, OUTPUT);        //initialize relay output
}

void loop()
{
  airTemperature = DHT.read11(airtempPin);            // checks the air temperature of airtempPin
  delay(2000);
  if (airTemperature <= 18)                           // checks if air temp is in range
  {
    airTLow = 1;
  }
  else
  {
    airTLow = 0;
  }

  if (Serial.available() > 0)                          //if some data is available of in the serial port
  {
    bluePinState = Serial.read();                            //read the value
  }

  if (airTLow == 1 && bluePinState == "1")             // checks for both condition to be true
  {
    digitalWrite(relayPin, HIGH);                     //turn ON the relay
  }
  else
  {
    digitalWrite(relayPin, LOW);                     //turn OFF the relay
  }

}

First read ALL your inputs
Then compare them to produce your output.
Tom… :slight_smile:

thanks i'll give that code a go and let you know of my results.

the code worked pretty good thanks… i would have never have thought of doing

if (airTemperature <= 24)                           // checks if air temp is in range
  {
    airTLow = 1;
  }
  else
  {
    airTLow = 0;
  }

i was wondering if there was a way to assign a 1 or 0 to a temperature…