|Software apps and online services:|
|Hand tools and fabrication machines:|
In this project we put together a handheld Utrasonic distance measuring device using the mcModule120 and a US-100 ultrasonic sensor! This is an example of using the ultra-low power nature of the mcThings platform to quickly and easily connect another sensor to create a cool IoT device/solution.
You can easily do this too into whatever enclosure you wish!
In a previous example, we had created a device that used the mcModule120 with an ultrasonic sensor to measure 'fullness' levels within a garbage can.
Using this example to create your own version, you can build tons of feasible and truly realistic IoT solutions:
- Smart City - Imagine smart Garbage/Recycling/Bin/Container levels relayed back to a city control/dispatch center to increase efficiencies with vehicle routing, statistics, etc
- Large Facilities - Large facilities with hundreds of bins (like amusement parks, airports, hospitals, universities/colleges, etc)
- Agriculture - Imagine smart water troughs/feed/silo bins for livestock for real-time alerts on levels, etc
- Parking/Object detection - Imagine an easy to deploy object and distance sensor system for all sorts of different use-cases
- Fun Stuff - How quickly are your tomato plants growing? How high your cat can jump? Guess your height? etc.
The mcThings platform includes 2 main components: mcModules and mcGateways. A powered and connected mcGateway creates the mcAir network (up to 200m range under optimal conditions) and bridges the information between the mcModules (within range) to and from the Internet. Using the IDE (mcStudio) and mcScript (ultra-low power programming language - a subset of VB.NET) allows you to wirelessly connect, debug and program modules with your customized scripts.
Note: You also require an mcDongle to complete firmware updates on the modules/devices and gateways! We recommend looking at the mcModule120 Dev kit which includes everything you need to get going!
Just like our other project, we soldered the ultrasonic sensor to the mcModule120
We found a nice enclosure that included an opening for easy battery changes. We started with using step bits to drill two holes into the enclosure for the ultrasonic sensor:
Because the enclosure had the opening for the battery pack, we decided to connect a 2 x AA battery holder to the mcModule120. This way we can power the device using AA batteries and increase the life of the device dramatically!
We then inserted the ultrasonic sensor into the holes we drilled and installed the rest of the electronics into the enclosure:
We then put some batteries in, closed up the case:
You can use the code that is listed at the bottom of this project (you'll need to also use the sensor library in your programming as well). Depending on where you want to direct the information, you'll need to modify the code and also your gateway configuration. For help, check out the other ultrasonic example we put together.
Because you can send the information to almost any IoT cloud application, you have the option to visualize or store the data based on your preference. mcThings works with many awesome partners that you can check out OR use a different application that can accept MQTT.
Depending on how often you ask the device to measure distance will determine how long the device will last. In this case, measuring every 30 seconds and relaying that to a cloud application, the device should last at least 8 years on 2 x AA batteries!
We'd love to hear your ideas for other use-cases for this type of device! Please become a member of our hub here on Hackster to stay up-to-date with new projects! We've got plenty more to come.
US-100 Ultrasonic Sensor librarymcScript
Define PinMode Pin4 As DigitalOutput Alias sensorPower Class US100 Const UART_BAUDRATE As Integer = 9600 Const DISTANCE_COMMAND As Byte = 0x55 Private _uartDev As Uart Private _txPin As Pin Private _rxPin As Pin Private _buf As ListOfByte Public Sub New(tx As Pin, rx As Pin) Disable() _txPin = tx _rxPin = rx _buf = New ListOfByte() End Sub Public Function GetDistance() As Integer _uartDev = Uart.Create(UART_BAUDRATE, _txPin, _rxPin) _buf.Clear() Enable() Thread.Sleep(800000) _uartDev.Write(DISTANCE_COMMAND) 'Command to request distance If Not WaitForResponse() Then _uartDev.Close() Disable() Return Nothing Else _uartDev.Close() Disable() 'calculate and return distance Return _buf(0) * 256 + _buf(1) End If End Function Private Function WaitForResponse() As Boolean Dim try As Integer = 3000 While (try > 0) If _buf.Count>= 2 Then Return True End If try -= 1 Thread.Sleep(1000) End While Return False End Function Public Sub Receive() Dim chr As Integer = _uartDev.Read() While chr >= 0 _buf.AddByte(chr.ToByte) chr = _uartDev.Read() End While End Sub Public Sub Enable() sensorPower = True End Sub Public Sub Disable() sensorPower = False End Sub End Class
Shared usSensor As US100 Shared Event Boot() usSensor = New US100(Pin.Pin2, Pin.Pin1) End Event Shared Event DistanceMeasurement() RaiseEvent Every 30 Seconds ' Create distance JSON object Dim distance As Integer = usSensor.GetDistance() Dim payload As Json = New Json payload.Add("mmDistance", distance) ' distance in mm 'Remove in final design (only used for debug) Dim payloadString As String = payload.ToString() Dim stringlength As Integer = payloadString.Length() Lplan.Publish(topic, payload.ToListOfByte) End Event Shared Event Uart0Receive() usSensor.Receive() End Event End Class
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!