Created
February 15, 2019 13:22
-
-
Save tashima42/4a5f8b68ab4517c3b25e428f43510c76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <DS3231.h> | |
int Relay = 4; | |
DS3231 rtc(SDA, SCL); | |
Time t; | |
const int OnHour = 12; | |
const int OnMin = 24; | |
const int OffHour = 12; | |
const int OffMin = 25; | |
void setup() { | |
Serial.begin(115200); | |
rtc.begin(); | |
pinMode(Relay, OUTPUT); | |
digitalWrite(Relay, LOW); | |
} | |
void loop() { | |
t = rtc.getTime(); | |
Serial.print(t.hour); | |
Serial.print(" hour(s), "); | |
Serial.print(t.min); | |
Serial.print(" minute(s)"); | |
Serial.println(" "); | |
delay (1000); | |
if(t.hour == OnHour && t.min == OnMin){ | |
digitalWrite(Relay,HIGH); | |
Serial.println("LIGHT ON"); | |
} | |
else if(t.hour == OffHour && t.min == OffMin){ | |
digitalWrite(Relay,LOW); | |
Serial.println("LIGHT OFF"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int pinoChuvaDigital = 2; //pino digital do sensor de chuva | |
const int pinoChuvaAnalog = A7; // pino analogico do sensor de chuva | |
int valorDigital = 0; // armazena os valores dos pinos digitais e analogicos | |
int valorAnalog = 0; | |
void setup() { | |
pinMode (pinoChuvaDigital, INPUT); | |
pinMode (pinoChuvaAnalog, INPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
valorDigital = digitalRead(pinoChuvaDigital); | |
valorAnalog = analogRead(pinoChuvaAnalog); | |
Serial.print("Valor Digital: "); | |
Serial.print(valorDigital); | |
Serial.print("Valor Analogico: "); | |
Serial.println(valorAnalog); | |
delay (1000); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DHT.h" //biblioteca para o leitor de umidade e temperatura DHT11 | |
//bibliotecas para o SD | |
#include <SPI.h> | |
#include <SD.h> | |
#define pinoDht 9 // PINO digital em que o DT11 esta conectado | |
#define tipoDht DHT11 // DHT 11 | |
const int chipSelect = 10; | |
const int pinoChuva = A7;//Pino de entrada analogico do sensor de chuva | |
int valorChuva = 0; //armazena o valor analogico do sensor de chuva | |
DHT dht(pinoDht, tipoDht); //define valores para o sensor DHT11 | |
void setup() { | |
Serial.begin(9600); | |
Serial.print("Iniciando DHT11 "); | |
dht.begin(); //inicia a biblioteca do DHT | |
pinMode(pinoChuva, INPUT);//definindo o pino do sensor de chuva como entrada | |
Serial.print("Initializing SD card..."); | |
// see if the card is present and can be initialized: | |
if (!SD.begin(chipSelect)) { | |
Serial.println("Card failed, or not present"); | |
// don't do anything more: | |
return; | |
} | |
Serial.println("card initialized."); | |
} | |
void loop() { | |
//DHT11 | |
int h = dht.readHumidity(); // le a umidade do ar | |
int t = dht.readTemperature(); //le a temperatura em celcius | |
//SENSOR DE CHUVA | |
valorChuva = analogRead(pinoChuva); | |
// open the file. note that only one file can be open at a time, | |
// so you have to close this one before opening another. | |
File dataFile = SD.open("datalog.csv", FILE_WRITE); | |
// if the file is available, write to it: | |
if (dataFile) { | |
dataFile.print(h); | |
dataFile.print(" , "); | |
dataFile.print(t); | |
dataFile.print(" , "); | |
dataFile.print(valorChuva); | |
dataFile.println(" , "); | |
dataFile.close(); | |
//PARTE DE IMPRESSAO PARA O MONITOR SERIAL | |
//DHT11 | |
//printa a umidade | |
Serial.print ("Umidade: "); | |
Serial.print (h); | |
Serial.print(" %\t"); | |
Serial.print(" , "); | |
//printa a temperatura | |
Serial.print("Temperatura: "); | |
Serial.print(t); | |
Serial.print(" *C"); | |
Serial.print(" , "); | |
//SENSOR DE CHUVA | |
Serial.print("Quantidade de Chuva: "); | |
Serial.print(valorChuva); | |
Serial.println(" , "); | |
} | |
// if the file isn't open, pop up an error: | |
else { | |
Serial.println("error opening datalog.csv"); | |
} | |
delay (1000); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int rele = 4; // pino de comando do modulo rele | |
void setup() { | |
Serial.begin(9600); | |
// define o pino relativo ao rele de saida | |
pinMode(rele, OUTPUT); | |
} | |
void loop() { | |
digitalWrite(rele, LOW); //Desliga o Rele | |
delay (1000); | |
digitalWrite(rele, HIGH); //Liga o Rele | |
delay (500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment