In this video Tom Edworthy goes through the implementation of a wireless IoT rain sensor system using the mc-Module 110 (also compatible with the mc-Module 120). Near the end of this video demonstration Tom shows the system in action by sending response data through the MQTT IoT app for Android.
https://youtu.be/Uxry7aGb2V4Links to both the rain sensor and MQTT Iot app below:
Rain Sensor:http://ebay.to/2ewel62 (eBay)
http://bit.ly/2dJmu80 (Wish)
http://bit.ly/2f8dRVE (Deal Extreme)
MQTT IoT Phone App:http://bit.ly/2eS6Fcs (Google Play)
Simple Code:Define PinMode Pin0 As AnalogInput Alias RainLevel
Define PinMode Pin6 As DigitalOutput Alias enableRainLevel
Class RainSensor
Shared Event measureRainLevel2() RaiseEvent Every 30 Seconds
enableRainLevel = True 'turn on voltage divider
Thread.Sleep(40000) 'sleep 40ms for voltage to stabilize
Dim voltage As Short = RainLevel
Dim payload As ListOfByte = New ListOfByte
Dim payString As String = ""
If voltage > 1076 Then
payString = "Dry"
ElseIf voltage <= 1075 Then
payString = "Raining/Wet"
Else
End If
enableRainLevel = False 'turn off voltage divider
payload.Add(payString)
Lplan.Publish("mcThings/RainLevel2", payload)
End Event
'the following will check the battery voltage and will alert if low via IFTTT
Shared Event measureVoltage() RaiseEvent Every 12 Hours
Dim BattVolt As Short = Device.BatteryVoltage
If BattVolt < 2200 Then
Lplan.IFTTT("YOURIFTTTKEYHERE", "RainSensor2Batt")
Else
End If
End Event
End Class
Complex Code:Define PinMode Pin0 As AnalogInput Alias RainLevel
Define PinMode Pin6 As DigitalOutput Alias enableRainLevel
Class RainSensor
Shared Event measureRainLevel() RaiseEvent Every 30 Seconds
enableRainLevel = True 'turn on voltage divider
Thread.Sleep(40000) 'sleep 40ms for voltage to stabilize
Dim voltage As Short = RainLevel
Dim payload As ListOfByte = New ListOfByte
Dim payString As String = ""
If voltage > 1076 Then
payString = "Dry"
ElseIf voltage <= 1075 And voltage >= 801 Then
payString = "LightRain"
ElseIf voltage <= 800 And voltage >= 651 Then
payString = "MediumRain"
ElseIf voltage < 650 Then
payString = "HeavyRain"
Else
End If
enableRainLevel = False 'turn off voltage divider
payload.Add(payString)
Lplan.Publish("mcThings/RainLevel", payload)
End Event
'the following will check the battery voltage and will alert if low via IFTTT
Shared Event measureVoltage() RaiseEvent Every 12 Hours
Dim BattVolt As Short = Device.BatteryVoltage
If BattVolt < 2200 Then
Lplan.IFTTT("YOURIFTTTKEYHERE", "RainSensorBatt")
Else
End If
End Event
End Class