Product Identifying & Sorting Robot

In this demo, we will showcase how QikEasy’s Virtual Wireless Sensor feature can be use together with your mobile phone to trigger certain specific actions to be performed by your LEGO robot.  Specifically, for our project, we use the Shortcuts app on iPhone to perform barcode scan to differentiate between different kinds of soft drinks, and then ask our robot to transport the drinks to their designated locations.

 

 

Architectural Overview

 

Here’s the flow chart to show the relevant components and how data flows between them:

 

 

Required Materials

 

To follow this tutorial, you must prepare these before starting the project:

 

    • Your LEGO Spike Prime or Robot Inventor system.

 

    • An iPhone

 

    • Your QikEasy Adapter must be setup to run in Virtual Wireless Sensor mode.  See instructions on how to set that up here.

 

    • Some products with barcode on them for your iPhone to identify and for the LEGO car to push to the designated location. (Tip: Products with bigger barcode strips tend to be easier for iPhone or iPad to scan.)

 

Both the iPhone and the QikEasy Adapter should be connected to the same Wifi network.

Building your LEGO Robot

 

You can build your LEGO base robot car customized to your personal preference.  Add U Shape railings to the front of your car such that it is wide and big enough to push the products it is going to push.

 

To use the example code we provided, the two driving motors should be connected to Ports A & B.  And the QikEasy Adapter should be connected to Port C.

 

 

 

 

The iPhone Shortcuts App Script

 

Shortcuts is a free app included in any iOS device.  Usage of Shortcuts app is kind of similar to the Spike Prime Word Block interface where user will select settings for each functional block and join them together.

 

In our script, we start by performing a Barcode scan to read the code for the program.  Once barcode of the product is read, depending the product read, we will issue a different HTTP request to our Virtual Wireless Sensor.  In our example:

 

    • Coca Cola has barcode of 4890008100309
    • Tonic Water has barcode of 4890008403363

 

If the scanned product is Coca Cola, we will send a “Force” raw value of 100 to the Virtual force Sensor.  (We could use any sensor for our programming.  In this example, we have chosen to use a Virtual Sensor.)

 

If the scanned product is Tonic Water, we will send a “Force” raw value of 10 to the Virtual force Sensor.  (We could use any sensor for our programming.  In this example, we have chosen to use a Virtual Sensor.)

 

Note that after the HTTP GET request to set the virtual sensor is sent, we wait 2 seconds to make sure the LEGO hub is able to detect the value, and then we must return the virtual sensor value back to zero so that the robot will not continuously perform the triggered action.

 

After everything finished, the script will run itself again so that the iPhone is ready to scan another product item.

 

 

Program running on LEGO Hub

 

On the LEGO robot, there will be a program running to receive commands from the iPhone sent in the form of force sensor force values.

 

 

The Word Block Program

 

The logic for our Word Block program is very simple:

 

    • [For the Tonic Water]  If the Virtual Force Sensor is reading a force of 1 (i.e. same as raw value of 10), the car should move forward and turn left till the “yaw” gyro is turned 60 degrees.  After that, it should reverse and go back to its original position.
    • [For the Coca Cola]  If the Virtual Force Sensor is reading a force of 10 (i.e. same as raw value of 100), the car should move forward and turn right till the “yaw” gyro is turned 60 degrees.  After that, it should reverse and go back to its original position.

 

As noted above, we use the hub’s “yaw” gyro to determine when a turn is finished when the turn is over 60 degrees.

 

Special Note:  Because the program expect that a force sensor will provide data about the scanned product, when you run the program, make sure you preset the virtual sensor type to “Force Sensor”.  You may do so by going to a URL like the following.  Don’t forget to change the IP address to the IP address of your virtual sensor.

 

http://192.168.11.135/set?t=f&f=0

 

 

 

 

Challenge Extensions

 

These are some of our suggestions for extending this project:

 

  • Program the same script on an Android mobile phone.   On the Android platform, there are FREE apps that provide equivalent function to Shortcuts.  Two of such apps are: Automate and MacroDroid.  Challenge yourself and build this project using an Android phone.

 

  • Improve the Product Pushing Path of the LEGO car.  Depending on the weight of the product, our current way of pushing the product to the designated area doesn’t work very well.  Extra weights tend to make the turning radius to become bigger.  A better way of pushing the product is that the car will push the product straight and the car should back up, and then it should go around to the side of the product to push straight in a perpendicular path.  This would result in the product moving in sharp 90 degree angle.

 

  • Instead pushing the product to the designated area, we could implement a ramp so that the product can be rolled down, and reach one of the designated buckets.  On the ramp for rolling product down, we would have a swivel path changer , a  mechanical device that could be flip to one side of the other to divert the product rolling down the ramp to the appropriate bucket.

 

Conclusion

 

QikEasy Adapter’s Virtual Wireless Sensor provides boundless integration opportunities with all sorts of data sources available over the network.  This project presents only one of its possible use.  You may visit our Virtual Wireless Sensor documentation page for more fun and interesting ideas.