Maker.io main logo

Adafruit.io Smart Home

2020-07-01 | By Grace Hill

License: General Public License Fans Arduino Adafruit Feather

Guide By Grace Hill

Overview

This project is based on the Digi-Key Mini Smart Home for Atmosphere IoT Studio.

Explore the Internet of Things(IoT) with Adafruit IO in a real-life situation! Through Digi-Key's Mini Smart Home kit, you will be able to experiment with environmental sensors and an alarm system. All this is possible through Adafruit.io which allows for a connection with your microcontroller over WiFi. No need to wonder if it's staying cool in your house in the summer or warm in the winter when you can check from anywhere with a Wi-Fi connection. After experimenting on a small scale, you can repurpose the supplies and use them in your own house.

Adafruit.io

Adafruit.io is a cloud service without the need for personal management (Adafruit takes care of that for you). It provides the ability to store data, interact with the microcontroller, and be connected to Wi-Fi which allows you to check in on your device wherever you have Wi-Fi. And they offer this to you all for free! It's up to you how you will use it.

Smart Home Hub

The hardware of the mini smart home consists of the main hub that is connected through a 2 x 2 quad board. It has one main microcontroller along with two sensors and a relay. Connected to the microcontroller are multiple inputs/outputs that allow for interactions.

Materials 

Tools

 All these materials can be bought on Digi-Key's website.

Wiring

BME680

  • Vin To 3.3 V
  • GND to GND
  • SCK to SCL
  • SDI to SDA

BME680 wiring

Buzzer

  • Long leg to pin 12
  • Short leg to GND

Buzzer wiring

Mini Relay FeatherWing

  • 3 V to NC on the Pin Connector
  • Signal to Pin 33

Relay

Female JST connectors

  • JST Female-red to Pin 15
  • JST Female-black to GND
  • top half
  • JST 2 Female-red to Pin 13
  • JST 2 Female-black to GND

Bottom half

  • JST 3 Female-red to Pin A3
  • JST 3 Female-black to GND

 A3_GND

 

Door

If you haven't recycled the box already, use it for the door. Measure and cut a door to fit in the inside of the house. Before installing the door, glue the sensor for the door with the wires to the door frame. Once the glue has set, begin to attach the door. Tape or a bamboo shoot will work for allowing the door to open and close. When the door has been placed, close it and glue on the second part of the magnetic door sensor (there should be no wires attached). Now, take the wires and strip about an eighth of an inch off. Slide a piece of shrink wrap on both wires and then solder on a JST Male Cable. It does not matter which wire is connected to which. After soldering, slide the shrink wrap over the newly soldered area and apply heat. Now that the connection is protected you are ready to proceed.

 Fan_Wiring

door

Fan

Take the popsicle stick out of the kit and cut it to the size of the ceiling. Put it on the ceiling and glue in place.

Place a small ring of shrink wrap around both of the fan wires and slide them down by the fan. Strip the wires and solder to a male JST wire so that the colors match up. After the soldering is complete, slide the shrink wrap over the newly soldered area and apply heat to shrink into place.

Once the wiring is done, put a small dot of glue in the center of the back of the motor (be cautious of the holes, do not get glue in them), and adhere to the popsicle stick making sure it is centered. If glue doesn't work try a sturdy tape such as duct tape or hockey tape.

Before placing the fan blades onto the motor, trim about an eighth of an inch off each blade or enough so that the fan can run without hitting the walls of the house.

fan plus led

LEDs

Strip the ends of a male JST cable and match the black wire to the negative and the red wire to the positive. There are five LEDs that come in the kit. The amount used is up to you, just be mindful when stripping the wires and placing the LEDs. Solder into place then tape or glue the LEDs to the ceiling or the inside of the roof.

LED_Wiring

Putting it All Together

Solder the headings onto the quad prototype board and attach the Non-Latching Relay on the upper left corner and the Huzzah 32 in the lower right corner. They should slip into the newly connected headers of the Quad board. 

Make the following connection of JST cables:

  • JST female Pin 13 to JST male LEDs
  • JST female Pin 12 to JST male Fan
  • JST female Pin A3 to JST male Door

HUB

Hole for USB Connection

Look at the house straight on, turn the house to the side on which the door is closer. In the lower-left corner of this wall, measure the height as well as the length you need to put the USB through the wall. Cut with a box cutter or Exacto knife.

Side_Opening

How Adafruit.io Works

Adafruit IO connects to your device through Wi-Fi. To get the device onto the Wi-Fi, the code must allow for your device to do so. Adafruit.io has a library of codes that allow for those who are new to coding a chance to experience the Internet of Things(IoT), all with having little to no knowledge of coding. In this project, the code to allow for communication back and forth will be in a file called config.h. 

Setup

