Project tutorial
Smart Vent System

Smart Vent System © GPL3+

Smart Vent System will help you save energy by heating or cooling only the rooms that you need.

  • 24 respects

Components and supplies

Apps and online services

About this project

Artik Challenge Category: Best Smart Home Application

The Nest thermostat was a leap in automated climate control.

However, did you ever wonder why do you need to heat or cool unoccupied rooms, like the office or kitchen during the night?

Smart Vent is an IoT enhanced vent that senses when there is people occupying a room, its temperature, and sends this information to Artik Cloud to optimize home or office climate control and save energy.

Our comprehensive solution provides 4 different ways for controlling individual vents:

  • Manual Control: Each vent can be easily opened or closed (toggle) by just the press of a button.
  • Voice: Use Amazon Alexa to request opening or closing a particular vent using voice commands.
  • Mobile: We developed an Android App to control our vents.
  • Rules: Use Artik Cloud's powerful rules to automate all vent states and avoid unsafe states like having all vents closed at once.

Customize Artik Cloud rules to:

  • Close vents during the night in unoccupied rooms like office or kitchen.
  • Open vents for occupied rooms relying on the Smart Vent motion sensors.
  • Open or Close vents according to local temperature.

The android app is open source and can be found in github. The app sends Artik Cloud commands to individual vents to open or close them.


We used Artik 10 as the main IoT Hub of the home and office. The Artik 10 runs a local MQTT broker, connects to all the vent's controllers and interacts with Artik Cloud.

Not having each vent connect directly to Artik Cloud but instead to the Artik 10 local hub has the advantages of efficiency, security and cost. Our prototype uses a Particle Photon for the vent controller but our final product will use an Artik 1 which is better suited and cheaper.

Artik Cloud get all sensors messages which are displayed in the charts section. These messages, like temperature and motion, are used by rules to automate the smart vents.

Creating an Artik Account

Go to and open an account.

Creating a Device Type

On the dashboard, press on the "New Device Type" button.

Create a new device type for Smart Vent

Press "New Manifest" to create the manifest for the Smart Vent.

Create a "state" field:

then a "temp" field

last a "motion" field:

Press on "NEXT: ACTIONS" to configure the actions. Let's start with the "open" action.

then the "close" action.

Select "Activate Manifest".

Connecting a Device

Navigate to the Artik Cloud Portal for Users at and login.

Select "+ Connect another device". There search for the smart vent device type and name your device.

After creating the device, select the gear in order to get the device info.

Press "Generate Token" to create the device secret token.

Copy your DEVICE ID and the DEVICE TOKEN. These values will be used to authenticate the device to send (or receive) date to Artik Cloud.

Creating Automation Rules

Rules will allow to automate actions according to sensor information.

Let's create 4 rules:

First rule will open the office vent in the morning at 8:00am

Second rule will close the vent at 11:00pm to avoid heating/cooling the office at night when it is unoccupied.

Third rule will close the vent when the office is unoccupied for a while.

Forth rule will open the vent when it detects motion and the office is above certain temperature.

Creating an Artik App

Go to your developer dashboard and select "New Application"

Name your app to "Smart Vent System", select "client Credentials auth code implicit" and provide an auth url which should match the one used in the app. Select save application.

Set the smart permissions to read and write for the smart vent and read for the profile. Select save.

You app is set. Click in "Show client ID & secret" to get your keys. These keys are needed to configure your app.

Configuring Amazon Alexa

In order to be able to control the Smart Vent using voice then you need to configure Amazon Alexa by following these steps:

Login to Amazon Alexa portal at, select "skills" and search for "Artik Cloud".

Press the "Enable" button to activate the skill.

When requested login to Artik Cloud account and authorize access to your account devices. You will get a message confirming that your skill was successfully linked.

Building the Vent Controller

  • Get all your components. If the motorized vent includes a controller you can remove it since we are going to connect our IoT project directly to the motor.
  • Connect your circuit according to the provided diagram.
  • Flash your Photon with the provided sketch from particle's ide . You need to update the ip address of your Artik 10 IoT hub in the sketch.

Configuring the Artik 10

  • Follow the instructions from Artik Tutorials to get mqtt broker and node-red installed.
  • Launch the mqtt broker by running $ mosquitto &
  • Configure your node-red program as described below.

Node-Red is a tool for wiring together hardware devices, APIs and online services using a drag and drop flow editor.

Configure your Node-Red flow by following this diagram.

Set the format temp event function as follows:

