25-01-2017, 21:10
Witam zaprogramowałem sterownik do akwarium.
Układ prosty.
1. arduino uno
2. moduł 2 przekazników
3. czujnik temperatury onewire
4. DS1302
Sterowanie grzałką zależne od temeratury
A także mój problem sterowanie czasowe swiatłem.
Chciałbym aby załączało się o godzinie 16 i wyłączało o 22, lecz nigdzie nie mogę znależć odpowiedniego algorytmu.
Gdyby ktos wiedział jak to zrobić lub miał jakiś pomysł to bedę wdzięczny za każdą pomoc .
myslałem o if time <16, 0, 0
ale to neidziała.
Załączam kod programu może komuś się przyda
Układ prosty.
1. arduino uno
2. moduł 2 przekazników
3. czujnik temperatury onewire
4. DS1302
Sterowanie grzałką zależne od temeratury
A także mój problem sterowanie czasowe swiatłem.
Chciałbym aby załączało się o godzinie 16 i wyłączało o 22, lecz nigdzie nie mogę znależć odpowiedniego algorytmu.
Gdyby ktos wiedział jak to zrobić lub miał jakiś pomysł to bedę wdzięczny za każdą pomoc .
myslałem o if time <16, 0, 0
ale to neidziała.
Załączam kod programu może komuś się przyda
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(18, 23, 0); // Set the time to 12:00:00 (24hr format)
rtc.setDate(22, 01, 2017); // 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 <= 22.00)
{
digitalWrite(grzalka,LOW);
Serial.print("grzalka zalaczona");
lcd.setCursor(14,0);
lcd.print("ON");
}
delay (100);
if (tempC >= 24.00)
{
digitalWrite(grzalka,HIGH);
Serial.print("grzalka wylaczona");
lcd.setCursor(13,0);
lcd.print("OFF");
}
delay (100);
}