• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Akwarium włącznik czasowy pomocy
#1
Witam.
Postanowiłem wykorzystać arduino uno w akawarium.
Napisałem program z obsługą :
1. czujnika temperatury i grzałki
2. wyswietlacza LCD po i2c.
3. zegara ds1302 do wyświetlania godziny.
Mój problem dotyczy włącznika czasowego.
Chciałbym aby światło włączało sie np o 16:00 a gasiło o 22:00
ale nie potrafię tego zrobić.
W jaki sposub to można zapisać za pomocą kodu .
Pozdrawiam
Kod:
#include <Time.h>
#include <DS1302.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>  
#include <LiquidCrystal_I2C.h>

// Init the DS1302
DS1302 rtc(A0, A1, A2);

// Data wire is plugged into pin 7 on the Arduino
#define ONE_WIRE_BUS A3

// Setup a oneWire instance to communicate with ANY OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Set oneWire reference to Dallas Temperature sensor.
DallasTemperature sensors(&oneWire);

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

int grzalka = 7;
int oswietlenie = 6;
int buton_1= 5;
int buttonState = 0;
void setup(void)
{
Serial.begin(9600);
sensors.begin();
pinMode(grzalka, OUTPUT);
pinMode (oswietlenie, OUTPUT);
pinMode (buton_1, INPUT_PULLUP);

lcd.begin(16,2);   // Inicjalizacja LCD 2x16
  
  lcd.setCursor(0,0); // Ustawienie kursora w pozycji 0,0

  // Set the clock to run-mode, and disable the write protection
  rtc.halt(false);
  rtc.writeProtect(false);

  // Setup Serial connection
  Serial.begin(9600);

  // The following lines can be commented out to use the values already stored in the DS1302
  rtc.setDOW(WEDNESDAY);        // Set Day-of-Week to FRIDAY
  rtc.setTime(19, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(12, 21, 2016);   // Set the date to August 6th, 2010

}
void loop(void)
{
sensors.requestTemperatures();
Serial.println("");
Serial.print("Sensor 1: ");
Serial.println(sensors.getTempCByIndex(0));
  lcd.setCursor(1,0);
lcd.print("Temp: ");
lcd.print(sensors.getTempCByIndex(0));

// time
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");

  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  lcd.setCursor(0,2);
  lcd.print("Time: ");
  lcd.print(rtc.getTimeStr());
  

  // Wait one second before repeating :)
  delay (1000);

  buttonState = digitalRead(buton_1);
    if (buttonState == LOW) {
    digitalWrite(oswietlenie,LOW);
    lcd.backlight();

  } else {
digitalWrite(oswietlenie,HIGH);
lcd.noBacklight();

  }

  
   float tempC = (sensors.getTempCByIndex(0));
if (tempC <= 23.00)
      {
    digitalWrite(grzalka,LOW);
    Serial.print("grzalka zalaczona");
    lcd.setCursor(14,0);
    lcd.print("ON");

    }
    delay (100);

if (tempC >= 26.00)
      {
    digitalWrite(grzalka,HIGH);
    Serial.print("grzalka wylaczona");
    lcd.setCursor(13,0);
    lcd.print("OFF");
    }
    delay (100);

    
}
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości