Arduino Project Hub
Project tutorial

SMART CUBE: A New Way to Control Your Home © GPL3+

Discover a new way to interact with your smart home thanks to Arduino 101: tilt and shake the cube to control your devices via Bluetooth!

  • 102 views
  • 0 comments
  • 3 respects

Components and supplies

About this project

What is SMART CUBE?

Smart Cube is a controller for your Smart Home devices.

Nowadays managing in a smarter way all the devices in our homes is becoming an exigence. We need something simple and intuitive to use. Smart Cube could be a solution: it’s a portable device that contains an Arduino 101 board and some sensors that communicate with the appliances and the actuators in your Smart Home.

The innovation of this remote controller is related with the innovation of Arduino 101 board. It uses Bluetooth (BLE) to control lights, temperature and your tv and you can also synchronize it with your smartphone. But the major innovation is the way you interact with Smart Cube with your gesture using the gyroscope and the accelerometer. The cube has 6 faces and each one control a particular function. The function you want to use is detected thanks to the gyroscope that recognize the upper face. For example you can open the lights of the room in which you are just by positioning the cube with the “light face” in the upper position. If you want to switch off the light you just need to shake the cube.

If a face is UP and it doesn’t move for more than 2 seconds it is activated the related function. This delay is made so that you can have the time to rotate and interact with the cube to find the face you need without activating accidentally other functions. When you shake the cube for more than 2 seconds, the last activated function is closed.

This project aims to help you to build a smart controller. This device need a receiver (smart centraline in the picture) that interpret the data and manage the functions of your smart home. The main output of the cube is a BLE signal that could be used in many ways: for example you can connect the cube with a smartphone app (or make your own), or you can build a station with another Arduino that collect the BLE data and directly controls the appliances of your home. Because of the variety of cases, this part depends on your exigence. In this guide we will see how to build a smart cube and you'll learn how to personalize it.

Functions:

The structure of the code is easy to personalize (we analyze the code later) so that you can decide which functions to control. These are the functions that I decided to control:

LIGHTS: This face in UP position open the lights of the room in which you are. If you shake the cube the lights switch off and a yellow led in this face is activated so you can find the cube in the darkness. The communication with your lamps is made by the BLE of the 101 board.

TEMPERATURE: This face UP activate (via BLE) the air conditioning if it’s hot or the heating if it’s cold. It detects the temperature using a thermal sensor and open a blue led if the conditioner is on (snow flake) or a red one if the heating is activated (sun).

TIMER: This face UP start a timer that you can see on the LCD display. There is a buzzer that work as an alarm when the countdown is finished. If you shake you stop the timer and you can see the remaining time. When the countdown ends the color of the LCD change from blue to red and the buzzer make three sounds.

TV: This face UP open the TV. The cube become a remote controller for your TV. There is a button panel with numbers that is activated only if this face is UP so to avoid accidental touches. The number you push is send via BLE to the central controller that is connected to your TV. Shaking the cube you close the TV.

SOUND: This face UP activate a led whose brightness is based on the noise level of the room. The noise is detected thanks to a sound sensor. If you shake the cube you close this function. (If you want you can activate your personal function clapping your hands).

OFF face: If you don't shake the cube this face is like a neutral position in which nothing is changed. If you want to close everything position the cube with the OFF face UP and shake it. This gesture is like the home button on you smartphone that you press if you want to exit quickly. There is a red led so that you can find the cube if it’s dark.

Differences from the concept:

The original plan was to use also IR communication to connect your TV directly to the cube. Because the Arduino 101 don't support (for now) the library that manage the IR signals I decided to send the information via BLE to a station that can manage this library (like Arduino UNO). Because of this problem I have removed the radio function (very similar to TV face), replacing it with a sound sensor face. This face could be used to recognize a loud noise (like hand clapping) to activate something. The biggest change is in the material of the cube. Initially I though to build it with a 3D printer but then I decided to use a laser cutter. In this way is easier to substitute a face if you want to change a function. For example you can remove the timer face and change it with a face that automatically fill your cat's bowl. Being modular you don't need to re-build the entire structure!

Let's build it:

Follow this instructions to build your own smart cube. We'll start from the hardware, assembling the electronics components first and then the laser cut body of the cube made of MDF. After this operation I'll explain how the code works and how you can personalize it. After you have uploaded the code on your Arduino 101 you can download the app to see the BLE output of the cube or connect it directly with your smart home!

