viewtopic.php?t=195223&start=30
I deleted a couple lines of the rtc code and got it to keep time correctly, but I still can't get the mini relay to work.
Here's the latest version. I'm certain the relay is wired correctly because I tried a simplified sketch with pinMode(12, OUTPUT); and got it to work...
Code: Select all
#include <RTClib.h>
#include <Wire.h>
#include "Adafruit_HTU21DF.h"
RTC_DS1307 rtc;
int hours = 0;
int minutes = 0;
int seconds = 0;
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 8
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(9600);
pinMode(12, OUTPUT);
if (!htu.begin()) {
Serial.println("Couldn't find sensor!");
while (1);
}
tft.init(135, 240);
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_CYAN); // set text color to green and black background
tft.setTextSize(2);
tft.setRotation(3);
/* rtc.begin(); */
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
}
}
void loop() {
tft.fillScreen(ST77XX_BLACK);
float temp = htu.readTemperature();
float rel_hum = htu.readHumidity();
tft.setCursor(15, 15);
tft.print("Temp: ");
tft.print(temp);
tft.print(" C");
tft.setCursor(15, 45);
tft.print("RH: ");
tft.print(rel_hum);
tft.print(" %");
{
DateTime now = rtc.now();
tft.setCursor(15, 75);
tft.print("Time: ");
tft.print(now.hour(), DEC);
tft.print(':');
tft.print(now.minute(), DEC);
tft.print(':');
tft.print(now.second(), DEC);
}
if (rel_hum >=80) {
digitalWrite(12, HIGH);
tft.setCursor(15, 105);
tft.print("Vent:");
tft.setTextColor(ST77XX_RED);
tft.setCursor(87, 105);
tft.print("ON");
}
else if (rel_hum <=60) {
digitalWrite(12, LOW);
tft.setCursor(15, 105);
tft.print("Vent:");
tft.setCursor(87, 105);
tft.setTextColor(ST77XX_YELLOW);
tft.print("OFF");
}
tft.setTextColor(ST77XX_CYAN); delay(5000);
}