turn off the temperature sensor pin in arduino uno + ethernet shield.
If the button turn on then its temperature will run, if the button turn off then the temperature will not run. I was stupid once, thank you coding code:
#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"
#define DHTPIN 6
// Uncomment whatever type you're using!
#define DHTTYPE DHT11
// debug ON-OFF
#define UARTDEBUG 1
int ethok=0;
char cmd;
char _buf[255];
byte mac[] = { 0xDE,0xAA,0xBB,0xCC,0xDD,0x01 };
IPAddress ip;
EthernetServer server(80);
DHT dht(DHTPIN, DHTTYPE);
#define pwm 9
void setup() {
Serial.begin(9600);
while (!Serial) {
}
// ethernet setup (using DHCP can be blocking for 60 seconds)
while (ethok==0) restartEthernetShield();
}
void restartEthernetShield() {
delay(100);
if (UARTDEBUG) Serial.println("-- RESTART ETHERNET SHIELD");
ethok = Ethernet.begin(mac);
if (ethok==0) {
if (UARTDEBUG) Serial.println("-- ERROR : failed to configure Ethernet");
} else {
// extract ip
ip = Ethernet.localIP();
// start server
server.begin();
// start listening for clients
if (UARTDEBUG) {
formatIP(ip);
Serial.print("-- IP ADDRESS is ");
Serial.println(_buf);
}
}
delay(100);
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 30"); // refresh the page automatically every 30 sec
client.println();
client.println("");
client.println("");
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.println(t);
Serial.println(h);
// from here we can enter our own HTML code to create the web page
client.print("Office Weather
Office Temperature
Temperature - ");
client.print(t);
client.print(" degrees Celsius
client.print("
Humidity - ");
client.print(h);
client.print(" percent
digitalWrite(pwm, 0-255);
if(t <26 )
{
analogWrite(pwm,0);
Serial.println("Fan OFF");
client.print("Fan OFF");
delay(100);
}
else if(t==26)
{
analogWrite(pwm, 51);
Serial.println("Fan Speed : 20%");
client.print("Fan Speed : 20%");
delay(100);
}
else if(t==27)
{
analogWrite(pwm, 102);
Serial.println("Fan Speed : 40%");
client.print("Fan Speed : 40%");
delay(100);
}
else if(t==28)
{
analogWrite(pwm, 153);
Serial.println("Fan Speed : 60%");
client.print("Fan Speed : 60%");
delay(100);
}
else if(t==29)
{
analogWrite(pwm, 204);
Serial.println("Fan Speed : 80%");
client.print("Fan Speed : 80%");
delay(100);
}
else if(t>29)
{
analogWrite(pwm, 255);
Serial.println("Fan Speed : 100%");
client.print("Fan Speed : 100%");
delay(100);
}
delay(3000);
client.print("
Page refreshes every 30 seconds.
");break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
void formatIP(IPAddress ii) {
sprintf(_buf,"%d.%d.%d.%d",ii[0],ii[1],ii[2],ii[3]);
}
void formatMAC() {
sprintf(_buf,"%02x:%02x:%02x:%02x:%02x:%02x",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
}
static void send_404(EthernetClient client) {
client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println();
client.println("404 NOT FOUND");
}