Saturday, January 7, 2017

Alexa Enabled Terrarium Temperature Monitor

I recently acquired a Hogg Island boa constrictor. An important part about keeping these types of snakes is maintaining a temperature gradient across the enclosure so the snake can thermoregulate. I had a couple TTF-103 thermistors laying around so I thought it would be cool to set up a temperature monitoring system.

I decided to use the Arduino Yun I had on hand to collect the data and make it available on the internet. A quick Google search for "TTF-103 arduino" and I found some code to convert the readings from the thermistor to temperature. I added some code to log readings from two thermistors to the SD card on the Linux side of the Yun.

    File dataFile ="/mnt/sd/temperature.log", FILE_APPEND);
    if (dataFile) {


I put the Yun in a Radio Shack project box and attached it to the back of the snake's enclosure with velcro.

I used regular old scotch tape to attach the thermistors inside the enclosure.

Initially I created a page using jpgraph that displays the temperature readings of both sides of the enclosure .

This was working fine, but wouldn't it be cool if I could just ask the terrarium what the temperature was like? Enter Alexa. It was actually easier than I thought to get a custom skill up and running using the Amazon documentation. The biggest issue I had was trying to get Amazon to use a page served from the web server on the Yun. No matter what I did it complained about the security of the SSL certificate I was using. I ended up finding an Amazon Lambda function that acts as a proxy to bypass this security requirement. All that was left was writing a quick page to return the temperature readings in a format that Alexa can understand.

exec("tail -n 2 /mnt/sd/temperature.log",$lines);
$left = explode(',',$lines[0]);
$right = explode(',',$lines[1]);
$readings = array('left'=>$left[2],'right'=>$right[2]);

$outputSpeech = array("type"=>"PlainText","text"=>"Left side temp ".$readings['left'] ." degrees. Right side temp ".$readings['right'] ." degrees");
$card = array("content"=>"Left: ".$readings['left']." F\nRight: ".$readings['right']." F","title"=>"Temp Readings","type"=>"Simple");
$response = array("version"=>"1.0","response"=>array("outputSpeech"=>$outputSpeech,"card"=>$card,"shouldEndSession"=>true));
header('Content-Type: application/json');
echo json_encode($response,JSON_PRETTY_PRINT);


This produces JSON like this:
    "version": "1.0",
    "response": {
        "outputSpeech": {
            "type": "PlainText",
            "text": "Left side temp 76.5225 degrees. Right side temp 81.8562 degrees"
        "card": {
            "content": "Left: 76.5225 F\nRight: 81.8562 F",
            "title": "Temp Readings",
            "type": "Simple"
        "shouldEndSession": true


  1. Great blog thanks for sharing Looking for the best creative agency to fuel new brand ideas? Adhuntt Media is not just a digital marketing company in chennai. We specialize in revamping your brand identity to drive in best traffic that converts.

  2. Nice blog thanks for sharing Growing your own plant comes with its own challenges and responsibilities. This is why you need a plant nursery in chennai who is ready to help you out throughout the way and guide you through the hurdles of growing a plant - Enter Karuna Nursery Gardens.

  3. Excellent blog thanks for sharing Pixies Beauty Shop is unlike any of the other cosmetic shops in Chennai. With tons of exclusive imported brands to choose from and the best value, this is the best shopping destination for your personal and salon needs.

  4. Very useful blog thanks for sharing While choosing your perfect ride for driving, Accord Cars comes with and the best packages for you to pick from. Self drive cars in Chennai are done the easier. Just pick out your plan from hourly, daily, weekly and even monthly plans available.

  5. Interesting blog thanks for sharing Pearls beauty lounge is the best beauty parlour in chennai. More than 30+ years experience in this field. When you come over at Pearl’s you don’t visit a just a beauty lounge, you are welcomed into an indulging experience which you’ll want to feel again and again. Our secret ingredient for your happiness is in going an extra mile to make you feel pampered.