Consegui acionar uma ventoinha depois que a temperatura atinge mais que 33 Graus Celcius.
Porém, coloquei o esquema de leitura LEDON da forma que você me passou e fica dando problema.
Eu quero acionar o LED da seguinte forma:
seleciono o checkbox, aplico, o LED liga, e o status fica ON.
se eu deixar o checkbox desmarcado e aplicar, o LED desliga, e o status fica OFF.
O código que postarei aqui em baixo está funcionando, porém está com as partes de LEDON, LOW, HIGH todo invertido.
Fora que mesmo se eu tiver ligado o LED, se eu fechar o browser e abrir novamente com o IP do ethernet shield, o LED apaga, sendo que eu queria que ele mantesse o estado que eu tinha deixado.
#include <String.h>
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
192, 168, 1, 243 }; // IP
byte gateway[] = {
192, 168, 1, 10 }; // roteador
byte subnet[] = {
255, 255, 255, 0 }; //Subnet
Server server(80); //Porta
byte sampledata=50;//some sample data - outputs 2 (ascii = 50 DEC)
int ledPin = 4;//Pino do Led
int fanPin = 5;// Pino do Fan
int analogPin = 0; //Pino Termistor
int tempc= 0, tempf=0,tempk=0;
int samples[8];
int i;
String readString = String(30);
boolean LEDON = false;
boolean FANON = false;//LED status flag
void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
** pinMode(ledPin, OUTPUT);**
pinMode(fanPin, OUTPUT);
Serial.begin(9600); //enable serial datada print
}
void loop(){
Client client = server.available();// Cria uma conexao cliente
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 30)
{
//store characters to string
readString += c;
}
for(i = 0; i<=7 ;i++){
samples = ( 5.0 * analogRead(analogPin) * 100.0) / 1024.0;
_ tempc = tempc + samples*; // somando os 8 valores lidos*_
* }*
* tempc = tempc/8.0; // tirando a media dos 8 valores*
_ tempf = (tempc * 9)/ 5 + 32; // converte para fahrenheit_
* tempk= tempc+273; // converte para Kelvin*
* delay(100);*
* if (tempc >= 33){*
* digitalWrite(fanPin, LOW);*
* FANON = true;*
* }*
* else{*
* digitalWrite(fanPin, HIGH);*
* FANON = false;*
* }*
* //output chars to serial port*
* Serial.print(c);*
* //if HTTP request has ended*
* if (c == '\n') {*
* //lets check if LED should be lighted*
* if(readString.indexOf("L=1") >=0)*
* {*
* //led has to be turned OFF*
* digitalWrite(ledPin, LOW); // set the LED off*
* LEDON = true;*
* }*
* else{*
* //led has to be turned ON*
* digitalWrite(ledPin, HIGH); // set the LED on*
* LEDON = false;*
* }*
* // now output HTML data starting with standart header*
* client.println("HTTP/1.1 200 OK");*
* client.println("Content-Type: text/html");*
* client.println();*
* //set background to yellow*
* client.print("");*
* //send first heading*
* client.println("");*
* client.println("
Casa Inteligente
");*
* client.println("");*
* client.println("");*
* client.println("
");*
* client.println("");*
* client.println("Luz do Quintal");*
* //controlling led via checkbox*
* client.println("LUZ*
");
* client.println("*
(1=ON / 0=OFF)
");
* //printing LED status*
* client.print("Status: ");*
* if (LEDON)*
* client.println("ON");*
* else*
* client.println("OFF");*
* client.println("");*
* client.println("
|
*
");
* client.println("Temperatura C:"); //Mostra as temperaturas em C F e K*
* client.println(tempc);*
* client.println("\t");*
* client.println("Temperatura F:");*
* client.println(tempf);*
* client.println("\t");*
* client.println("Temperatura K:");*
* client.println(tempk);*
* client.println("\n");*
* client.println("");*
* client.println("");*
* readString=""; //clearing string for next read*
* client.stop(); //stopping client*
* }*
* }*
* }*
* }*
}