Project in progress
Habitat Hub: An Alexa and Arduino Smart Home for terrariums.

Habitat Hub: An Alexa and Arduino Smart Home for terrariums. © GPL3+

Need help keeping your pet healthy and safe. Use this environmental monitoring unit that attaches to your reptile or amphibians terrarium.

  • 1,803 views
  • 0 comments
  • 3 respects

Components and supplies

Ard yun
Arduino Yun
The brains of the project.
×1
Adafruit RGB LCD Shield Kit w/ 16x2 Character Display - Only 2 pins used! - NEGATIVE DISPLAY
Used to display environment readings and to configure the settings using the buttons.
×1
12002 04
Breadboard (generic)
Used a 2x3 and a 1x1.
×2
10167 01
DHT22 Temperature Sensor
Used for ambient temperature and humidity.
×1
381 00
Adafruit Waterproof DS18B20 Digital temperature sensor
Use for hot spot and cool spot temperatures.
×2
Solu ® Water Level Sensor Depth of Detection
Used for taking water level measurements of water bowl.
×1
Adafruit industries ada592 image 75px
USB-A to Micro-USB Cable
×1
826 04
Male/Female Jumper Wires
×1
Male/Male Jumper Wires
×1
Cardboard Box
Used as temporary housing for the unit. This is only temporary until finial design has been completed.
×1
3M Dual Lock Reclosable Fastener Velcro
×1
Echo
Amazon Alexa Amazon Echo
×1
Iphone hero
Apple iPhone
Used to setup HabHub's Amazon Alexa Skill.
×1
Gorilla Super Glue Gel, 20 g, Clear
Used to glue Velcro to cardboard box.
×1
Adafruit TACTILE BUTTON SWITCH (6MM) X 20 PACK
Used 2 buttons for the clean water and clean cage button.
×1
Mfr 25fbf52 4k75 sml
Resistor 4.75k ohm
×2
Electrical Tape
×1

Necessary tools and machines

09507 01
Soldering iron (generic)
Wire cutters (generic)
Used in assembly of the LCD backpack kit.
Hobby Knife
Ruler

Apps and online services

About this project

About

My son got a ball python for Christmas. I objected to him getting one but you guest it. I lost that battle. So I joined him on this journey. My major concern was him taking care of his new friend because of the care that is needed for this type of snake. Keeping track of temperatures at different spots in the terrarium, humidity and keeping the water bowl full is a big list for a teenager. This is where the idea for this project came about.

Habitat Hub is an Arduino based unit with multiple sensors and display that helps monitor environmental conditions of a reptile or amphibian terrarium. The display rotates through the temperature areas, humidity, water level and last time the water bowl and cage was cleaned. If there is WiFi access, the unit has the ability to connect to Amazon Alexa to report back these conditions.

For reptiles and amphibians it's important to regulate their environment to mimic their natural habitat and to keep it clean. This project will monitor the following:

  • Ambient Temperature
  • Cool Spot
  • Hot Spot
  • Bowl water level
  • Date of last cage cleaning
  • Date of last water cleaning

Hardware

Creating the Habitat Unit

  • Find a box that's around 15.5" x 12.75" x 3.5". Use a Amazon shipping box if you have one laying around.
  • Choose one end of the box and cut the corners where marked in the photo below to extract the end piece of the box. This will become the casing for our unit. Save the other end for another project.
  • Choose the best side of the cardboard to be the outward side. Turn that side face down. On both ends of the cardboard, use a ruler to mark an inch from the bottom of the cardboard. Mark two spots that are at least six inches apart. Using the ruler, draw a straight line across the width of the piece using these two marks. It's important that the lines are straight.
  • Make sure the lines are face up. Take a knife and score the cardboard on the lines but do not cut through the cardboard. This will allow you to bend the cardboard inward.
  • Measure the length of your lines. Cut two Velcro strips, one hook and one loop, with an adhesive back to the measurement previously taken.
  • Take one Velcro strip to apply it between the line and the end of the cardboard as show in the photo below. Peel tape from backing and press firmly into place keeping the Velcro parallel with your lines. Turn the cardboard over where the outward side is now facing upward.
  • Take the second Velcro strip to apply it between the the line from the crease and the end of the cardboard. Peel tape from backing and press firmly into place keeping the Velcro parallel with your lines.
  • We are going to make the slots for the display headers. On one side of the cardboard, measure an 1 3/4 inch from the fold crease to the center. We are trying to center the display on the face of the unit. Mark the display headers, top and bottom, where they need to be inserted into the box.
  • Use your knife to make the header openings from the marks you made. The size of the marks might vary. Mine were ~1.5" and ~2".
  • Insert the display headers into the cardboard. If it's snug, that's OK, just push until the display back is flush to the cardboard. Peel adhesive backing from small bread board a place it under the display as shown in the photo below.
  • Following is the circuit design with pictures of my finial design.

