Things used in this project

Hardware components:
Mc devkit100a scojkvv1ol
mcThings mcModule120 Dev Kit
This kit gives you everything you need to get going with mcThings. Not a requirement for this project however you will require at least one mcModule120, one mcGateway and one mcDongle
Product mcmod120 top front back p8hs3xepwv
mcThings mcMod120 Module
You also require an mcGateway and mcDongle to bring the information from the device to the cloud. Consider an mcModule120 development kit!
Hammond - Nice blue case with easy access to batteries
US100 - Ultrasonic Sensor
You can get these from many different suppliers - search around for the best price from your preferred supplier
Generic AA battery clip
Software apps and online services:
Mcstudio h8lhxdnyfz
mcThings mcStudio
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)


mcModule120 Product brief
mcModule120 Schematic


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)
        _txPin = tx
        _rxPin = rx
        _buf = New ListOfByte()
    End Sub
    Public Function GetDistance() As Integer
        _uartDev = Uart.Create(UART_BAUDRATE, _txPin, _rxPin)
        _uartDev.Write(DISTANCE_COMMAND) 'Command to request distance
        If Not WaitForResponse() Then
            Return Nothing
            '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
        End While
        Return False
    End Function 
    Public Sub Receive()
        Dim chr As Integer = _uartDev.Read()
        While chr >= 0
            chr = _uartDev.Read()
        End While
    End Sub
    Public Sub Enable()
        sensorPower = True
    End Sub
    Public Sub Disable()
        sensorPower = False
    End Sub
End Class
mcModule120 programmingmcScript
    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


Cu3cvrhf tdqeqwcew0
17 projects • 38 followers
Use mcThings to quickly & easily create, test and deploy IoT solutions for industrial, business/commercial and individual needs!


Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback


Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog