Author Topic: mcModule as doorbell  (Read 29 times)

michaelblight

  • Newbie
  • *
  • Posts: 7
    • View Profile
mcModule as doorbell
« on: August 03, 2018, 02:08:31 am »
I'm looking to hook up a mcModule as a doorbell sending MQTT messages. I haven't been able to find any existing examples, and I'm no electrical engineer! Is it enough to connect pin 7 and GND to a push-button and define it as AnalogInputPullDown? I'm guessing not. Or do I need to connect VDD to push-button to pull-down resistor to GND and then connect pin 7 between switch and resistor?

And then is there an event to hook into that will fire when the push-button is pressed? Or do I have to poll pin 7 (which would drain the battery too fast)?

Any help would be appreciated.

Social Buttons


mc-T2

  • Administrator
  • Sr. Member
  • *****
  • Posts: 252
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: mcModule as doorbell
« Reply #1 on: August 14, 2018, 10:43:08 am »
Hey michaelblight,

yes, I havent seen anyone post this project yet, however, we have done this ourselves and i know of some users who have done a button onto a mcModule. The mcModule includes a small button/switch already but if you wished, you could connect a push button and use it for a doorbell (or other purposes).

Since you are working on the older version (legacy) of the mcThings platform, you will need to work with some older code. NOTE - We are moving towards the public release of mcCloud in the next month or two so keep an eye out as the new version of mcCloud is very versatile and makes it much easier to work with multiple devices! Older equipment will not work on the new system but we are going to be offering our users discounted hardware for those who want to move to the new system. It should also be noted that we are no longer supporting the legacy system (no new firmware, big fixes, etc) as we are focusing on the new version.

Button code: The below is a code we used to send information to the IFTTT service but you can modify it to send the info to elsewhere if you wish. A standard pushbutton was soldered to PIN 0 and GRD from the button and then the device was loaded with the below code:


Code: [Select]
Class ButtonExample
   
    //The following will send an IFTTT message when the button is pressed & will light the LED when pressed
    Shared Event ButtonPressed()
        Thread.Sleep(50000)
        Thread.ClearHardwareEvent()
        'If Pin0 = False Then
        If Button0 = False Then
            Lplan.IFTTT("YOURIFTTTWEBHOOKKEYHERE", "BUTTON", "pressed")
            LedGreen = True // turn off LED
            Thread.Sleep(100000)
            LedGreen = False
            Thread.Sleep(120000000)
        End If       
    End Event   
End Class

From there, we setup an IFTTT applet which would send a notification/email/text when the button is pressed. Note, there can sometimes be some lag as you are working with a third-party service.. sometimes it is lightening fast and other times it can take up to a minute. You will also need to test and ensure that your mcGateway is in range of the device.
Hope that helps, good luck and when the new version of mcCloud is out, we will be pushing out the same above example for a button so you can do this on the new system.
Thanks
Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB

michaelblight

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: mcModule as doorbell
« Reply #2 on: August 26, 2018, 02:57:39 am »
Thanks @mc-T2 for the update - I will try it soon. I'm a bit confused though. You said you soldered a push button between Pin 0 and GND, but the code is responding to the ButtonPressed event. Or am I reading it wrong - have you soldered the button in parallel with the existing button on the mcModule? Is there an event that will fire on a change to Pin 0? I have soldered breadboard cables to these pins in anticipation, which was challenging with old eyes. I don't like my chances of soldering to the button on the PCB!

mc-T2

  • Administrator
  • Sr. Member
  • *****
  • Posts: 252
  • mc-Things! The opportunities are endless!
  • Location: Canada
    • View Profile
Re: mcModule as doorbell
« Reply #3 on: August 27, 2018, 09:51:05 am »
@michaelblight - you are correct, i think i put in the wrong code for you. There is a button on the mcMod's that you can use - it is predefined within the langage script (as button) and can be used. However, this button will be quite touch for someone to press as a doorbell. Here is code that is better suited to what you want to do (With a button soldered to pin0 and GND):

Code: [Select]
Define PinMode Pin0 As DigitalInputPullupWeak
Class mcSwitch
   
   
   
    //The following will send an IFTTT message when the button is pressed & will light the LED when pressed
    Shared Event Pin0FallingEdge()     
        Thread.Sleep(50000)
        'This timing may need To be modified but essentially this Is a debounce.After the device detects a change it waits 50 ms To check again To confirm that the button was actually pushed * *
        Thread.ClearHardwareEvent()
        If Pin0 = False Then
            Lplan.IFTTT("YOURIFTTTKEYHERE", "BUTTON")
            LedGreen = True // turn off LED
            Thread.Sleep(100000)
            LedGreen = False
            Thread.Sleep(30000000)
            'This can also be modified.After the above program runs, the module will Not be able To run it again For 120 Seconds / 2 Minutes (the timing Is In microSeconds).If you want, you can change this To 6000000 which will give you 60 Seconds before the button can be pressed again.
        End If
    End Event
End Class
   
End Class

Hope that helps
Need more mc-Modules, mc-Gateways or other mc-Things? Check out our product page: www.mcthings.com/products. mc-Development kits are available too!
Check out a live Dashboard using mcThings and Losant! Click here: https://goo.gl/ST43hB

michaelblight

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: mcModule as doorbell
« Reply #4 on: September 01, 2018, 08:07:38 am »
Thanks! Can't wait to try it out. Much better than those suckers with their voltage hungry Arduinos