Software

1. Amazon Web Services

You must have an Amazon Web Service account to complete this project. You may skip to IAM section below if you already have one. To create a free Amazon Web Service account, you may click on the "Create a Free Account" button on the AWS Management Console website. The following step below will assume that you have logged into the AWS management console.

IAM - Identity and Access Management

The IAM link above will bring you to it's landing page. For general help on IAM, you may watch this YouTube video.

  • IAM is used for allowing access to your resources on AWS.
  • Create a user with the following policies: AWSLambdaFullAccess, AWSIoTFullAccess and AmazonAPIGatewayPushToCloudWatchLogs. Make sure you download your Access key ID and Access Secret Key for secure storage and later use. You will not have an opportunity to download the Access Secret Key later.
  • Create a group called HabHub with the following policies: AWSLambdaExecute and AWSIoTFullAccess.
  • Create a role called Habitat_Hub_RDS with the following attached policies:
  • Create a role called Habitat_Hub_Alexa with the following attached policies:
  • Now would be a good time to load awscli for command line operations later. See this page for install instructions: Install awscli or YouTube video here.

IoT - AWS IoT Services (Internet of Things)

The IoT link above will bring you to it's landing page.

  • IoT is used to manage the Habitat unit and to allow Alexa and Client Web interface to access the the unit's data.
  • Click on Manage and then Create button to create a thing. Name it habhub_1234. Create certificates and download them for secure storage and later use.
  • Create a new policy under IoT Secure section. Click on the Create button and name the policy HabHub-Policy. Use the following policy document.
{
 "Version": "2012-10-17",
 "Statement": [
   {
     "Effect": "Allow",
     "Action": [
       "iot:Publish",
       "iot:Subscribe",
       "iot:Connect",
       "iot:Receive",
       "iot:GetThingShadow"
     ],
     "Resource": [
       "*"
     ]
   }
 ]
}
  • Go back to habhub_1234 things that was created in the above task and edit it. Go to it's security sections to show the certificate that were created. Click on the certificate to review it's policies. Use Actions drop down control to Attach policy called HabHub-Policy.
  • Before you leave this section, make sure the certificate has been Activated by using the Actions drop down control as seen in the above photo. Activate will be grayed out if it's activated.

Lambda - AWS Lambda

The Lambda link above will bring you to it's landing page.

  • Lambda is used for several purposes but the most important is the function for the Alexa custom skill.
  • You need to make sure you select the region from the drop-down in the upper right corner. Select US East (N. Virginia).
  • Use the Create function button to start the Create a Lambda Function process.
  • Select Author from scratch.
  • In the Designer section, click on the Alexa Skill Kit trigger that is in the list on the left side shown below. When you click it, it will be applied to the Lambda function bringing it over to the hierarchical chart on the right.
  • To configure the trigger for the Alexa
  • We need to setup the Alexa Custom Skill before entering the Skill ID in the Configure triggers screen below. Come back to this when you have the Skill ID.
  • Click on Alexa_HabHub_Custom_Skill box to add the code.
  • Use the deploy.cmd in the Code directory of AlexHabHubCustomSkill to create the zip file to upload. The deploy.cmd assumes you have 7zip installed in your system. If you don't you may download it from here.
  • Once zipped, click on Upload button to select your zip file. Then press save at the top of the screen.

  • Be patient, it might take a few minutes.
  • Before moving on, copy down the Lambda's function ARN. We'll use it in the Alexa Custom Skill section.

