EdOliverVictor AltamiranoAlejandro Sanchez
Published © MIT

TechCare: Baby Safe

TechCare Baby Safe, an IoT solution to improve security and access to neonates, with face recognition using Thundercomm's AI kit.

AdvancedFull instructions provided20 hours1,311
TechCare: Baby Safe

Things used in this project

Hardware components

Thundercomm AI Kit
ThunderSoft Thundercomm AI Kit
×1
Solenoid Electrolock
×1
Darlington High Power Transistor
Darlington High Power Transistor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Pocket Solder- 60/40 Rosin Core 0.031" diameter
Pocket Solder- 60/40 Rosin Core 0.031" diameter
×1
Custom PCB
Custom PCB
×1
Raspberry Pi Zero
Raspberry Pi Zero
×1

Software apps and online services

Thundercomm SDK
Watson
IBM Watson
BlueMix
IBM BlueMix
Raspbian
Raspberry Pi Raspbian
Android Studio
Android Studio
OpenCV
OpenCV

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Flowchart

Schematics

Tech Care

The full solution

Code

Arduino software

C/C++
code for the smart lock servo.
/*
 Controlling a servo position using a potentiometer (variable resistor)
 by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
 modified on 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Knob
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.attach(10);  // attaches the servo on pin 9 to the servo objec 
  myservo.write(160); 
}

void loop() 
{
  if(analogRead(A0)>500)
  {
    delay(100);
    if(analogRead(A0)>500)
    {
      Serial.println("ON");
      myservo.write(20); 
      delay(10000);
      Serial.println("OFF");
      myservo.write(160);  
    }            
  }
  else
  {
    // Nothing
  }
   
                      
}

Raspberry pi code

Python
MQTT python code for IBM watson IoT.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import ibmiotf.application
import json
import RPi.GPIO as GPIO
import time

i=0

try:
  options = {
    "org": "YOUR_ORG",
    "id": "ANY_ID",
    "auth-method": "apikey",
    "auth-key": "YOUR_KEY",
    "auth-token": "YOUR_TOKEN",
    "clean-session": 1
  }
  clients = ibmiotf.application.Client(options)
except ibmiotf.ConnectionException  as e:
    ...

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
GPIO.output(18,GPIO.LOW)

def myEventCallback(event):
      str = "%s event '%s' received from device [%s]: %s"
      print(str % (event.format, event.event, event.device, json.dumps(event.data)))
      if (event.event == "open" and event.device =="Tech:001"):
          print("YES")
          GPIO.output(18,GPIO.HIGH)
          time.sleep(5)
          GPIO.output(18,GPIO.LOW) 

clients.connect()
clients.deviceEventCallback = myEventCallback
clients.subscribeToDeviceEvents()
while 1:
    i=i

Raspberry pi second code

Python
Raspberry pi code for the numerical keyboard.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from threading import Thread
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
GPIO.output(18,GPIO.LOW)
code = "1234"

def runA():
    while True:
        codein = input("Introduce the code:")
        if(code == codein):
            print("YES")
            GPIO.output(18,GPIO.HIGH)
            time.sleep(10)
            GPIO.output(18,GPIO.LOW)
        else:
            print("NO")
            GPIO.output(18,GPIO.LOW)
            
if __name__ == "__main__":
    t1 = Thread(target = runA)
    t1.setDaemon(True)
    t1.start()
    while True:
        pass

Android Studio basic code for Mqtt connectivity and camera via Open CV

Java
follow the tutorial and use this in your Main.java file in Android studio,
package com.example.YOU.YOURFILE;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import org.eclipse.paho.android.service.MqttAndroidClient;
import org.eclipse.paho.client.mqttv3.IMqttActionListener;
import org.eclipse.paho.client.mqttv3.IMqttToken;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.JavaCameraView;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.CvType;
import org.opencv.core.Mat;

import java.io.UnsupportedEncodingException;

public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {

    static String MQTTHOST = "tcp://your broker:PORT" ;
    static String USERNAME= "your username credentials";
    static String PASSWORD= "Your password";
    String topicStr= "Your topic";

    MqttAndroidClient client;

    CameraBridgeViewBase cameraBridgeViewBase;

    Mat mat1,mat2,mat3;
    BaseLoaderCallback baseLoaderCallback;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //MQTT
        String clientId = MqttClient.generateClientId();
        client = new MqttAndroidClient(this.getApplicationContext(), MQTTHOST, clientId);

        MqttConnectOptions options = new MqttConnectOptions();
        options.setUserName(USERNAME);
        options.setPassword(PASSWORD.toCharArray());


        try {
            IMqttToken token = client.connect(options);
            token.setActionCallback(new IMqttActionListener() {
                @Override
                public void onSuccess(IMqttToken asyncActionToken) {
                    // We are connected
                 //   Log.d(TAG, "onSuccess");
                    Toast.makeText(MainActivity.this, "connected", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
                    // Something went wrong e.g. connection timeout or firewall problems
                  //  Log.d(TAG, "onFailure");
                    Toast.makeText(MainActivity.this, "connection failed", Toast.LENGTH_SHORT).show();

                }
            });
        } catch (MqttException e) {
            e.printStackTrace();
        }


        //video
        cameraBridgeViewBase = (JavaCameraView)findViewById(R.id.myCameraView);
        cameraBridgeViewBase.setVisibility(SurfaceView.VISIBLE);
        cameraBridgeViewBase.setCvCameraViewListener(this);

        baseLoaderCallback = new BaseLoaderCallback(this) {
            @Override
            public void onManagerConnected(int status) {
                super.onManagerConnected(status);
                switch(status){
                    case BaseLoaderCallback.SUCCESS:
                        cameraBridgeViewBase.enableView();
                        break;
                    default:
                        super.onManagerConnected(status);
                        break;

                }
            }
        };


    }
    @Override
    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
        mat1 = inputFrame.rgba();

        return mat1;
    }

    @Override
    public void onCameraViewStopped() {
        mat1.release();
        mat2.release();
        mat3.release();

    }

    @Override
    public void onCameraViewStarted(int width, int height) {
        mat1=new Mat(width,height,CvType.CV_8UC4);
        mat2=new Mat(width,height,CvType.CV_8UC4);
        mat3=new Mat(width,height,CvType.CV_8UC4);

    }

    @Override
    protected void onPause() {
        super.onPause();
        if(cameraBridgeViewBase!=null) {
            cameraBridgeViewBase.disableView();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(!OpenCVLoader.initDebug()){
            Toast.makeText(getApplicationContext(), "there is a problem in open cv", Toast.LENGTH_SHORT).show();
        }
        else{
            baseLoaderCallback.onManagerConnected(BaseLoaderCallback.SUCCESS);

        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(cameraBridgeViewBase!=null) {
            cameraBridgeViewBase.disableView();
        }
    }
    public void pub(View v){
        String topic = topicStr;
        String message = "Your Message";

        try {

            client.publish(topic, message.getBytes(),0,false);
        } catch (MqttException e) {
            e.printStackTrace();
        }
    }
}

Android Studio Manifest File basic functionality

Java
Manifest file should be like this one
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.YOU.YOURFILE">
    
    <uses-permission android:name="android.permission.CAMERA"></uses-permission>
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name="org.eclipse.paho.android.service.MqttService" >
        </service>
    </application>

</manifest>

Github repo

To be concluded.

Credits

EdOliver

EdOliver

37 projects • 73 followers
Engineer, Scientist, Maker. Entrepreneur and Futurist.
Victor Altamirano

Victor Altamirano

25 projects • 81 followers
I am a Biomedical engineer who likes to develop hardware and software solutions.
Alejandro Sanchez

Alejandro Sanchez

8 projects • 19 followers
I am a biomedical engineer working at Boston Scientific as a service engineer

Comments