Arduino Fan Controller (DS18B20 & Relay)

Discussion in 'The Projects Forum' started by james211, Mar 2, 2014.

  1. james211

    Thread Starter Member

    May 29, 2012
    210
    2
    So I've been working on this all night and I think part of my problem is coming from lack of documentation on part of the relay I'm using. I have had no problem getting a tempF readout from the temp probe, but for the life of me, even with basic arduino tutorials from many places, I cannot get he relay to trigger.

    Here is the relay I'm using:
    http://www.robotgeek.com/robotgeek-relay

    There is no documentation, and video on the site doesn't work.

    The relay has a Vcc, Ground, and Signal.

    What I'm looking to do is have a fan that kicks on at 81 degrees and turns off at 77 degrees. This is the code I was using, but again, I can't even test the code cause I can't get the relay to trigger. I have two of them, just in case.

    I am by no means 100% about this code either..any help is appreciated. This forum has never let me down. Thank you as always!

    Code ( (Unknown Language)):
    1. #include <OneWire.h>
    2.  
    3. int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
    4. int relay =7;
    5.  
    6. //Temperature chip i/o
    7. OneWire ds(DS18S20_Pin);  // on digital pin 2
    8.  
    9. void setup(void) {
    10.   Serial.begin(9600);
    11. }
    12.  
    13. void loop(void) {
    14.   float temperature = getTemp();
    15.   float tempF = (temperature * 9.0)/ 5.0 + 32.0;
    16.   Serial.println(tempF);
    17.   if (tempF >60) {
    18.         digitalWrite(7,HIGH);
    19.     } else {
    20.         digitalWrite(7,LOW);
    21.     }
    22.  
    23.   delay(100); //just here to slow down the output so it is easier to read
    24.  
    25. }
    26.  
    27.  
    28. float getTemp(){
    29.   //returns the temperature from one DS18S20 in DEG Celsius
    30.  
    31.   byte data[12];
    32.   byte addr[8];
    33.  
    34.   if ( !ds.search(addr)) {
    35.       //no more sensors on chain, reset search
    36.       ds.reset_search();
    37.       return -1000;
    38.   }
    39.  
    40.   if ( OneWire::crc8( addr, 7) != addr[7]) {
    41.       Serial.println("CRC is not valid!");
    42.       return -1000;
    43.   }
    44.  
    45.   if ( addr[0] != 0x10 && addr[0] != 0x28) {
    46.       Serial.print("Device is not recognized");
    47.       return -1000;
    48.   }
    49.  
    50.   ds.reset();
    51.   ds.select(addr);
    52.   ds.write(0x44,1); // start conversion, with parasite power on at the end
    53.  
    54.   byte present = ds.reset();
    55.   ds.select(addr);    
    56.   ds.write(0xBE); // Read Scratchpad
    57.  
    58.  
    59.   for (int i = 0; i < 9; i++) { // we need 9 bytes
    60.     data[i] = ds.read();
    61.   }
    62.  
    63.   ds.reset_search();
    64.  
    65.   byte MSB = data[1];
    66.   byte LSB = data[0];
    67.  
    68.   float tempRead = ((MSB << 8) | LSB); //using two's compliment
    69.   float TemperatureSum = tempRead / 16;
    70.  
    71.   return TemperatureSum;
    72.  
    73. }[/i]
     
  2. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    You can test the software easily by connecting a LED and series resistor to the output pin (that you will later use for the fan relay).

    Then you can confirm the LED is turning ON and OFF as the sensor reaches the correct temperatures.

    Once you have that working, it should be a simple matter to connect a relay instead of your test LED. If you need help with a relay drive circuit that can be done with one transistor, a resistor and a diode. We can offer suggestions with that once your software is all working. :)
     
  3. james211

    Thread Starter Member

    May 29, 2012
    210
    2
    Cool! With my current code, and the LED, that works perfectly. Now I just need to know how to connect the relay.
     
  4. james211

    Thread Starter Member

    May 29, 2012
    210
    2
    I did find this schematic - http://playground.arduino.cc/uploads/Learning/relays.pdf
    I have all the parts, but what I don't see on here is a signal connection. Also, I was able to use the basic blink sketch to get the relay to trigger. I connected Vcc to 5V, Ground to Ground and Signal to pin 13.

    So help me to understand where I connect the signal to? From what I gather, that is the trigger for this relay.
     
  5. james211

    Thread Starter Member

    May 29, 2012
    210
    2
    ok..figuring out more as I go here. The relay board I have contains the transistor, resistor and diode. I'm must baffled why it won't trigger....the LED test works fine.
     
  6. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    4,771
    971
    5V pin on arduino goes to Vcc
    gnd to gnd
    pin 7 to signal
     
  7. james211

    Thread Starter Member

    May 29, 2012
    210
    2
    Thats what I thought. I figured it out now, I was missing a piece of code in my sketch. Seems to be working fine now.
     
  8. james211

    Thread Starter Member

    May 29, 2012
    210
    2
    If I wanted to run two 12V fans, and an Arduino nano with one power supply, a 2amp power supply should suffice correct? The fans need .6watts each, and from what I gather the arduino nano only needs about 40mA per pin with a maximum of 200mA.
     
    Last edited: Mar 3, 2014
  9. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    The power supply needs to provide enough current for both fans, both relays, and the arduino.

    I think the 2A PSU should be fine, but it is always a good idea to calculate or measure the current consumption of all your devices, and allow some extra overhead in the PSU.

    So if everything draws 1A total, your 2A PSU is fine.

    If everything draws 1.9A total, then a >2A PSU would be a good idea.
     
Loading...