Wearable Tech

Enter Your Electronics & Design Project for a chance to win a $100 Shopping Cart!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll

 

Before starting, I would like to thank tariq.ahmad and E14 team for providing me wear:it development kit which I ordered using the $100 Shopping Cart prize I got for IoT Magical Wand project.

 

Introduction

 

This is 'WatchAble' - a wearable watch capable of doing cool things! It has been developed using wear:it development kit from micro:bit. The name of this project is the combination of the words 'Watch' and 'capAble'. The wear:it development kit has a strap which helps us to wear the micro:bit inside a case as a watch. Though currently there is no option to display time which is the expected out of watch, I'll integrate it at a later point of time. For now, this is capable of performing the functionalities explained below.

 

Modes

 

There are various modes available which can be accessed by pressing Btn A + Btn B together in the micro:bit inside the wear:it development kit. The following are the various modes available for now,

  • Smart Home - In this mode, we can control the home appliances by the press of a button (Btn B) in the wear:it development kit! There is a receiving unit which executes the command sent wirelessly from wear:it development kit which is as follows: A micro:bit connected in the same radio group as wear:it development kit receives wirelessly the command containing a number corresponding to the relay and its respective state. This is in turn serially connected to Arduino Uno which updates the relay state according to the command received. Numbers from 1 to 6 are used to control three relays. Odd numbers are used to represent ON state and even for OFF state. For example, for relay 1, number 1 is used to turn it ON and number 2 is used to turn it OFF. By default when this mode is activated, number 1 appears on the 25 LED micro:bit display in the wear:it development kit. This can be incremented by pressing Btn A and then Btn B is used to send the command to the receiving unit.

 

  • Shake it - This feature is a hands free implementation of the above mode. When you shake it sends wirelessly the relay and its respective state. On the next shake followed by, it changes the state by itself. If the first shake turns ON the relay, the next shake turns in OFF. For simplicity, I have configured for a single relay. When there is a state sent either ON or OFF is displayed in the  wear:it development kit.

 

  • Light Level - In this mode, the light level of the surrounding is displayed.
  • Temperature - In this mode, we can have a view of the real time temperature of the surrounding.

 

 

Demo

 

The below video is the demo explaining the various modes and features of 'WatchAble'. Let you know your comments, suggestion in the comments section below.

 

 

Code

 

The following are the code that needs to be uploaded,

 

Watchable - wear:it kit's code

 

let loopExit = 0
let shakeVar = 0
let relayControl = 0
let modeSelect = 0
input.onButtonPressed(Button.AB, function () {
    if (modeSelect >= 2) {
        modeSelect = 0
        loopExit = 0
    } else {
        modeSelect += 1
        loopExit = 0
    }
})
input.onButtonPressed(Button.A, function () {
    if (modeSelect == 1) {
        if (relayControl >= 6) {
            relayControl = 1
        } else {
            relayControl += 1
        }
    }
})
function dispTemperature() {
    if (loopExit == 0) {
        basic.showString("TEMPERATURE")
        loopExit = 1
    }
    basic.showNumber(input.temperature())
}
input.onButtonPressed(Button.B, function () {
    radio.sendNumber(relayControl)
})
input.onGesture(Gesture.Shake, function () {
    if (shakeVar == 1) {
        shakeVar = 2
        radio.sendNumber(1)
        basic.showString("ON")
    } else {
        shakeVar = 1
        radio.sendNumber(2)
        basic.showString("OFF")
    }
})
function lightLevel() {
    if (loopExit == 0) {
        basic.showString("LIGHT LEVEL")
        loopExit = 1
    }
    basic.showNumber(input.lightLevel())
}
function controlRelay() {
    if (loopExit == 0) {
        basic.showString("SMART HOME")
        loopExit = 1
    }
    basic.showNumber(relayControl)
}
radio.setGroup(25)
modeSelect = 0
loopExit = 0
relayControl = 1
shakeVar = 1
basic.forever(function () {
    if (modeSelect == 0) {
        dispTemperature()
    } else if (modeSelect == 1) {
        controlRelay()
    } else if (modeSelect == 2) {
        lightLevel()
    } else {
   
    }


})

 

Receiver unit - micro:bti's code:

 

radio.onReceivedNumber(function (receivedNumber) {
    basic.showNumber(receivedNumber)
    serial.writeNumber(receivedNumber)
})
radio.setGroup(25)
serial.redirect(
SerialPin.P0,
SerialPin.P1,
BaudRate.BaudRate38400
)
basic.forever(function () {

})



 

Receiver unit - Arduino UNO's code:

 

int Relay1 = 10;
int Relay2 = 11;
int Relay3 = 5;
int Relay4 = 6;
int serialData = 0;


void setup() {
  // put your setup code here, to run once:
  pinMode(Relay1, OUTPUT);
  pinMode(Relay2, OUTPUT);
  pinMode(Relay3, OUTPUT);
  pinMode(Relay4, OUTPUT);
  Serial.begin(38400);
  digitalWrite(Relay1, HIGH);
  digitalWrite(Relay2, HIGH);
  digitalWrite(Relay3, HIGH);
  digitalWrite(Relay4, HIGH);
}


void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()>0){
     serialData = Serial.read();
     Serial.println(serialData);
     if (serialData == 49){
      digitalWrite(Relay1, LOW);
     }
     else if (serialData == 50){
      digitalWrite(Relay1, HIGH);
     }
     else if (serialData == 51){
      digitalWrite(Relay2, LOW);  
     }
     else if (serialData == 52){
      digitalWrite(Relay2, HIGH); 
     }
     else if (serialData == 53){
      digitalWrite(Relay3, LOW);
     }
     else if (serialData == 54){
      digitalWrite(Relay3, HIGH);
     }
     else if (serialData == 55){
      digitalWrite(Relay4, LOW);  
     }
     else if (serialData == 56){
      digitalWrite(Relay4, HIGH); 
     }
  }
}