Go Down

Topic: Chicken Coop - LCD + 2 Fans + 2 Lights + RTC + DHT11 + Stepper (Read 3 times) previous topic - next topic

PaulS

Quote
Paul doesn't seem to understand the issue.

Perhaps because you have not stated the problem clearly enough.

Something like this. I see this in the serial monitor:
Quote
Time to turn the relay.


My code looks like this:
Code: [Select]
Serial.print("Time to turn the relay on");
digitalWrite(relayPin, HIGH);


The relay does not come on.

Now, something like that would be easy to troubleshoot.

34DOL

Read up ^.  The relays cycle when using a test code (i.e. one that cycles the relay and does nothing else) but don't with the attached code.  The test code I used was essentially the same code as you listed in your preceding post.

I think its time for you to move on PaulS.  This issue seem to be above your level of competency.  Thanks for your help.

PaulS

One last post, then I'll leave you alone.
Why are you reading the temperature so many times?

Code: [Select]
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (dht.readTemperature() >= 20)
  {
    digitalWrite(Relay_1, RELAY_OFF);
  }
  else if (dht.readTemperature() < 18)
  {
    digitalWrite(Relay_1, RELAY_ON);
  }

  //Window fan (Relay_2) on-off temperature
  if (dht.readTemperature() >= 25)
  {
    digitalWrite(Relay_2, RELAY_OFF);
  }
  else if (dht.readTemperature() < 23)
  {
    digitalWrite(Relay_2, RELAY_ON);
  }


Where are the serial print statements to show whether the relay is to be turned on or off? What actually happens?

I know that it is frustrating when code doesn't work as you want, but, you need to remember that we can't see what you are seeing. If you don't show serial output, we can't see it. If you don't say what the relays are actually doing, we don't know.

Anyway, I wish you luck in solving your problem.

34DOL

Maybe that is what is missing, the serial print statements.  Maybe serial print statements should replace dht.readTemperature().

I don't know what the relays are doing with that code.  As I said, they don't seem to be doing anything.

34DOL

Attached is my revised code using PaulS's suggestions.  I haven't been able to test it, because the USB chip on my Arduino burned up, but I've ordered a replacement.

Docedison

#20
Dec 08, 2012, 12:53 pm Last Edit: Dec 08, 2012, 12:57 pm by Docedison Reason: 1
Why write the data unless it has changed? is what I think the center of the issue here.
What the total center that is being asked is why do anything that doesn't need to be done. millisec() is great for that I've heard/.

Bob
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

34DOL

I'm not sure what millisec() does.  I've never heard of it and can't find any documentation on it.

I have however removed my delays and inserted millis()s.  I've never used this function before and am not sure if I did it correct.  Attached is my code.

Docedison

There is a page here you might find useful  http://arduino.cc/en/Reference/HomePage
and Specifically:http://arduino.cc/en/Reference/Millis
For further reading try the Blink without delay Sketch. I've taken the liberty of posting it here for your perusal...
Please read the comments...
Code: [Select]

// constants won't change. Used here to
// set pin numbers:
const int ledPin =  13;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;           // interval at which to blink (milliseconds)

void setup()
{
  pinMode(ledPin, OUTPUT);     // set the digital pin as output: 
}
void loop()
{
  // here is where you'd put code that needs to be running all the time.
  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval)
  {
    // save the last time you blinked the LED
    previousMillis = currentMillis;     
    if (ledState == LOW)   // if the LED is off turn it on and vice-versa:
      ledState = HIGH;
    else
      ledState = LOW; // set the LED with the ledState of the variable:   
    digitalWrite(ledPin, ledState);
  }
}



Bob
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

34DOL

Thanks Bob.

I had used a different tutorial to create my code around the millis() function.  The reference you provided makes more sense though...

scottyjr

Quote
This issue seem to be above your level of competency.
R i i i i i i g h t! - Scotty

liudr

Op, have you ever tested the code you wrote or borrowed with simple LEDs instead of going straight for the relay board? If the LEDs don't behave what the relays should, you have a software problem. If they do behave the way you intended your relays do, you have hardware problem.

Go Up