mcThings
Published © GPL3+

Ultra Long-Life Smart IoT Recycling Bin

An ultra-low power, battery-operated recycling bin to showcase a perfect smart city IoT solution using mcThings, SIGFOX and Ubidots!

EasyFull instructions provided1 hour1,926

Things used in this project

Hardware components

mcModule120 Dev Kit
mcThings mcModule120 Dev Kit
We recommend a kit for this example so that you have multiple modules to gather information from (Not required but you will need at least one mcModule, one mcGateway and an mcDongle)
×1
mcMod120 Module
mcThings mcMod120 Module
You'll need at least one mcModule120 for this project if you wish to use mcAir
×1
mcGateway110
mcThings mcGateway110
You'll need an mcGateway for this project
×1
mcDongle
mcThings mcDongle
You'll need one of these to complete your firmware updates! Be sure to update your firmware to the latest versions before starting
×1
mcDemo205
mcThings mcDemo205
Used if you wish to work with the SIGFOX network
×1
US100 Ultrasonic Sensor
http://www.yourduino.com/sunshop/index.php?l=product_detail&p=121
×1
Hammond- plastic encosure
http://www.hammondmfg.com/scpg.htm
×1

Software apps and online services

mcStudio
mcThings mcStudio
Ubidots
Ubidots
Sigfox
Sigfox
MQTT - Means of sending information to Ubidots

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

mcMod120 Features

Code

US100 Sensor Library

mcScript
If you connect the sensor to other pins on the module, make sure you note those changes within the library code
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

mcModule programming

mcScript
You could also check the temperature, open/closed or really anything other sensor out there so feel free to modify this code to your needs
Class UbidotsUltrasonic
    
    Const DeviceLabel As String = "YOURDEVICENAME"
    Const topic As String = "/v1.6/devices/" + DeviceLabel
    
    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()
        
        ' Publish to Ubidots
        
        Lplan.Publish(topic, payload.ToListOfByte)
        
        
        
    End Event
    
    Shared Event Uart0Receive()
        usSensor.Receive()
    End Event
    
End Class 

Credits

mcThings

mcThings

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

Comments

Add projectSign up / Login