msg.topic = "/v1.1/messages/"+global.get("deviceId")   
msg.payload = { 
   "temp": parseFloat(msg.payload)  
return msg; 

Set the format motion event function as follows:

msg.topic = "/v1.1/messages/"+global.get("deviceId")   
msg.payload = { 
   "motion": (msg.payload == "true") 
return msg; 

Set the format action function as follows:

var json = JSON.parse(msg.payload) 
var action = json["actions"][0]["name"]; 
msg.topic = "office-vent"   
msg.payload = action;   
return msg; 

The deviceId global variable above is defined in the .node-red/settings.json file:

  // Anything in this hash is globally available to all functions. 
   // It is accessed as 
   // eg: 
   //    functionGlobalContext: { os:require('os') } 
   // can be accessed in a function block as: 
   functionGlobalContext: { 
       // os:require('os'), 
       // octalbonescript:require('octalbonescript'), 
       // jfive:require("johnny-five"), 
       // j5board:require("johnny-five").Board({repl:false}) 
       deviceId:"<<your device id>>" 

Configure your local MQTT to your local broker:

And the external MQTT to point to Artik Cloud. You also need to set the user/password to your device_id/token values.


Arduino SketchC/C++
#include "MQTT/MQTT.h"
#include <math.h>

boolean bVentStatus = false;            // true when vent is open; false when close
boolean bMotionDetected = false;        // true when motion has been detected
int countSinceMotionDetected = 0;       // counts since motion detected to send no motion event
int counter = 0;                        // loop count


#define OPEN_VENT_PIN           1
#define CLOSE_VENT_PIN          0
#define PIR_MOTION_SENSOR       4
#define RED_LED                 3
#define BUTTON_PIN              5
#define BOARD_LED               7

// MQTT Configuration and Callbacks

byte server[] = { 10, 0, 0, 45 };
void callback(char* topic, byte* payload, unsigned int length);
MQTT client(server, 1883, callback);

void callback(char* topic, byte* payload, unsigned int length) {
    char p[length + 1];
    memcpy(p, payload, length);
    p[length] = NULL;
    String message(p);

    if (message.equals("open")) {
    else if (message.equals("close")) {


void setup() {
    RGB.control(true);                // Enable on board Photon color LED

    pinMode(RED_LED, OUTPUT);
    pinMode(BOARD_LED, OUTPUT);
    pinMode(BUTTON_PIN, INPUT);

    digitalWrite(CLOSE_VENT_PIN, HIGH);
    digitalWrite(OPEN_VENT_PIN, HIGH);

    if (client.isConnected()) {
        client.subscribe("office-vent");    // subscribe to vent actions


void loop() {


    if (client.isConnected()) {



// handleMantualControl
// if button is pressed then toggle between opening and closing vent
// update on board led color to green when open and red when closed

void handleMantualControl() {
    int state = digitalRead(BUTTON_PIN);

    boolean action = false;
    if (state == HIGH) {
        digitalWrite(BOARD_LED, HIGH);
        if (!action) {
            if (bVentStatus) {
            } else {
        action = true;
    } else {
        digitalWrite(BOARD_LED, LOW); 
        action = false;

// handleTemp
// publish temperature to MQTT channel

void handleTemp() {
    // publish temp
    char tempBuffer[32];

    if (counter % 500 == 0) {
        float temp = readTemp();
        sprintf(tempBuffer,"%2.2f", temp);
        client.publish("office-vent-temp", tempBuffer);

// handleMotion
// When motion is detected then turn on led
// publish motion event to MQTT
// after period of inactivity send no motion event (false)

void handleMotion() {
    int motion = digitalRead(PIR_MOTION_SENSOR);
    if (motion == HIGH) {
        bMotionDetected = true;
    digitalWrite(RED_LED, motion); 
    if (counter % 10 == 0 && bMotionDetected) {
        client.publish("office-vent-motion", "true");
        bMotionDetected = false;
        countSinceMotionDetected = 0;
    if (countSinceMotionDetected % 2000 == 0) {
        client.publish("office-vent-motion", "false");

// openVent
// Open vent and send MQTT notification

void openVent() {
    if (!bVentStatus) {
        // set to green once opened
        RGB.color(0, 255, 0);
        digitalWrite(OPEN_VENT_PIN, LOW);               
        digitalWrite(OPEN_VENT_PIN, HIGH);
        bVentStatus = true;
        client.publish("office-vent-state", "open");

// closeVent
// Close vent and send MQTT notification

void closeVent() {
    if (bVentStatus) {
        // set to red once closed
        RGB.color(255, 0, 0);
        digitalWrite(CLOSE_VENT_PIN, LOW);               
        digitalWrite(CLOSE_VENT_PIN, HIGH);
        bVentStatus = false;
        client.publish("office-vent-state", "closed");

// readTemp
// Temperature calculation helper

float readTemp() {
    int a;
    float temperature;
    int B=3975;                  //B value of the thermistor
    float resistance;
    resistance=(float)(4300-a)*10000/a; //get the resistance of the sensor
    temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet
    return temperature;
Android App
Open Source in GitHub


Circuit Diagram
Screen%20shot%202016 10 01%20at%204.33.22%20pm
Vent Controller Schematics


Similar projects you might like

Smart Home - Smart Rules using ARTIK Cloud & Photon

Project tutorial by Raghavendra Ponuganti

  • 17 respects

Home/Hotel Monitoring System with Automated controls

Project tutorial by Muhammad Anas

  • 20 respects

Smart Personal Money Vault Monitoring System Based on IoT

Project tutorial by Salah Uddin

  • 1 comment
  • 13 respects

Smart Parking System

Project in progress by Md. Khairul Alam

  • 130 respects

Smart Garbage Monitoring System Using Arduino 101

Project tutorial by Technovation

  • 60 respects

The hydroMazing Smart Garden System

Project tutorial by Cory Potter

  • 148 respects
Add projectSign up / Login