Hardware - electronics:

Let's start form your Arduino 101. This is the fritzing scheme to follow:

Mount the Grove base shield on your board and start with the connections.

Keypad: you have to connect the wires in order to the pins: 10, 8, 7, 6, 5, 4, 2.

LED connections:

First of all we have to prepare the leds:

- connect the long leg of the led (anode) to a 220 ohm resistance and then to a red wire (this is the cable to connect to the pin)

- connect the short leg (cathode) to a white wire (this will go to the gnd)

- solder the parts and cover them with electrical tape

- connect all the white cables to a single white cable (this will go to the gnd) and solder them all together

Now connect the red wires to your Arduino: GREEN led to pin 9, YELLOW led to pin 11, RED led to pin 12, BLUE led to pin 13 and the last RED to pin A2.

Grove sensors:

Connect the grove sensors to the shield (see scheme on attachments).

Buzzer to D3, LCD RGB to I2C, Temperature sensor to A0, Sound sensor to A1.

Ok, now we have connected all the electric parts. Now you need the case.

Hardware - box

You can download the sketch of the cube to cut with laser. The red lines in the sketch are the symbols of the faces, just engrave them. The black lines should be cut. The internal dimension of the cube is 9 cm. The sketch is ok if you use a 3mm material, if you use a different thickness you should modify it (you can use this website: http://www.makercase.com/).

The material I choose is MDF (Medium Density Fiber) but you can use what you want.

Here are some pictures of the laser cut:

Now we have to assemble it.

I glued some pieces of cardboard to make thickness for the led. In this way they will be aligned with the surface.

Now we mount the keypad. Insert it in the hole and remove the adhesive film, then reconnect the pins.

Now the RGB LCD. This fit perfectly the hole.

Let's prepare the battery connector:

I have cut an old transformer plug and connected it to a battery clip. In this way we save space inside the box.

At this point thats what you should have:

Now you just need to connect the battery, upload the code and close the cube!

TIP: fix the board and the battery with the case so that when you shake the cube they will be stable.

Code

You can find the code in the attachments. Upload it in your board with the Arduino IDE (remember to update your software for Arduino 101 compatibility).

I have commented almost every line of the code to make it more understandable that I can. Don't be afraid of the 500+ lines, the structure it's not so complicate.

At the beginning there are the libraries and all the variables declaration.

In this part there is also the definition of BLE services and characteristic. I used Automation IO service. I used the Digital characteristic for lights and temperature (this use 2 bit , so 4 possible cases to codify) and the Analog for TV (to send all the codes of the keypad).

Then the setup. This pat is executed only one time at the beginning. Here we initialize the components as inputs or outputs and initialize the BLE and the gyro of the 101 board.

The main part is the loop. It is divided in four parts:

  • 2 The second part we activate a face only if it is in the up position for more than two seconds. We use the millis function to count the time. When the position change it memorize the millis value and if the orientation remain the same, after an interval (2 sec), we enter in an if-zone where the selected face became true (for the 4th part).
  • 3 The third part is activated only if the cube is shaked with a certain intensity and for more than 2 seconds. The last activated face function is closed and the face is set as false. If the face is false can't enter in the 4th part.
  • 4 The fourth part is only for true faces. Here there is the core of the functions of the smart cube. In this part are constantly executed only the faces that are true in loop.

You can modify the face functions with some modifications of the code. The main structure should be as described. You can change the part inside the if conditions of every face.

if (face2 == true) { // TEMPERATURE face  
 
//START CHANGING HERE
 
 digitalWrite (LEDOFF, LOW); // if this face is true the OFF face led is LOW  
 if (central.connected() == true) { // if the cube is BLE connected   
  // read temperature value  
  int val = analogRead(pinTemp); // get analog value  
  resistance=(float)(1023-val)*10000/val; // get resistance  
  temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;  
  // calculate temperature  
  //conditions of activation  
  if (temperature > tooHot) { // activate air conditioning  
   digitalWrite(LEDhot, LOW); // close heating led  
   digitalWrite(LEDcold, HIGH); // open air conditioner led  
   termoChar.setValue(1); // set via BLE the condition 1 = cold on - hot off  
  }  
  if (temperature < tooCold) { // activate heating  
   digitalWrite(LEDhot, HIGH);  
   digitalWrite(LEDcold, LOW);  
   termoChar.setValue(2); // 2 = cold off - hot on    
  }  
  if (temperature > tooCold && temperature < tooHot) { 
   // ideal temperature: nothing is activated  
   digitalWrite(LEDhot, LOW);  
   digitalWrite(LEDcold, LOW);  
   termoChar.setValue(0); // 0 = cold off - hot off  
  }  
 }  
 
//END HERE
 
}

You have to code the "true" part (as in the previous code) and also the "false" part when the cube is shaked:

// TEMPERATURE deactivation  
if (lastFUNCTION == 2) { // TEMPERATURE face  
 
 //START CHANGING HERE
 
 // if a central is connected to peripheral:  
 if (central.connected() == true) {  
  digitalWrite(LEDhot, LOW); // close temperature red led   
  digitalWrite(LEDcold, LOW); // close temperature blue led  
  termoChar.setValue(0); // temperature BLE signal: 0 = cold off - hot off  
 
 //END HERE
 
 }  
Serial.println("TEMPERATURE false - CLOSE");  
face2 = false; // TEMPERATURE face became false  
}

Remember to set the face as false when you shake it.

App:

To see the cube BLE outputs you can download this app: nRF Connect

https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp&hl=it

When you open it, just search for devices and connect with "smartcubesketch". Then you will see three "Automation IO" tabs, click on them and push the continuous data collector.

It is important to connect the cube because some functions (lights, temperature and tv) are executed only if the cube is connected.

How it works: VIDEO

Upload the code, insert the battery, close the box and...

...now you have a SMART CUBE!

I made a video to show you all the functions of the cube and how to use it.

Conclusions

This project is only the first step to a smart home. My purpose was to use the Arduino 101 board potentiality to create something new. I think that the accelerometer and gyroscope give to the board new opportunities in terms of mobility. With the BLE, in addition of being portable, is also easy to connect.

This is the fist time that I realize concretely one of my projects (I mean with a working prototype). It was hard and there were some difficulties during the road but at the end I've learn a lot and I'm happy with the result. I hope that also everyone who read this guide could learn something from my work and also modify this project on their needs. I'm sorry for my bad english but I hope that the images could help you.

In the future of this project I expect to create the centraline that is like the bridge between the smart cube and the actuators (lights, temperature, tv...). This centraline will receive the BLE signal from the cube and use this information to do smart things in your home.

I'm very happy to have the opportunity to use Arduino 101 and the Grove kit (the kit is very simple and fast for prototyping).

I hope that using the board in this way could be an inspiration for your project. You can personalize it as you want: I'm curious to see what functions will you create and in what different context you will use it!

Maybe this is not a revolution but it's a new way to interact with your home.

Hope you like this tutorial.

Now it's your turn: put your hands on the cube and hack it!

SMART CUBE: a new way to control your home!

Custom parts and enclosures

SMART CUBE box - Laser Cut
This is the file (.dxf) that you can upload on your laser cutter. I used a medium density fiberboard (MDF) of 3mm. Cut the black lines and engrave red lines. Important: if your material thickness is different you have to modify this sketch.
smart_cube_8sVCflFmhM.dxf
SMART CUBE box in .pdf
The same file of the box but in a different format: .pdf

Schematics

SMART CUBE - Fritzing schematics
This is a .jpeg of the Fritzing scheme (yellow wires are connected to Grove components)
Smart cube bb tfknaokws3
SMART CUBE - Grove Base Shield connections
This is a scheme of the connections in the Grove Shield
_cI0IwUsPVZ.Base shield connections

Comments

Similar projects you might like

Arduino 101 BLE App

Project in progress by Alexis Santiago Allende

  • 1,762 views
  • 12 comments
  • 22 respects

Arduino Digital Clock Version 2

Project showcase by John Wafik William

  • 450 views
  • 0 comments
  • 7 respects

FM radio

Project tutorial by Patrick Müller

  • 7,981 views
  • 2 comments
  • 36 respects

Aquariumatic

Project in progress by Craig Hissett

  • 7,164 views
  • 2 comments
  • 17 respects

Avoid Injuries with Smart Backpack

Project tutorial by Chathuranga Liyanage

  • 955 views
  • 2 comments
  • 12 respects

Arduino Temperature Control

Project tutorial by Team pandhoit

  • 937 views
  • 3 comments
  • 9 respects
Add projectSign up / Login