Pages: 1 [2]   Go Down
Author Topic: Chicken Coop - LCD + 2 Fans + 2 Lights + RTC + DHT11 + Stepper  (Read 2954 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 642
Posts: 50366
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 642
Posts: 50366
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
  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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

* Test.ino (10.7 KB - downloaded 10 times.)
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2927
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: December 08, 2012, 06:57:23 am by Docedison » Logged

--> 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

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

* Test.ino (11.02 KB - downloaded 8 times.)
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2927
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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
Logged

--> 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

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Bob.

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

* Test.ino (11.39 KB - downloaded 14 times.)
Logged

Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 323
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Central MN, USA
Online Online
Tesla Member
***
Karma: 75
Posts: 7265
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Pages: 1 [2]   Go Up
Jump to: