Home delivery of meals is very popular these days, and technology is only fueling that trend. But nobody wants food that’s gone cold because the delivery guy forgot to ring the doorbell. Like any good engineer, Kenichi built a sensor-based solution designed to wirelessly alert him via Bluetooth that the food has arrived on his doorstep.
It’s well known that Singapore is a food paradise. I couldn’t agree more. But, it’s really not healthy to go out to eat every day. Homecooked food is always the best, but it can be extremely time consuming and not so economical for a household of two like ours. With that in mind, so, we order “Tingkat”—home delivered food services—for our dinner during the weekdays. It’s very economical and convenient and best of all, you can get food made for health-conscious customers.
For us, the delivery time varies between 3 PM and 7 PM. The problem is that delivery guy—due to his tight delivery schedule—often forgets to press the doorbell to alert us that the food is delivered. Sometimes, the food would be at the gate for more than a few hours. If not kept at a certain temperature, some foods can spoil easily—or a mischievous neighbor might just take it and have a free meal. I’m not saying that from our experience. We have nice neighbors! So, as any engineer would do, all this inspired me to create a solution. This article describes my Proximity Food Delivery Notifier system for solving this problem.
The basic idea is to have a system to alert us that our food has been delivered at our doorstep. The overall design (Figure 1) shows a fixed location with a hook for placing the food where a sensor will also be planted, a controller that will read and wirelessly relay that information to a receiver. In this case, a smartphone would work just fine. So, for the specific location, a sensor detects the existence of the food based on the proximity of an object. In this project, I have chosen an ultrasonic sensor as the proximity sensor because it provides some accuracy on the distance from the object. I found the Parallax PING sensor (Figure 2) to be particularly easy to implement because it provides information on distance in both centimeters and inches. Since I am using the Parallax Propeller for this project, the code that comes with the PING sensor is particularly helpful—providing distance readings in centimeters and inches.
I selected Bluetooth as the wireless protocol for this project. That’s mainly because the Bluetooth module I had on hand is a Class 2 and the distance between the delivered food and the receiver is also less than 10 meters. I used an HC-05 module (Figure 3) because I have quite a stock of these modules from my previous projects that I did back in 2013. Moreover, this module is very easy to implement because the PCB has castellation pads. These pads make it easy to either mount it as a SMT device on a PCB or insert to breadboard after soldering in the headers. Besides all that, this module is also very versatile in that configuration to it are all via the AT commands in a UART terminal. The module is also very widely used, so there are many articles and websites providing useful information about its configuration. And, the best part is you can get it for less than $5 (US).
As for the controller, the location for holding the delivered Tingkat food is very small and narrow, so I designed a small PCB that houses all the necessary components and the Parallax Propeller chip. This is the Propeller version 1 since the Propeller version 2 was just being released as of this writing. The Figure 4a schematic shows the basic components for the microcontroller, which includes the EEPROM and 5MHz crystal plus connectors, while the Figure 4b schematic shows the HC-05 Bluetooth module and an optional tactile switch for the microcontroller as user input. Finally, schematic Figure 4c is the power circuit with LDOs for 5V and 3.3V. Figure 5 shows the top and bottom image of the PCB. Figure 6 shows 3D model of the top and bottom enclosure for the PCB. I used a 3D printer to print out the enclosures and hold them together with 4 bolts and nuts. Figure 7 shows the final working unit that has been in use since July 2016. It hasn’t failed since.
The power requirements are 5V for the PING sensor and 3.3V for the other onboard components and peripherals. With that in mind, there is a simple power circuit to step-down the input voltage of 9V. Because the input voltage is rather low, LDOs (low dropout regulators) will work just fine providing low inefficiencies. However, you can use any Propeller-based boards available on the Parallax website, for example the Propeller QuickStart or the Propeller Project Board USB. I personally prefer the latter because it provides ample prototyping space for mounting other components.
On the receiver part, I used an Android phone. Using the MIT App Inventor 2 tool , which is free, I could rapidly develop an app using the code blocks. Figure 8 shows the Designer view of the MIT App Inventor 2 and Figure 9 shows the Blocks Editor View. If you are new to MIT App Inventor, I encourage you to look at some of the tutorials on their resource page. This will give you a sense of what tools will be available for you as you start coding using their blocks. Coming back to my app, as I like to keep it simple, I only used less than 10 components. So, that’s all on the main building blocks for this system. Now, let me go deeper into each of the sub-system.
The programming language I used for the controller was SPIN by Parallax for the Propeller 1 microcontroller. My code for this project available on the Circuit Cellar article code and files download webpage. Even though the “.spin” files are in a plain-text format, you will need a compiler to compile into bytecode. I usually use the Propeller Tools for Windows by Parallax. You can download and install the Propeller Tools software for Windows from Parallax’s website . If you are not using a Microsoft Windows machine, you can also download PropellerIDE, which runs on Linux/Ubuntu, OS X and Windows.
The main file is #TingkatR1v1.spin. In a normal .spin file, there are five major sections: CON (Constant blocks), OBJ (Object blocks), VAR (Variable blocks), PUB (Public method blocks) and PRI (Private method blocks). For this project, I don’t need the VAR because I only needed the local variables within the PUB Main section. In the CON section, I declared the required
_clkmode which is the application-defined clock mode and since the board uses a standard 5MHz crystal, the
_xinfreq which is the application-defined external clock frequency was declared as
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
Next, we declare the I/O pin from the ultrasonic sensor’s connection to the Propeller. The connection is on pin 3.
_ping = 3
The final declaration would be for the Bluetooth module’s connection to the Propeller.
BTComm_Tx = 26 ‘’(Transmit from Bluetooth Module)
BTComm_Rx = 25 ‘’(Receive from Bluetooth Module)
BTComm_Baud = 19_200 ‘’Baudrate
The next section, OBJ, we will need two object files. These are also downloadable from Parallax’s OBEX website . Most of these objects were written by members of the Parallax community. I, myself, have contributed a few of them.
Ultra : “Ping.spin” ‘’Connects to ultrasonic sensor
BTM : “FullDuplexSerialExt.spin” ‘’Using UART to communicate with HC-05
The PUB will hold the Main section which are the main codes. Notice the “| scannedObj”? That is the local 4-bytes variable within the Main section.
PUB Main | scannedObj
BTM.Start(BTComm_Tx, BTComm_Rx, 0, BTComm_Baud) ‘’Initialises the Bluetooth
Pause(500) ‘’Pause for 500 ms
scannedObj := Ultra.Centimeters(_ping) ‘’Get the measurement
BTM.Dec(scannedObj) ‘’Sends out to the Bluetooth module to receiver
Pause(2200) ‘’Pause for 2.2 secs
Finally, for the PRI section I usually like to add this function to most my projects because it converts the system clock into milliseconds which becomes very convenient to use throughout the code. It was initially written by a member of the Parallax community, Jon McPhalen.
Depending on your personal needs, you can make the necessary changes or add additional sensors for other locations. Say if you have 2 ultrasonic sensors, you will then declare two objects like this:
_ping1 = 3 ‘’Assigning sensor 1’s I/O pin to pin 3 of MCU
_ping2 = 4 ‘’Assigning sensor 2’s I/O pin to pin 4 of MCU
Ultra : “Ping.spin”
And in your PUB Main section, use them like this:
scannedObj1 := Ultra.Centimeters(_ping1)
scannedObj2 := Ultra.Centimeters(_ping2)
Now onto the receiver unit. I used Google Chrome as my default browser. Navigating to appinventor.mit.edu , you will see the home page of MIT App Inventor 2. Click on the “Create App!” button and it will direct you to the login and account creation page. For me, I logged in using my Google account. You will need to create one if you do not have a Google account. Next, it will direct you to your project listings. If you are new to MIT App Inventor, you won’t see any project listings yet. So, you could either create a new project or load my “.aia” project file and modify from there. Just to give you a brief introduction to MIT App Inventor, I will show you how to add components from the Palette.
In the Designer interface, you will be able to drag and drop the types of user interface, layout, sensors and so forth onto the main screen called Screen1 by default. This is what you will see when you first launch the app on your phone. You will be able to add multiple screens depending on your needs. First, I selected the Bluetooth client component from the Connectivity Palette and dropped it onto the Viewer. This is needed to connect to our HC-05 Bluetooth module on the controller.
Next is the Text-to-Speech component. This will inform us that the “food is here” via the text-to-speech feature. I have added two Clock components which are timers. Clock1 is used to check if there are any data received in the Bluetooth client in the app. Clock2 is used to define the duration to announce “Food is here” when food was placed in the assigned location. Next, I’ll show you some screen captures as the app is launched and explain the process flow. Hopefully this will help you understand the code in the Blocks Editor.
USING THE APP
Once you launch the app as shown in Figure 10, the first thing is to connect the app to your Bluetooth device. There is a button that is labelled “Connect to Tingkat Checker.” This allows the app to bring up the list of Bluetooth devices already paired with your phone. Therefore, you will need to ensure that the Bluetooth module (HC-05) is already paired with your phone before it can be listed. If you already have paired, upon clicking the button, it will bring up the list of devices as shown in Figure 11. Since I was using a Bluetooth module from my previous project, it was renamed as TellMe instead of the default HC-05.
If you are going to use the HC-05 module, please look at its datasheet under “Set/inquire device’s name” section for this feature. Back to the list of Bluetooth devices, once I tapped on my Bluetooth device, the button will be changed to “Connected” as shown in Figure 12. You will notice the text box at the bottom that initially showed “Debug Log Box” has changed to “373.” This “373” is the reading that was received from the controller which means there is 373cm between the ultrasonic sensor and the object.
Since the datasheet for the ultrasonic sensor states that the non-contact distance measurements are from about 2cm (0.8″) to 3 meters (3.3 yards), that means there is nothing being placed on the hook (Figure 13). However, the debug textbox was just to show the actual readings coming from the controller since the retrieval was timed at every 1,000ms (1 second) by Clock1. Clock2 is assigned to activate every 10,000 ms (10 seconds). It will first transfer the value received from the controller and place it into the TextBox1 then perform a verification to see if it is below the value 10 (meaning 10cm). However, when food is placed on the hook as shown in Figure 14, the value shows 5cm as shown in Figure 15. This will then trigger the Text-to-Speech component to say “Food is here” every 10 seconds until someone removes the food from the hook!
On the Circuit Cellar article code and files webpage, I have provided the code, 3D models for the enclosure in .STL format and the Gerber files with the bills of materials if you wish to produce the same PCB as mine. My device has been in operation since July 2016 and it is still in good working condition today. By using this simple concept, you can also create your own proximity sensors around your house as home surveillance or a door response system to do something when someone is at your door. The possibilities are endless. So, create your very own mobile notification system today!
References: MIT App Inventor 2
Massachusetts institute of Technology | www.appinventor.mit.edu
Parallax Inc. | www.parallax.com
Guangzhou HC Information Technology Co., Ltd | www.wavesen.com
PUBLISHED IN CIRCUIT CELLAR MAGAZINE • MAY 2020 #358 – Get a PDF of the issueSponsor this Article