Introduction: Arduino Thermostat With 2x DS18b20 I2c 4x16 Display, 2 RGB LED's and 3 Relay's

Picture of Arduino Thermostat With 2x DS18b20 I2c 4x16 Display, 2 RGB LED's and 3 Relay's

The Goal of the Project is a Thermostat for my 2 Fish Tank's with LCD Display RGB LED an Relay to control the Heater in the Tank
an a Cooling Fan for the Big Fishtank

Parts:
Arduino Nano or equal
2x RGB LED's or RGB SMD LED or Single Color LED's
1x 2 Channel 5v Relay Modul -> for the Heater's
1x 1 Channel 5v Relay -> for Cooling Fan 
2x DS18B20 1 Wire Sensor
1x 4k7 Ohm Resistor for the 1 Wire Bus
6x 220Ohm Resistor for the LED's
1x 20x4 Display with i2c Interface
Breadboard


Step 1: Schematic Without Relay's and Display

Picture of Schematic Without Relay's and Display

This is the Schematic without Display an Relay's

Step 2: Display 20x4 I2c

Picture of Display 20x4 I2c

my Display is equal to this
http://www.sainsmart.com/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html

SDA -> Arduino A4
SDL -> Arduino A5
GND -> GND
VCC -> 5V

Step 3: Relay

Picture of Relay

2 Relay Modules are connected

1x Dual Channel Modul equal to this for the Heater
1x Single Channel Modul from HonKong for the Fan in the Big Tank

Rel1 -> Arduino D2
Rel2 -> Arduino D3
Rel3 -> Arduino D8
GND -> Arduino GND
VCC -> Arduino 5V

Step 4: The Code

#include <OneWire.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>

//RGBLED
int bluePin1 = 10;                        //Digital Pin für Blaue LED1 in RGB-LED 
int greenPin1 = 11;                       //Digital Pin für Grüne LED1 in RGB-LED 
int redPin1 = 12;                         //Digital Pin für Rote LED1 in RGB-LED 

int redIn1 = 0;
int greenIn1 = 1;
int blueIn1 = 2;

int redVal1;
int greenVal1;
int blueVal1;

int bluePin2 = 4;                        //Digital Pin für Blaue LED2 in RGB-LED 
int greenPin2 = 5;                       //Digital Pin für Grüne LED2 in RGB-LED 
int redPin2 = 6;                         //Digital Pin für Rote LED2 in RGB-LED 

int redIn2 = 3;
int greenIn2 = 4;
int blueIn2 = 5;

int redVal2;
int greenVal2;
int blueVal2;

//Relays
int relPin1 = 2;                        //Digital Pin für Relay1
int relPin2 = 3;                        //Digital Pin für Relay2
int relPin3 = 8;                        //Digital Pin für Relay3

int relPin1In = 3;
int relPin2In = 4;
int relPin3In = 5;

int relPin1Val;
int relPin2Val;
int relPin3Val;

//Heizungs Status
int heiz1Val;
int heiz2Val;
#define BACKLIGHT_PIN 13
#define ONE_WIRE_BUS 7
LiquidCrystal_I2C lcd(0x20,20,4);  // set the LCD address to 0x20 for a 20 chars and 4 line display
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(9600);
  sensors.begin();
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  pinMode(relPin1, OUTPUT);      //Output Mode for Relay1
  pinMode(relPin2, OUTPUT);      //Output Mode for Relay2
  pinMode(relPin3, OUTPUT);      //Output Mode for Relay3
  }

void loop() {
  sensors.requestTemperatures();
  float temperature1 = sensors.getTempCByIndex(0);
  lcd.setCursor(0, 0);
  lcd.print("Aquarium: ");
  lcd.print(sensors.getTempCByIndex(0));
  lcd.print("C");
 
  float temperature2 = sensors.getTempCByIndex(1);
  lcd.setCursor(0, 2);
  lcd.print("Becken:   ");
  lcd.print(sensors.getTempCByIndex(1));
  lcd.print("C");
   
//Je nach Temperatur Farbe der RGB-LED anpassen und Rel 1 schalten
    if(temperature1 <= 27)
    {
      redVal1 = 0;
      greenVal1 = 0;
      blueVal1 = 150;
      relPin1Val = LOW;
      relPin3Val = LOW;
      lcd.setCursor(0, 1);
      lcd.print("Heizung ist: Ein  ");
     }
    else if(temperature1 > 27 && temperature1 < 29)
    {
      redVal1 = 0;
      greenVal1 = 150;
      blueVal1 = 0;
      relPin1Val = HIGH;
      relPin3Val = LOW;
      lcd.setCursor(0, 1);
      lcd.print("Heizung ist: Aus  ");
      }
    else if(temperature1 > 29)
    {
      redVal1 = 150;
      greenVal1 = 0;
      blueVal1 = 0;
      relPin1Val = HIGH;
      relPin3Val = HIGH;
      lcd.setCursor(0, 1);
      lcd.print("Lueftung ist: Ein  ");
      } 

//Je nach Temperatur Farbe der RGB-LED anpassen und Rel 2 schalten
    if(temperature2 <= 27)
    {
      redVal2 = 0;
      greenVal2 = 0;
      blueVal2 = 255;
      relPin2Val = LOW;
      lcd.setCursor(0, 3);
      lcd.print("Heizung ist: Ein  ");    
    }
    else if(temperature2 > 27 && temperature2 < 29)
    {
      redVal2 = 0;
      greenVal2 = 255;
      blueVal2 = 0;
      relPin2Val = HIGH;
      lcd.setCursor(0, 3);
      lcd.print("Heizung ist: Aus  ");   
    }
    else if(temperature2 > 29)
    {
      redVal2 = 255;
      greenVal2 = 0;
      blueVal2 = 0;
      relPin2Val = HIGH;
      lcd.setCursor(0, 3);
      lcd.print("Lueftung ist: Ein ");
     } 
{
  analogWrite(redPin1, redVal1);
  analogWrite(greenPin1, greenVal1);
  analogWrite(bluePin1, blueVal1);
  analogWrite(redPin2, redVal2);
  analogWrite(greenPin2, greenVal2);
  analogWrite(bluePin2, blueVal2);
  digitalWrite(relPin1, relPin1Val);
  digitalWrite(relPin2, relPin2Val);
  digitalWrite(relPin3, relPin3Val);
}
}

Comments

SzabolcsM1 (author)2015-11-28

I have a problem:



akvarium:59: error: 'class LiquidCrystal_I2C' has no member named 'init'

exit status 1
'class LiquidCrystal_I2C' has no member named 'init'

How can i fix this?

gryzli133 (author)SzabolcsM12017-01-28

Here is more about:

https://arduino-info.wikispaces.com/LCD-Blue-I2C

by myself the problem was:

- wrong i2c address

- I have change two lines of code to:

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
lcd.begin(20,4); // initialize the lcd
rexty37 (author)2016-03-19

Bonjour

Ce programme ne fonctionne pas

erreur à la ligne 56

steventerrell (author)2015-11-11

Hello Sir,

I'd like to convert C to F. Can you assist me with this?

Thank you so much.

TkonekT (author)2015-07-06

It's a 4x20 LCD Display ! :)

rexa6969 (author)2014-11-11

and how about the diagram with lcd and relay looks like, please?

About This Instructable

45,450views

49favorites

License:

Add instructable to: