Go Down

Topic: Need help adding a fan via relay (Read 100 times) previous topic - next topic

spides

Hi guys. Im using a Mega board, an LCD 16x2 Shield and a ds3231RTC. I've got the code working so that it displays time, date and temp. What I want to do now is connect a relay to switch on a single PC fan when it reaches a certain temp.
 Just checking is SDA is the data pin to get temps from

And what else is wrong with this code

Code: [Select]

// Attempting to control a fan off temperature
   
    #include <LiquidCrystal.h>
    #include <Wire.h>
    #include <ds3231.h>
    int reading = 0;
    int sensorPin =SDA; // Temperature data pin
    int relay =32; // Relay pin
    int temp = 26
    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
   
   float high_temp = 28.00;
   float norm_temp = 24.00;
   
    void setup() {
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    pinMode(relay,OUTPUT);

    }
 
   
    void loop() {
    reading = digitalRead(sensorPin);
    int celsius = reading/2;
    lcd.setCursor(0, 0);
    lcd.print("Temperature: "); 
    lcd.setCursor(0,1);
    lcd.print(celsius, DEC);
    lcd.print((char)223);
    lcd.print("C");
    if (celsius >28) {
    digitalWrite(32,HIGH);
    } else {
    digitalWrite(32,LOW);
    }
    delay(500);
    lcd.clear();
   
    if(temp>28)
{
digitalWrite(relay_1, HIGH);
}
  if(temp<27)
{
digitalWrite(relay_1, LOW);
}
    }
 


Thanks
Chris




gilshultz

Use the same source you use to display temperature. SDA is a bad name to use, it indicates a I2C hardware connection.  This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil
This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

spides

Thanks Gil. My issue is the ds3231 is SDA, SCL, VCC & GND, so Im not sure what to use

Go Up