Temperature Webserver

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

atoughram

Well-Known Member
Joined
May 23, 2013
Messages
1,896
Reaction score
297
Location
Puyallup
Finally got the DS18B20 from China and connected it up to my Arduino with Ethernet shield. My plan is to keep track of temperatures in my kegerator and fermentation cabinet, along with the status of the garage doors and maybe a light sensor to tell me if I left the lights on. I was really surprised at how easy the DS18B20 is to integrate! It should be capable of eight temperature channels easily. I'll post the schematics and code when I get the other sensor.

DSCN0350.jpg


Fullscreen capture 6122013 83653 AM.jpg
 
OK - I'm fairly sure it will read up to 8 sensors now... I've only got three to test it with though. Here's a screen shot. I've got to clean up the code and then I'll post it.

screen.jpg
 
Here is the code so far.

/*
Fermenter Web Server

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Up to eight DS18B20's attached to Pin 9

Created June 26, 2013
by atoughram

*/
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

//Initialize the Onewire library with the DS10B20's on pin 9
//Install a 4.7K resistor between pin 9 and +5V
OneWire ds(9);

//Set up some variables
byte i, ii; //array pointers
byte dev[8] [8]; //device array
byte devpr; //Number of devices present

void setup() {
// Open serial communications
Serial.begin(9600);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());

//Find all of the Onewire devices connected to pin 9
for (ii = 0; ii < 8; ii++) { //Up to eight devices
if (!ds.search(dev[ii])){ //if no devices found
Serial.println("No more devices found! ");
devpr = ii;
Serial.print("Number of devices found equal ");
Serial.println(devpr);
ds.reset_search();
delay(250);
return;
}
}

}

void loop() {

byte present = 0;
byte data [8] [12];
int16_t raw [8];
float celsius [8], fahrenheit [8];

//Print out the device serial numbers
for( ii = 0; ii < devpr; ii++) {
Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(dev[ii], HEX);
}
Serial.println("");
}
//Let get some data!
for( ii = 0; ii < devpr; ii++) { //Select which device
ds.reset();
ds.select(dev[ii]);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
present = ds.reset();
ds.select(dev[ii]);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[ii] = ds.read();
}
}
//Conversion time...
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
for( ii = 0; ii < devpr; ii++) {
raw [ii]= (data[ii][1] << 8) | data[ii][0];
raw [ii]= (raw [ii] & 0xFFF0) + 12 - data[ii][6];
celsius [ii] = (float)raw [ii] / 16.0;
fahrenheit [ii] = celsius [ii] * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius [ii]);
Serial.print(" Celsius, ");
Serial.print(fahrenheit [ii]);
Serial.println(" Fahrenheit");
}
// listen for incoming clients on the Ethernet
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: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html><title>Garage Status</title>");
client.println("<body BGCOLOR='#ccffff'>");
client.println("<h1 style='text-align: center;'>Fermentation and Refrigerator Temps</h1>");
client.println("<table style='width: 100%' border='1'>");
client.println("<tbody>");
client.println("<tr>");
client.print("<td><font size=+10 color=#ff3300>Fermenter Cabinet <b>");
client.print(fahrenheit [0]);
client.println("f</b></font></td>");
client.print("<td><font size=+10 color=#3399cc>Refrigerator Temp <b>");
client.print(fahrenheit [1]);
client.println("f</b></font></td></tr>");
/* client.print("<tr><td><font size=+10 color=#3399cc>Sensor 3 <b>"); //Commented out - comment in whichever sensors your going to use.
client.print(fahrenheit [2]); //If celsius is preferred, change variable fahrenheit to celcius
client.println("f</b></font></td>"); //If celsius is preferred, change f at beginning of line to c
client.print("<td><font size=+10 color=#3399cc>Sensor 4 <b>");
client.print(fahrenheit [3]);
client.println("f</b></font></td></tr>");
client.print("<tr><td><font size=+10 color=#3399cc>Sensor 5 <b>");
client.print(fahrenheit [4]);
client.println("f</b></font></td>");
client.print("<td><font size=+10 color=#3399cc>Sensor 6 <b>");
client.print(fahrenheit [5]);
client.println("f</b></font></td></tr>");
client.print("<tr><td><font size=+10 color=#3399cc>Sensor 7 <b>");
client.print(fahrenheit [6]);
client.println("f</b></font></td>");
client.print("<td><font size=+10 color=#3399cc>Sensor 8 <b>");
client.print(fahrenheit [7]);
client.println("f</b></font></td></tr>"); */
client.println("</tbody>");
client.println("</table>");
client.println("</body>");
client.println("</html>");
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 disconnected");
}
}
 
Looks good!

