Hardware components | ||||||
![]() |
| × | 4 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 |
I need to control the humidity and temperature of some carnivorous plants in the greenhouse, this requires constant temperatures and humidity all year round, plus I have inserted a clock that has proved very useful when I spend a lot of time in the greenhouse.
I ordered the RTC form and I'm waiting for it to arrive.
As soon as it is available I will modify and update the program to add the more precise RTC.
CLOCK-DH22.ino
ArduinoI need to control the humidity and temperature of some carnivorous plants in the greenhouse, this requires constant temperatures and humidity all year round, plus I have inserted a clock that has proved very useful when I spend a lot of time in the greenhouse.
/*Thanks to: Electronics-project-hub.com.
implemented and modified by Franchini Marco.
frank8952@gmail.com*/
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <SevSeg.h>
DHT dht(A2,DHT22);
SevSeg Display;
char text[10][6];
int i = 0;
unsigned long timer;
//----------------------SET OROLOGIO
const unsigned long period = 1000; //durata 1 sec.
const unsigned long led_period = 500; //durata lampeggio :
unsigned long startMillis;
unsigned long led_startMillis;
unsigned long currentMillis;
unsigned long led_currentMillis;
const int hrs_btn = A0; //set ore
const int min_btn = A1; //set minuti
const int ledPin = 13; //pin lampeggio :
int Hrs = 0;
int Min = 0;
int Sec = 0;
int Time = 0000;
int ledState = HIGH;
void setup() {
pinMode(hrs_btn, INPUT_PULLUP);
pinMode(min_btn, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
byte numDigits = 4;
byte digitPins[] = {12, 10, 9, 11};
//byte digitPins[] = {11, 9, 10, 12};
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8,0};
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_CATHODE; // See README.md for options
bool updateWithDelays = false; // Default 'false' is Recommended
bool leadingZeros = true; // Use 'true' if you'd like to keep the leading zeros
bool disableDecPoint = true; // Use 'true' if your decimal point doesn't exist or isn't connected
Display.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
updateWithDelays, leadingZeros, disableDecPoint);
Display.setBrightness(100);
dht.begin();
pinMode(ledPin, OUTPUT); // PIN 13 lampeggio :
pinMode(A2, INPUT); // input DHT22
}
void loop()
{
char mychar[ ] = "ORA";
float hu = dht.readHumidity();
float t = dht.readTemperature();
float orario = Time;
String e = String (mychar); //memorizza mychar
String f = e.substring (0,4); //memorizza cifra a 4 digit
f.toCharArray(text[1],5); //visualizza come 1 (ARRAY)
orario=orario*10;
String c = String (orario); //memorizza ora
String d = c.substring (0,4); //memorizza cifra a 4 digit
d.toCharArray(text[2],5); //visualizza come 2 (ARRAY)
t=t*10;
String k = String(t); //memorizza t
String r = k.substring (0,3)+"*"; //memorizza cifra a 3 digit + C
r.toCharArray(text[3],5); //visualizza come 3 (ARRAY)
hu=hu*10;
String A = String(hu); //memorizza hu
String B = A.substring(0,3)+"h"; //memorizza cifra a 3 digit
B.toCharArray(text[4],5); // visualizza come 4 (ARRAY)
switch (i)
{
case 1:
digitalWrite(ledPin, LOW); //pin 13 on Humid
break;
case 2:
digitalWrite(ledPin, HIGH); //pin 13 off ORA
break;
case 3:
digitalWrite(ledPin, LOW); //orario
Display.setNumber(Time);
if (digitalRead(hrs_btn) == LOW){goto X;}
if (digitalRead(min_btn) == LOW){goto X;}
break;
case 4:
digitalWrite(ledPin, LOW); //gradi
break;
}
if (millis() > (timer + 6000)) //tempo di visualizzazione
{
switch(i);
Display.setChars(text[i]);
i++;
if (i >= 5) i = 1; // (ARRAY)conta fino a 5 poi torna a 1
timer = millis();}
//--------------------------------OROLOGIO
X: currentMillis = millis();
if (currentMillis - startMillis >= period)
{
Sec = Sec + 1;
startMillis = currentMillis;
}
led_currentMillis = millis();
if (led_currentMillis - led_startMillis >= led_period)
{ led_startMillis = led_currentMillis;
if (ledState == LOW) { ledState = HIGH;
if (digitalRead(hrs_btn) == LOW) //avanzamento ore
{ Hrs = Hrs + 1; }
if (digitalRead(min_btn) == LOW) //avanzamento min
{ Min = Min + 1; Sec = 0; }
}
else
{ ledState = LOW; }
digitalWrite(ledPin, ledState);
}
if (Sec == 60)
{
Sec = 0;
Min = Min + 1;
}
if (Min == 60)
{
Min = 0;
Hrs = Hrs + 1;
}
if (Hrs == 24) //12/24 ore
{
Hrs = 0;
}
Time = Hrs * 100 + Min;
Display.refreshDisplay();
}
/*Thanks to: Electronics-project-hub.com.
implemented and modified by Franchini Marco.
frank8952@gmail.com*/
Comments
Please log in or sign up to comment.