Home Automation Kits with pcDuino and BLE4.0

From LinkSprite Playgound
Jump to: navigation, search



Before this article, there is post about DIY Smart home connecting through Wifi. Nowadays, the wearable devices such as smartbands and smart watch are extremely popular. So it’s time to talk about Bluetooth4.0, this article is all about how to DIY your own smart home using BLE4.0 Shield and BLE4.0 Bee as connection devices, pcduino as openhab server, Arduino as device.


Install openHAB

Install openHAB server software on pcDuino, get more detail form linksprite learn center:


or, download the image file below, then update ( install openh under “/opt/openhab” folder):

http://pan.baidu.com/s/1ntHtCyX?qq-pf-to=pcqq.c2c code: fh6c

For more detail about how to use BLE4.0 shield ( the usage of BLE4.0 Bee is the same as BLE4.0 Shield )


Test Code

We need to install python serial first before we can use serial from pcDuino3B by doing:


Code 1.jpg

Code 2.jpg

Code 3.jpg

Code 4.jpg

Hardware Perparation

pcduino3 x1

ArduinoUNO x1

BLE4.0 Bee x1

BLE4.0 Shield x1

Xbee Shield x1

Door Sensor x1

Linker LED x1

pcDuino3 x1

Test Execution

(1) install openhab on pcDuino and APP on mobile device:


(2) build a file “mqtt-BLE.py”, copy the code of python-mqtt in it, remember to edit IP address to the IP address that read now:

  • edit IP address based on distribution by pcDuino ( check by $ifconfig ), following is the location:

Test 1.jpg

(3) open “/home/ubuntu/c_environment/sample”, add a c file, copy the test code in it (need to add socket in Makefile of current directory, besides, edit IP address into ( the same as (2) ) ;

Test 2.jpg

(4) Connect the door sensor to D8 and GND of Arduino (set D8 as pull-up input, when the magnet of the door sensor approached, the IO level will drop ) , then connect linker LED to D13 and GND of Arduino, and install BLE4.0 Xbee on Arduino, and then download the test code of Arduino ( both switches of Xbee Shield should on the left side) :

Test 3.jpg

Test 4.jpg

(5) turn on pcDuino, run openhab, python MQTT, socket:

#turn on openhab:


$sudo ./start.sh

(if openhab mirror image has been build, add a self-start in it : sudo /opt/openhab/start.sh )

#run MQTT :

$cd/ home/ ubutu

$sudo python ./mqtt_publish.py

Test 5.jpg

#run socket ( this program should be run after python mqtt ):

$cd /home/ubuntu/c_enviroment/sample

$sudo ./socket

(6) the socket connection was build, after the program above start up.

(7) Now we can open the APP of mobile device, click settings, edit setting below :

Test 6.jpg

Edit IP address based on pcDuino, set up user name and code as following:

$cd /opt/openhab/configurations

$vim ./users.cfg

“test” is user name, “12345678” is code.

Test 7.jpg

(8) after setting, click “save” at right side, then it will be return to the main interface ( click button can control light) :

#when door is open, LED turn off :

Test 8.jpg

Test 9.jpg

#when door is close, LED will open :

Test 10.jpg

Test 11.jpg

Package List

  • 1 X Arduino UNO
  • 1 X Access control sensor
  • 1 X battery case
  • 1 X Dupont Line
  • 1 X Power Supply for pcDuino
  • 1 X microUSB Line
  • 1 X plastic box