I did something similar with mine except pushing the data to COSM to get really nice graphs and data logging(now Xively). I really should update the code on my original post, but its pretty straight forward to download the new Xively API and replace the COSM calls with Xively ones, they are literally the same function names with COSM replaced with Xively....
 
Way cool! My ethernet shield has a micro-SD slot on it, I could use it to data log also. I've got an RTC module somewhere around here too....

I noticed that you first identify the sensors and then hard code their serial numbers into the final code. This code should go out and discover the sensors in void setup(), store the serial numbers in the dev array, and then reads them in void loop().

I have to apologize for my programming. I was self taught in "C" on VAX/VMS many years ago and never really programmed professionally in that language.
 
Hy nice sketch,
Is there a possibiliti to set the resolution (10,11,12 byte) ? I try to change evrithing but the result is __.00 :confused:

thanks .





Here is the code so far.

/*
Fermenter Web Server

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Up to eight DS18B20's attached to Pin 9

Created June 26, 2013
by atoughram

*/
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

//Initialize the Onewire library with the DS10B20's on pin 9
//Install a 4.7K resistor between pin 9 and +5V
OneWire ds(9);

//Set up some variables
byte i, ii; //array pointers
byte dev[8] [8]; //device array
byte devpr; //Number of devices present

void setup() {
// Open serial communications
Serial.begin(9600);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());

//Find all of the Onewire devices connected to pin 9
for (ii = 0; ii < 8; ii++) { //Up to eight devices
if (!ds.search(dev[ii])){ //if no devices found
Serial.println("No more devices found! ");
devpr = ii;
Serial.print("Number of devices found equal ");
Serial.println(devpr);
ds.reset_search();
delay(250);
return;
}
}

}

void loop() {

byte present = 0;
byte data [8] [12];
int16_t raw [8];
float celsius [8], fahrenheit [8];

//Print out the device serial numbers
for( ii = 0; ii < devpr; ii++) {
Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(dev[ii], HEX);
}
Serial.println("");
}
//Let get some data!
for( ii = 0; ii < devpr; ii++) { //Select which device
ds.reset();
ds.select(dev[ii]);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
present = ds.reset();
ds.select(dev[ii]);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[ii] = ds.read();
}
}
//Conversion time...
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
for( ii = 0; ii < devpr; ii++) {
raw [ii]= (data[ii][1] << 8) | data[ii][0];
raw [ii]= (raw [ii] & 0xFFF0) + 12 - data[ii][6];
celsius [ii] = (float)raw [ii] / 16.0;
fahrenheit [ii] = celsius [ii] * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius [ii]);
Serial.print(" Celsius, ");
Serial.print(fahrenheit [ii]);
Serial.println(" Fahrenheit");
}
// listen for incoming clients on the Ethernet
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: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html><title>Garage Status</title>");
client.println("<body BGCOLOR='#ccffff'>");
client.println("<h1 style='text-align: center;'>Fermentation and Refrigerator Temps</h1>");
client.println("<table style='width: 100%' border='1'>");
client.println("<tbody>");
client.println("<tr>");
client.print("<td><font size=+10 color=#ff3300>Fermenter Cabinet <b>");
client.print(fahrenheit [0]);
client.println("f</b></font></td>");
client.print("<td><font size=+10 color=#3399cc>Refrigerator Temp <b>");
client.print(fahrenheit [1]);
client.println("f</b></font></td></tr>");
/* client.print("<tr><td><font size=+10 color=#3399cc>Sensor 3 <b>"); //Commented out - comment in whichever sensors your going to use.
client.print(fahrenheit [2]); //If celsius is preferred, change variable fahrenheit to celcius
client.println("f</b></font></td>"); //If celsius is preferred, change f at beginning of line to c
client.print("<td><font size=+10 color=#3399cc>Sensor 4 <b>");
client.print(fahrenheit [3]);
client.println("f</b></font></td></tr>");
client.print("<tr><td><font size=+10 color=#3399cc>Sensor 5 <b>");
client.print(fahrenheit [4]);
client.println("f</b></font></td>");
client.print("<td><font size=+10 color=#3399cc>Sensor 6 <b>");
client.print(fahrenheit [5]);
client.println("f</b></font></td></tr>");
client.print("<tr><td><font size=+10 color=#3399cc>Sensor 7 <b>");
client.print(fahrenheit [6]);
client.println("f</b></font></td>");
client.print("<td><font size=+10 color=#3399cc>Sensor 8 <b>");
client.print(fahrenheit [7]);
client.println("f</b></font></td></tr>"); */
client.println("</tbody>");
client.println("</table>");
client.println("</body>");
client.println("</html>");
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 disconnected");
}
}
 
I'm sorry - I didnt try any other resolutions - I believe you must write to the DS18B20 to change the resolutions and I never did try that.

I no longer use this system - I replaced it with a brewpi.
 

Latest posts

Back
Top