Md. Khairul Alam
Published © MIT

Toilet Tracker (Powered by Walabot)

Toilet tracker can tell you either the toilet is clean or not. It also shows either it is engaged or not.

AdvancedFull instructions provided15 hours690
Toilet Tracker (Powered by Walabot)

Things used in this project

Story

Read more

Schematics

Configuration Screen

2018 09 20 22 00 12 iqwauui2cg

Screenshot of the App

2018 09 18 12 56 34 6haourjxzh

Screenshot of the App

2018 09 18 12 57 07 rscluvkw4l

Screenshot of the App

2018 09 18 13 21 25 6gic6ccwpu

Block Diagram

Block diagram shows the working of the system.
Block xoofklc6q1

Database configuration

Ubi1 baprhteojq

App development with App Inventor

Appd1 n5rstxczup

App development with App Inventor

Appd2 fqbilhkifs

App development with App Inventor

Appd3 lgeqow216c

Android application (.apk file)

Android source file (MIT App Inventor)

Code

Python Code for Raspberry Pi

Python
from __future__ import print_function # WalabotAPI works on both Python 2 an 3.
from sys import platform
from os import system
import time
from imp import load_source
from os.path import join
from ubidots import ApiClient

#Create an "API" object
api = ApiClient("656242bc2aebcb699c3a62cd339ab91b8dfaaecc") #put your own API key

#Create  "Variable" objects
clean_variable = api.get_variable("5ba1f819c03f972faa2d9366") #put your variable id here
engage_variable = api.get_variable("5ba1f80bc03f972f6f40314c")

#Write the value to your variable in Ubidots
#clean_variable.save_value({'value':1})
#engage_variable.save_value({'value':0})

if platform == 'win32':
	modulePath = join('C:/', 'Program Files', 'Walabot', 'WalabotSDK',
		'python', 'WalabotAPI.py')
elif platform.startswith('linux'):
    modulePath = join('/usr', 'share', 'walabot', 'python', 'WalabotAPI.py')     

wlbt = load_source('WalabotAPI', modulePath)
wlbt.Init()

def UpdateToiletStatus(targets):
    system('cls' if platform == 'win32' else 'clear')
    if targets:
        for i, target in enumerate(targets):
            print(target.zPosCm)
            if target.zPosCm>100 and target.zPosCm<180:
                print("Toilet is engaged.")
                engage_variable.save_value({'value':1}) #engaged variable 1 means it is engaged, android app reads in this way
            elif target.zPosCm>200 and target.zPosCm<210:
                print("Toilet is not engaged, not clean.")
                engage_variable.save_value({'value':0})
                clean_variable.save_value({'value':1}) #clean variable 1 means it is not clean
            else:
                print("Toilet is not engaged and clean.")
                engage_variable.save_value({'value':0})
                clean_variable.save_value({'value':0})
            break
    else:
        print('Not engaged and clean')
        clean_variable.save_value({'value':0})
        engage_variable.save_value({'value':0})

def SensorApp():
    #Change the "R value" to change how far you want your Walabot to look. 
    #It's default value is from 10 centimeters to 100 centimeters, 
    #but it can go as far as 1000 cm. 
    #SetArenaR values according to the distance between commode and walabot
    minInCm, maxInCm, resInCm = 30, 300, 3
    #Set the "Theta degrees," which is the width. Lines on the X/Y window become more flat as the arena narrows.
    minIndegrees, maxIndegrees, resIndegrees = -15, 15, 5
    #set the "Phi." which is the lengthwise width.
    minPhiInDegrees, maxPhiInDegrees, resPhiInDegrees = -30, 30, 5
	#Set the "threshold." This sets the resolution of the target. 
    #The lower the threshold, the better the Walabot's ability to detect weak targets. 
    #If you set it to 100, the walabot will only see very large targets 
    #In our case we want to detect stool, so it should be small
    threshold = 2
    # Set MTI mode
    mtiMode = False
    # Configure Walabot database install location (for windows)
    wlbt.SetSettingsFolder()
    # 1) Connect : Establish communication with walabot.
    wlbt.ConnectAny()
    # 2) Configure: Set scan profile and arena
    # Set Profile - to Sensor.
    wlbt.SetProfile(wlbt.PROF_SENSOR)
    # Setup arena - specify it by Cartesian coordinates.
    wlbt.SetArenaR(minInCm, maxInCm, resInCm)
    # Sets polar range and resolution of arena (parameters in degrees).
    wlbt.SetArenaTheta(minIndegrees, maxIndegrees, resIndegrees)
    # Sets azimuth range and resolution of arena.(parameters in degrees).
    wlbt.SetArenaPhi(minPhiInDegrees, maxPhiInDegrees, resPhiInDegrees)
	# Sets threshold.
    wlbt.SetThreshold(threshold)
    # Moving Target Identification: standard dynamic-imaging filter
    filterType = wlbt.FILTER_TYPE_MTI if mtiMode else wlbt.FILTER_TYPE_NONE
    wlbt.SetDynamicImageFilter(filterType)
    # 3) Start: Start the system in preparation for scanning.
    wlbt.Start()
    if not mtiMode: # if MTI mode is not set - start calibrartion
        # calibrates scanning to ignore or reduce the signals
        wlbt.StartCalibration()
        while wlbt.GetStatus()[0] == wlbt.STATUS_CALIBRATING:
            wlbt.Trigger()
    while True:
        appStatus, calibrationProcess = wlbt.GetStatus()
        # 5) Trigger: Scan(sense) according to profile and record signals
        # to be available for processing and retrieval.
        wlbt.Trigger()
        # 6) Get action: retrieve the last completed triggered recording
        targets = wlbt.GetSensorTargets()
        rasterImage, _, _, sliceDepth, power = wlbt.GetRawImageSlice()
        # PrintSensorTargets(targets)
        UpdateToiletStatus(targets)
        time.sleep(15)
    # 7) Stop and Disconnect.
    wlbt.Stop()
    wlbt.Disconnect()
    print('Terminate successfully')

if __name__ == '__main__':
    SensorApp()

Credits

Md. Khairul Alam

Md. Khairul Alam

28 projects • 250 followers
Engineer, developer, maker, and hacker.

Comments