Before being able to hook up your microcontroller, you must log in or create an account on the Adafruit.io website. Once your profile is made, we can continue on with our project.

Feeds

Our main line of communication with the microcontroller is through the feeds. To create a feed, click on the drop bar in the top left corner and hit Create Feed.

Create Feed

Name your feed.

 Name Feed

This project consists of five feeds: Temperature, Humidity, Digital, Door, and Alarm. All of these will be either feeding information to you or the controller. For more information on feeds, Adafriut.io has a course: https://learn.adafruit.com/series/adafruit-io-basics.

Feeds

Dashboards

Dashboard

After your feeds have been created, click on the dashboard, and create a new one. The dashboard is where you will be able to monitor and interact with your home.

To add a gauge to receive your data, click on the blue plus sign in the upper right corner. 

 Create Block

A variety of options will be available, choose the gauge.

Create Block

Select the Temperature feed.

Temperature

Name the block then change the gauge so that the minimum is 0 and your maximum is 100.

Temperature Gauge

Add a block with the blue plus sign.

Create Block

Select the gauge again.

Select Gauge

Set the feed to Humidity.

Humidity Feed

Set the minimum value to 0 and the maximum m value to 100.

Humidity Block

To add the light switch, click the blue plus sign in the corner.

Create Block

Choose the toggle. 

Create Toggle

Connect the Digital feed.

Digital Feed

Name the toggle LED. It’s important to change the toggle name for On and Off to 1 and 0, respectively. If not done, your light will not respond. Create the block and place.

Toggle LED

Create another toggle and set the feed to Alarm.

Alarm Feed

Name the toggle Alarm System. You do not need to change the On and Off, it will work without switching it to 1 and 0. Create the block and place.

Toggle Alarm

The last feed we will use is the Door feed. For this sensor, we will be indicating if the door is open or closed. Add another block and choose the indicator. 

Indicator

Set the feed as a door. 

Door Feed

Rename to read the Door indicator. Change the values and the condition. The conditions should be set to if equal to 1.

Door

To edit the layout of the dashboard, click the green gear in the upper right corner. This will allow you to drag the blocks into different places as well as change the setting of each of the blocks.

Redesign

Arduino IDE

With the Arduino IDE application, we will be able to access the library of pre-made projects by Adafruit as well as upload our code and write new ones. If you do not have Arduino IDE installed on your device, do so now. Once installed there are a few more files that need to be installed within the Arduino IDE application.

Libraries

Under the Sketch tab, you will find Include Library, go onto Manage Libraries. Once at the search bar, install the following libraries: Adafruit IO Arduino, and BME680.

Manage Library

Manage Library

Boards

Click Tools, Board, then Manage Boards. Here you will need to install the ESP 32 file to be able to run on the Huzzah 32 FeatherWing. Once completed, go back to the Tool handlebar, go to Board and find the Adafruit ESP32 FeatherWing.

Manage Boards

Enter Board

Code

Open a new code and copy and paste this code:

Copy Code
//include libraries
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#include "Adafruit_SGP30.h"
#include "config.h"

//
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10


#define LED_PIN 13
#define FAN_PIN 15
#define DOOR_PIN A3
#define BUZZER_PIN 12
#define ALARM_PIN 5

//set the feeds
Adafruit_BME680 bme; // I2C
AdafruitIO_Feed *TempFeed = io.feed("temperature");
AdafruitIO_Feed *HumFeed = io.feed("humidity");
AdafruitIO_Feed *Digital = io.feed("digital");
AdafruitIO_Feed *Alarm = io.feed("alarm");
AdafruitIO_Feed *Door = io.feed("door");

//global variable
bool isAlarm = false;
bool isDoor = false;

void handleMessage(AdafruitIO_Data *data) {

Serial.print("received <- ");

if(data->toPinLevel() == HIGH)
Serial.println("HIGH");
else
Serial.println("LOW");
digitalWrite(LED_PIN, data->toPinLevel());
}

void handleAlarm(AdafruitIO_Data *data) {
// handle the alarm toggle on the Adafruit IO Dashboard
String toggleValue = data->toString();
Serial.print("> rcv alarm: ");
Serial.println(toggleValue);
if(toggleValue == String("ON")) {
Serial.println("* Alarm Set: ON");
isAlarm = true;
} else {
Serial.println("* Alarm Set: OFF");
isAlarm = false;
}
}

void setup() {
//set inputs/outputs
pinMode(LED_PIN, OUTPUT);
pinMode(FAN_PIN, OUTPUT);
pinMode(DOOR_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(ALARM_PIN, OUTPUT);

Serial.begin(9600);
while (!Serial);
Serial.println(F("BME680 test"));
if (!bme.begin()) {
Serial.println("Could not find a valid BME680 sensor, check wiring!");
while (1);
}
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);

Serial.print("Connecting to Adafruit IO");
io.connect();
// wait for a connection
while (io.status() < AIO_CONNECTED)
{
Serial.print(".");
delay(500);
}

// we are connected
Serial.println();
Serial.println(io.statusText());
Digital->onMessage(handleMessage);
Alarm->onMessage(handleAlarm);
Digital->get();
Alarm->get();

}