Alexa Custom Skill Kit

  • Go to the Amazon Developer Portal. If you don't already have an account, you will be able to create a new one for free.
  • In the top right corner of the screen, click the Sign In button.
  • Click on the Alexa button at the top of the screen and then click on Alexa Skill Kit.

  • Select Add A New Skill. This will get you to the first page of the new Alexa skill. Fill out the Skill Information screen. There are tips provided to help make it easier for you. See below the screenshot.
  • Skill Type - Custom Interaction Model
  • Name - Habitat Hub
  • Invocation Name - habitat hub
  • Now save the skill by clicking on the save button.
  • Next, go to Interaction model as shown in the below screen shot.
  • Add the following intents using the below json and putting it into the code editor.
{
 "languageModel": {
   "types": [
     {
       "name": "tempSensor",
       "values": [
         {
           "id": "",
           "name": {
             "value": "hot spot",
             "synonyms": []
           }
         },
         {
           "id": "",
           "name": {
             "value": "cool spot",
             "synonyms": []
           }
         },
         {
           "id": "",
           "name": {
             "value": "ambient",
             "synonyms": []
           }
         }
       ]
     }
   ],
   "intents": [
     {
       "name": "AMAZON.CancelIntent",
       "samples": []
     },
     {
       "name": "AMAZON.HelpIntent",
       "samples": []
     },
     {
       "name": "AMAZON.StopIntent",
       "samples": []
     },
     {
       "name": "getHumidity",
       "samples": [
         "give me the humidity",
         "what is the humidity",
         "what is humidity",
         "for the humidity"
       ],
       "slots": []
     },
     {
       "name": "getLastCleanCageDate",
       "samples": [
         "give me the last clean cage date",
         "last time the cage was clean",
         "the last clean cage date"
       ],
       "slots": []
     },
     {
       "name": "getLastCleanWaterDate",
       "samples": [
         "last time water was clean",
         "for the last clean water date",
         "give me the last clean water date"
       ],
       "slots": []
     },
     {
       "name": "getStatus",
       "samples": [
         "the status",
         "for the status",
         "what the status is",
         "give me the status"
       ],
       "slots": []
     },
     {
       "name": "getTemperature",
       "samples": [
         "give me the {tempType}",
         "give me the {tempType} temp",
         "give me the {tempType} temperature",
         "what is the temp of {tempType}",
         "what is the temperature of {tempType}",
         "what is {tempType} temp",
         "what is {tempType} temperature",
         "the temperature of {tempType}",
         "the temp of {tempType}",
         "for the temperature of {tempType}",
         "for the temp of {tempType}",
         "what is the temperature",
         "what's the temperature"
       ],
       "slots": [
         {
           "name": "tempType",
           "type": "tempSensor",
           "samples": [
             "{tempType}",
             "i would like {tempType}"
           ]
         }
       ]
     }
   ],
   "invocationName": "habitat hub"
 },
 "prompts": [
   {
     "id": "Elicit.Intent-getTemperature.IntentSlot-tempType",
     "variations": [
       {
         "type": "PlainText",
         "value": "which temperature sensor are you wanting?"
       }
     ]
   }
 ],
 "dialog": {
   "intents": [
     {
       "name": "getTemperature",
       "confirmationRequired": false,
       "prompts": {},
       "slots": [
         {
           "name": "tempType",
           "type": "tempSensor",
           "elicitationRequired": true,
           "confirmationRequired": false,
           "prompts": {
             "elicitation": "Elicit.Intent-getTemperature.IntentSlot-tempType"
           }
         }
       ]
     }
   ]
 }
}
  • The above code should work with these type questions to Habitat Hub:
  • Save model by clicking on the Save Model button at the top bar followed by the Build Model. Make sure you Build Model after every save and before continuing.
  • You will need the Alex_HabHub_Custom_Skill lambda function ARN to enter it in the Default endpoint.
  • Then add the third Redirect URL on your page to the end of Authorization URL after "?redirect_url=".
  • Client Secret: You can get this on the Login with Amazon page.
  • Privacy Policy URL will have to be filled in for it to be saved.
  • Remember to to copy down your Skill Id to configure the Alexa Custom Skill in your Lambda function.
  • Now you can test using the Test Simulator.

2. Arduino Software

Habitat Hub Arduino ARV Code

This code is for the Arduino Yun AVR side that monitors the sensors and sends the data to the middle ware application on the Linux side. Reason I choose to code the middle ware and not communicate directly to Amazon Web Services was to allow the unit to be fully functional if there was no access to the Internet. You can find the code in projects code section.

The program does the following in the loop:

  • Reads sensors
  • Reads menu buttons
  • Reads clean water button, Send date and command to save configuration
  • Reads clean cage button, Send date and command to save configuration
  • Rotates through sensor data on LCD every 15 seconds
  • Access configuration menu via select button, Change configuration values Up/Down buttons

The following libraries will be needed to build.

  • BridgeClient
  • OneWire
  • DallasTemperature
  • DHT
  • Adafruit_RGBLCDShield

If you need help with uploading code to an Arduino, you may read more about it at Arduino Howto.

Habitat Hub Arduino Linux Side Code

This is the middle ware that stores configuration data from the ARV, receives sensor data and pushes it to the IoT Shadow. You can find the code in projects code section.

habhubconfig.json

  • JSON file containing configuration setting and last clean water and cage day.

habhubconfig.json.bak

  • Backup copy.

habhubgate.py

  • Python middle ware program that needs to be ran automatically when system boots.

run.sh

  • Used to run habhubgate from the command line. I was having trouble getting it to work. I used it to copy and paste the command on the command line.

certs

  • Folder where certificates are stored.
  • aws_iot_root_CA.crt - aws root CA.
  • your_thing-certificate.pem.crt - you will get this after you have created your IoT.
  • your_thing-private.pem.key - you will get this after you have created your IoT.

To run habhubgate.py on startup, you must install the coreutils-nohup package.Instructions:

  • opkg update
  • opkg install coreutils-nohupAdd the following line to /etc/rc.local/---------- Add below Don't add this line --------------------//usr/bin/nohup /your/directory/name/habhubgate.py -e yourIOTendpoint.iot.us-east-1.amazonaws.com \ -r /your/directory/name/certs/aws_iot_root_CA.crt \ -c /your/directory/name/certs/your_thing-certificate.pem.crt \ -k /your/directory/name/certs/your_thing-private.pem.key \ -n habhub_1234 \ -id yourClientID/---------- Add above. Don't add this line --------------------/

You can upload the code using a SCP client. Bitvise SSH Client or Putty would work for you.

NOTE:

  • yourIOTendpoint can be found on the IOT AWS service page under Settings -> Custom Endpoint.
  • yourClientID can be anything but it has to be unique.

Testing

Final Thoughts

This project has pushed me to learn new languages and technology in a short period of time. Habitat Hub is still in it's infancy stage and has a lot a room to grow. There are items I still need to polish with this first version; like more error checking and connection recovery.

I have already started working out the second version with AWS Cognito using user pools and federated identities. Hopefully adding a mobile/web application with a AWS RDS that will monitor current status and trends from your phone or desktop.

All in all, my son and I will be able to keep his new friend Kaa safe and healthy. Even though I lost the battle, I gained more knowledge and a new slithery friend.

Code

Habitat Hub project with Arduino Yun and Alexa
Project code for Habitat Hub. This was my first GitHub repository so please offer me some grace.

Schematics

Habitat Hub Circuit Design

Comments

Similar projects you might like

Alexa BBQ/Kitchen Thermometer with IoT Arduino and e-Paper

Project tutorial by Roger Theriault

  • 2,387 views
  • 0 comments
  • 9 respects

Smart Pool: Alexa Controlled Pool Manager

Project tutorial by Benjamin Winiarski

  • 1,355 views
  • 2 comments
  • 7 respects

How to Build a DIY Arduino-Based Smart Home Hub with 1Sheeld

Project tutorial by amrmostaafaa

  • 5,722 views
  • 1 comment
  • 29 respects

Hygge Home - Alexa Smart Bath

Project tutorial by J Howard

  • 5,355 views
  • 2 comments
  • 18 respects

Smart IOT Propane Monitoring Pedestal

Project in progress by Team A Bit Gassy

  • 1,284 views
  • 1 comment
  • 12 respects

Amazon Alexa / Arduino YÚN Smart Home Light Sample

Project showcase by Noctuvigilus

  • 3,242 views
  • 0 comments
  • 9 respects
Add projectSign up / Login