Project Explained

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!

What could this be used for?

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?

How mcThings platform works:

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!

Connecting the ultrasonic sensor to the mcModule120

We soldered the ultrasonic sensor to the mcModule120  - Check out the details within the pcture

PIN 0 to VCC, PIN 1 to Echo/Rx, PIN 2 to Trig/Tx, GND to GND

Setting up the enclosure and installing the device

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

And done!

Programming the mcModule120

You can use the code that is listed below (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


mcModule120 programming

 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()
    End Event
End Class

US-100 Ultrasonic Sensor library

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...
Read more »