void loop() {
io.run();

Serial.println("Reading Sensors....");

int TempRead = bme.readTemperature();
TempRead=((TempRead)*(9/5))+32;
Serial.print("Temperature = ");
Serial.print(bme.temperature);
Serial.println("*C");

int HumRead = bme.readHumidity();
Serial.print("Humidity = ");
Serial.print(bme.humidity);
Serial.println("%");

//saves to the io
TempFeed->save(TempRead);
HumFeed->save(HumRead);

// Fan turns on if it gets above 70 degrees
if(TempRead >= 70){
digitalWrite(15,HIGH);
}
else
digitalWrite(15,LOW);
int i = 0;
//Alarm system: if door is open and the alarm is set then turn on the buzzer

if(analogRead(DOOR_PIN)>0){
isDoor = true;
if(isAlarm ==true)
digitalWrite(BUZZER_PIN,HIGH);
}
else{
digitalWrite(BUZZER_PIN,LOW);
isDoor=false;
}
Door->save(isDoor);
//wait 20 sec to check sensors again
delay(2500);

}
//acts as light switch

After the main code is in we need to add some side code. Add a new tab and name it config.h. This file of code allows your device to connect over the Wi-Fi network. Copy and paste the config.h code into the program.

New Tab Arduino

Copy Code
#define IO_USERNAME "Username"
#define IO_KEY "Keycode"

#define WIFI_SSID "SSID"
#define WIFI_PASS "password"

#include "AdafruitIO_WiFi.h"

#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
defined(ADAFRUIT_PYPORTAL)
// Configure the pins used for the ESP32 connection
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
// Don't change the names of these #define's! they match the variant ones
#define SPIWIFI SPI
#define SPIWIFI_SS 10 // Chip select pin
#define NINA_ACK 9 // a.k.a BUSY or READY pin
#define NINA_RESETN 6 // Reset pin
#define NINA_GPIO0 -1 // Not connected
#endif
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif

Before compiling, type in your username, keycode, Wi-Fi name, and password in place of the filler in the config.h code. Without this, you will not be able to communicate with your board.

Afterward, in the upper right corner is a checkmark. Hit this to compile the program to make sure that everything is in place. 

Verify

Upload code by clicking on the arrow next to the compile button.

Upload

log in to Adafruit.io to watch the data roll in. Don't forget to have fun with the light and alarm system as well.

If you would like more information on how Adafruit.io works, visit their website here.

For original BME680 Wiring photo, Buzzer Wiring photo, and Hole for the USB photo go to the original project: https://www.digikey.com/en/maker/projects/digi-key-iot-studio-mini-smart-home/c545d33029044fa183531c43ff052715 

 

制造商零件编号 4450
ADAFRUIT MINI SMART HOME KIT
Adafruit Industries LLC
¥732.20
Details
制造商零件编号 3619
HUZZAH32 ESP32 FEATHER STACK HDR
Adafruit Industries LLC
¥178.67
Details
制造商零件编号 4147
ADXL343 + ADT7410 SENSOR FEATHER
Adafruit Industries LLC
¥97.27
Details
制造商零件编号 3660
STEMMA QT BME680 SENSOR BOARD
Adafruit Industries LLC
¥154.25
Details
制造商零件编号 375
MAGNETIC CONTACT SWITCH (DOOR SE
Adafruit Industries LLC
¥32.15
Details
制造商零件编号 1536
TERM BINDING POST 8-32 1PIN PCB
Keystone Electronics
¥15.79
Details
制造商零件编号 2895
ADAFRUIT NON-LATCHING MINI RELAY
Adafruit Industries LLC
¥70.39
Details
制造商零件编号 1755
ADAFRUIT LED SEQUINS
Adafruit Industries LLC
¥33.28
Details
制造商零件编号 3896
3-BLADED TRIFOIL PROPELLER FAN F
Adafruit Industries LLC
¥6.48
Details
制造商零件编号 1131
JST-PH BATTERY EXT CABLE
Adafruit Industries LLC
¥15.87
Details
制造商零件编号 592
CABLE A PLUG TO MCR B PLUG 3'
Adafruit Industries LLC
¥24.01
Details
制造商零件编号 1649
MULTI-COLORED HEAT SHRINK PACK
Adafruit Industries LLC
¥42.59
Details
PLR RAD HOSE PINCH OFF
制造商零件编号 145
PLR RAD HOSE PINCH OFF
Apex Tool Group
¥328.34
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum