ESP8266 Controlled Gecko Habitat :: Student Project
A student of our training, John Hart, is at it again with an interesting new project that uses an ESP8266 to control the temperature of the family pet gecko habitat.
The ESP8266 is a low cost WiFi module that can be programmed right from the Arduino IDE. It’s great, because all the Arduino code you learn can be used on it just any other Arduino board.
He did a great write of the project at Instructables. Here is a video that walks through the project…
Here is picture of his wife’s spotted gecko “Leonardo”. I think he looks happy – what about you?

Here is what John had to say about the project…
“In a nutshell, there are (2) DS18B20 sensors connected to the ESP8266 via Onewire. One sensor measuring the surface bottom temp and one measuring the air temp. The surface sensor is the decision maker. When it is low, it turns on a relay connected to the heat and warms things up. And vice-versa. The webserver that the ESP is hosting is a nice value-add so we can take a peek at the data whenever we’d like….
Thought you might be interested in taking a look at another ‘cool gizmo’ that came to life largely in part thanks to your training.”
John was also kind enough to share his Arduino code….
Arduino Code:
//JohnnyFRX 13Aug17
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
WiFiServer server(6969);//********************************************************************PORT
#define ONE_WIRE_BUS_PIN D3//*****************************************************************PIN ASSIGNMENT FOR DS18B20
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);
//********************************************************************************************************** http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress heatpadThermo = { 0x28, 0xFF, 0x0C, 0x29, 0xA0, 0x16, 0x05, 0x05 };//********************************YOUR DS18B20 ADDRESS...SEE COMMENT/URL ABOVE FOR DETAILS
DeviceAddress coolsideThermo = { 0x28, 0xFF, 0x04, 0x95, 0x83, 0x16, 0x03, 0x15 };//*******************************YOUR DS18B20 ADDRESS...SEE COMMENT/URL ABOVE FOR DETAILS
const int relayPin = D8;//********************************************************************PIN ASSIGNMENT FOR RELAY
boolean heatStatus;
void setup()
{
Serial.begin(9600); const char* ssid = "";//*********************************************************************YOUR SSID
pinMode(relayPin, OUTPUT);
const char* password = "";//****************************************************************************************YOUR SSID PASSWORD
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
server.begin();
Serial.println("Web server running. Waiting for the ESP IP...");
delay(10000);
Serial.println(WiFi.localIP());
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Initializing Temperature Control Library Version ");
Serial.println(DALLASTEMPLIBVERSION);
sensors.begin();
sensors.setResolution(heatpadThermo, 10);//****************************************************************************SET RESOLUTION FROM 9-12....9 IS FASTEST
sensors.setResolution(coolsideThermo, 10);//****************************************************************************SET RESOLUTION FROM 9-12....9 IS FASTEST
}
void loop()
{
delay(1000);
Serial.println();
Serial.print("Number of Devices found on bus = ");
Serial.println(sensors.getDeviceCount());
Serial.print("Getting temperatures... ");
Serial.println();
sensors.requestTemperatures();
Serial.print("heatpadThermo temperature is: ");//*****************************************************************YOUR INFO
printTemperature(heatpadThermo);
Serial.println();
float heatpadTemp = sensors.getTempF(heatpadThermo);
Serial.print("coolsideThermo temperature is: ");//*****************************************************************YOUR INFO
printTemperature(coolsideThermo);
Serial.println();
float coolsideTemp = sensors.getTempF(coolsideThermo);
//***********************************************************************************************************************BELOW VARIES ON 'NC' OR 'NO' RELAY AND LOGIC
if (heatpadTemp < 75) {
digitalWrite(relayPin, LOW);
heatStatus=true;
} else {
digitalWrite(relayPin, HIGH);
heatStatus=false;
}
if (heatpadTemp >= 85) {
digitalWrite(relayPin, HIGH);
heatStatus=false;
}
//***********************************************************************************************************************ABOVE VARIES ON 'NC' OR 'NO' RELAY AND LOGIC
//****************************************************************************************************************************WEB STARTS HERE
WiFiClient client = server.available();
if (client) {
Serial.println("New client");
// bolean to locate when the http request ends
boolean blankLine = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n' && blankLine) {
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>");
client.println(" <HEAD>");
client.println(" <TITLE> Leonardo's Lair </TITLE>");//*****************************************************************YOUR INFO
client.println("</head>");
client.println("<style>");
client.println("</style>");
client.println(" </HEAD>");
client.println("<body>");
client.println("<br>");
client.print ("<font color=green size=7>");
client.println("<H1><center>Leonardo's Lair</center></h1>");//*****************************************************************YOUR INFO
client.println("<center>");
client.println("<H2>Current Status</H2>");
client.println("<table id=""t01"">");
client.print ("<font color=black size=7>");
client.println("<br />");
client.print ("<font color=black size=7>");
client.print("Heatpad Thermo: ");//*****************************************************************YOUR INFO
client.print(heatpadTemp); //print temperature from DS18x20 sensor
client.println("\xB0");//*********************************************************************************************DEGREE SYMBOL
client.println(" F");
client.print ("<font color=green size=7>");
client.print ("<font color=black size=7>");
client.println("<br />");
client.print ("<font color=black size=7>");
client.print("Coolside Thermo: ");//*****************************************************************YOUR INFO
client.print(coolsideTemp); //print temperature from DS18x20 sensor
client.println("\xB0");//*********************************************************************************************DEGREE SYMBOL
client.println(" F");
client.print ("<font color=green size=7>");
client.println();
break;
}
if (c == '\n') {
blankLine = true;
}
else if (c != '\r') {
blankLine = false;
}
}
}
delay(1);
client.stop();
Serial.println("client disconnected");
}
//**********************************************************************************************************************WEB STOPS HERE
}//*********************************************************************************************************************END VOID LOOP HERE
/*-----( Declare User-written Functions )--------------------------------------------------------------------------------NOT USED---*/
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00)
{
Serial.print("Error getting temperature ");
}
else
{
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}// End printTemperature