Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <SerialRelay.h>
- #include <Ethernet_v2.h>
- #include <DS1307.h>
- #include <String.h>
- #include <DHT.h>
- byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x70, 0xbC };
- IPAddress ip( 192, 168, 1, 12 );
- EthernetServer server(80);
- SerialRelay relays(8,9,2); // (data, clock, number of modules)
- DS1307 rtc(A4, A5);
- #define DHTPIN A1 // pino que estamos conectado
- #define DHTTYPE DHT11 // DHT 11
- DHT dht(DHTPIN, DHTTYPE);
- String readString = String(300);
- String statusSala;
- String statusRecepcao;
- String statusArquivo;
- boolean RelaySala = false; // varivel para guardar o estado do rele
- boolean RelayRecepcao = false;
- boolean RelayArquivo = false;
- String Display;
- String Temp;
- float h;
- float Xpto;
- Display += Xpto;
- void setup() {
- Ethernet.begin(mac, ip);
- rtc.halt(false);
- //As linhas abaixo setam a data e hora do modulo
- //e podem ser comentada apos a primeira utilizacao
- //rtc.setDOW(SATURDAY); //Define o dia da semana
- //rtc.setTime(20, 25, 10 ); //Define o horario
- //rtc.setDate(26, 03, 2016); //Define o dia, mes e ano
- //Definicoes do pino SQW/Out
- rtc.setSQWRate(SQW_RATE_1);
- rtc.enableSQW(true);
- }
- void loop()
- {
- h = dht.readHumidity();
- Xpto= dht.readTemperature();
- Display = "C:"; // C: no texto
- Display += Xpto; // valor da temperatura no texto
- Display += " H:"; // H: no texto
- Display += h; // valor da umidade no texto
- String str=rtc.getTimeStr();
- String str2="17:30:00";
- if (str==str2){
- relays.SetRelay(1, SERIAL_RELAY_OFF, 1);
- relays.SetRelay(2, SERIAL_RELAY_OFF, 1);
- relays.SetRelay(3, SERIAL_RELAY_OFF, 1);
- relays.SetRelay(4, SERIAL_RELAY_OFF, 1);
- relays.SetRelay(1, SERIAL_RELAY_OFF, 2);
- relays.SetRelay(2, SERIAL_RELAY_OFF, 2);
- RelaySala = false;
- RelayRecepcao = false;
- RelayArquivo = false;
- statusSala="Desligado";
- statusRecepcao="Desligado";
- statusArquivo="Desligado";
- }
- EthernetClient client = server.available();
- if(client)
- {
- while(client.connected())
- {
- if(client.available());
- {
- char c = client.read();
- if(readString.length() < 300)
- {
- readString += (c);
- }
- if(c == '\n')
- {
- if(readString.indexOf("Sala") >=0) {
- if(RelaySala) { // se o rele estiver ativado (true)
- relays.SetRelay(1, SERIAL_RELAY_OFF, 1); // desliga o rele
- delay(1000);
- relays.SetRelay(2, SERIAL_RELAY_OFF, 1);
- RelaySala = false; // define como false para sinalizar que esta desligado
- } else {
- relays.SetRelay(1, SERIAL_RELAY_ON, 1); // senao liga o rele
- delay(1000);
- relays.SetRelay(2, SERIAL_RELAY_ON, 1);
- RelaySala = true; // define como true para sinalizar que ele esta ligado
- }}else if(readString.indexOf("Recepcao") >=0) {
- if(RelayRecepcao) { // se o rele estiver ativado (true)
- relays.SetRelay(3, SERIAL_RELAY_OFF, 1); // desliga o rele
- delay(1000);
- relays.SetRelay(4, SERIAL_RELAY_OFF, 1);
- RelayRecepcao = false; // define como false para sinalizar que esta desligado
- } else {
- relays.SetRelay(3, SERIAL_RELAY_ON, 1); // senao liga o rele
- delay(1000);
- relays.SetRelay(4, SERIAL_RELAY_ON, 1);
- RelayRecepcao = true; // define como true para sinalizar que ele esta ligado
- }}else if(readString.indexOf("Arquivo") >=0) {
- if(RelayArquivo) { // se o rele estiver ativado (true)
- relays.SetRelay(1, SERIAL_RELAY_OFF, 2); // desliga o rele
- delay(1000);
- relays.SetRelay(2, SERIAL_RELAY_OFF, 2);
- RelayArquivo = false; // define como false para sinalizar que esta desligado
- } else {
- relays.SetRelay(1, SERIAL_RELAY_ON, 2); // senao liga o rele
- delay(1000);
- relays.SetRelay(2, SERIAL_RELAY_ON, 2);
- RelayArquivo = true; // define como true para sinalizar que ele esta ligado
- }
- }
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("Connnection: close");
- client.println();
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- client.println("<head>");
- client.println("<title>Automacao Residencial V 1.0 By EduTel</title>");
- client.println("<meta name=\"viewport\" content=\"width=320\">");
- client.println("<meta name=\"viewport\" content=\"width=device-width\">");
- client.println("<meta charset=\"utf-8\">");
- client.println("<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\">");
- client.println("<meta http-equiv=\"refresh\" content=\"1; URL=http://192.168.1.12\">");
- client.println("</head>");
- client.println("<body>");
- client.println("<center>");
- client.println("<font size=\"5\" face=\"verdana\" color=\"Orange\">EduTel</font>");
- client.println("<font size=\"3\" face=\"verdana\" color=\"red\"> & </font>");
- client.println("<font size=\"5\" face=\"verdana\" color=\"Orange\">EduCel</font><br />");
- client.println("<font size=\"5\" face=\"verdana\" color=\"Orange\">Automacao Residencial V 1.0</font><br />");
- client.println("<font size=\"5\" face=\"verdana\" color=\"black\">Hora:"+str+"</font><br />");
- client.println("<font size=\"5\" face=\"verdana\" color=\"black\">Humidade:"+humidade+"</font><br />");
- client.println("<font size=\"5\" face=\"verdana\" color=\"black\">Temperatura:"+temp+"*C""</font><br />");
- if(RelaySala == false){
- statusSala="Desligado";
- }else{
- statusSala="Ligado";
- }
- client.println("<form action=\"Sala\" method=\"get\">");
- client.println("<button type=submit style=\"width:200px;\">Lampadas Sala -"+statusSala+"</button>");
- client.println("</form> <br />");
- if(RelayRecepcao == false){
- statusRecepcao="Desligado";
- }else{
- statusRecepcao="Ligado";
- }
- client.println("<form action=\"Recepcao\" method=\"get\">");
- client.println("<button type=submit style=\"width:200px;\">Lampadas Recepcao -"+statusRecepcao+"</button>");
- client.println("</form> <br />");
- if(RelayArquivo == false){
- statusArquivo="Desligado";
- }else{
- statusArquivo="Ligado";
- }
- client.println("<form action=\"Arquivo\" method=\"get\">");
- client.println("<button type=submit style=\"width:200px;\">Lampadas Arquivo -"+statusArquivo+"</button>");
- client.println("</form> <br />");
- client.println("</center>");
- client.println("</body>");
- client.println("</html>");
- readString="";
- client.stop();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement