Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. 5v on input to act like a button

5v on input to act like a button

Scheduled Pinned Locked Moved Troubleshooting
11 Posts 4 Posters 3.5k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Cliff KarlssonC Offline
    Cliff KarlssonC Offline
    Cliff Karlsson
    wrote on last edited by
    #1

    I have a cheap 433mhz dorbell where I have removed the internal speaker and connected those cables to PIN 3 and GND.

    When the remote button is pressed the cables supply 4.7v for a couple of seconds. I am powering the arduino from the same three AA batteries that runs the reciever and they are connected to the RAW, GBD on the arduino.

    I have tried running http://www.mysensors.org/build/binary but that dont work. How would I modify that sketch to report button pressed when PIN 3 recieves ~5v.

    Also the arduino is powerd up when I connect the speaker cables to PIN 3, GND and when GND from power supply. Even if I don´t connect the "power" frm the power supply.

    1 Reply Last reply
    0
    • sowardS Offline
      sowardS Offline
      soward
      wrote on last edited by
      #2

      The speaker is probably being sent an AC waveform, and the meter is just averaging it out so you see 4.7v. Likewise there may be some DC power from one side of it to gnd all the time since it's able to energize the Arduino.

      Best would be to trace the circuit further back and see if there is something else you can tap into ahead of the speaker and it's driver.

      If not you might be able to tie the speaker outputs together through a diode and a small resistor ( say 16Ohm ) and hook that to pin 3 -- or not depending on how it's driven. Or you could build a voltage dividing circuit to keep the AC voltage down to ~2v and use an ADC pin to read the waveform being sent to the speaker.

      1 Reply Last reply
      0
      • Cliff KarlssonC Offline
        Cliff KarlssonC Offline
        Cliff Karlsson
        wrote on last edited by
        #3

        Solved it by using a optocoupler on the signal from the speakers.

        1 Reply Last reply
        0
        • Cliff KarlssonC Offline
          Cliff KarlssonC Offline
          Cliff Karlsson
          wrote on last edited by Cliff Karlsson
          #4

          But now I have a new problem. I am using this sketch:

          // Enable debug prints to serial monitor
          #define MY_DEBUG 
          
          // Enable and select radio type attached
          #define MY_RADIO_NRF24
          //#define MY_RADIO_RFM69
          
          #include <SPI.h>
          #include <MySensor.h>
          #include <Bounce2.h>
          
          #define CHILD_ID 3
          #define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
          
          Bounce debouncer = Bounce(); 
          int oldValue=-1;
          
          // Change to V_LIGHT if you use S_LIGHT in presentation below
          MyMessage msg(CHILD_ID,V_TRIPPED);
          
          void setup()  
          {  
            // Setup the button
            pinMode(BUTTON_PIN,INPUT);
            // Activate internal pull-up
            digitalWrite(BUTTON_PIN,HIGH);
            
            // After setting up the button, setup debouncer
            debouncer.attach(BUTTON_PIN);
            debouncer.interval(5);
            
          }
          
          void presentation() {
            // Register binary input sensor to gw (they will be created as child devices)
            // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
            // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
            present(CHILD_ID, S_DOOR);  
          }
          
          
          //  Check if digital input has changed and send in new value
          void loop() 
          {
            debouncer.update();
            // Get the update value
            int value = debouncer.read();
           
            if (value != oldValue) {
               // Send in the new value
               send(msg.set(value==HIGH ? 1 : 0));
               oldValue = value;
            }
          } 
          

          But I always get two triggers for one one button press. So the status is never changed like: Start state= ON, trigger OFF,TriggerON.

          How can I make it so that It has to be more then 2 seconds apart from the triggers? So that the second rapid trigger command is filtered and not reported to domoticz ?

          Also I would like the arduino to sleep as long as it is not detecting any button-press on PIN 3

          1 Reply Last reply
          0
          • B Offline
            B Offline
            BSB
            wrote on last edited by BSB
            #5

            Find out where the second pulse comes from and mitigate it.

            You already have a debounce in there so increase the time there to start with.

            You may also want to put a voltage divider in there too in case its actually a voltage spike as suggested already.

            Is there any sort of relay involved in the whole circuit as it could also be chatter ?

            1 Reply Last reply
            0
            • Cliff KarlssonC Offline
              Cliff KarlssonC Offline
              Cliff Karlsson
              wrote on last edited by
              #6

              OK, so if I change

              debouncer.interval(5);
              

              to

              debouncer.interval(1000);
              

              It will skip any button that are sent within 1 sec of the first buttonpress?
              Regarding the voltage-spike I am using a optocoupler this time so there are no current sent to the arduino. It only acts like I connect PIN 3 to GND.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                BSB
                wrote on last edited by
                #7

                Yup just change the debounce until your second trigger is no longer an issue. and well done going opto it's much safer.

                That delay is only 5ms and the 1000 is 1s.
                Times on delays are only approximate as the program takes time to run itself causing other slight delays.

                1 Reply Last reply
                0
                • Cliff KarlssonC Offline
                  Cliff KarlssonC Offline
                  Cliff Karlsson
                  wrote on last edited by
                  #8

                  Ok, thanks. I think I read somewhere that there could be problems using debounce and sleep. Can I still use debounce and sleep until interrupt on Pin 3?

                  AWIA 1 Reply Last reply
                  0
                  • Cliff KarlssonC Cliff Karlsson

                    Ok, thanks. I think I read somewhere that there could be problems using debounce and sleep. Can I still use debounce and sleep until interrupt on Pin 3?

                    AWIA Offline
                    AWIA Offline
                    AWI
                    Hero Member
                    wrote on last edited by
                    #9

                    @Cliff-Karlsson I find it hard to figure out why you are getting a double trigger from your circuit. As you don't have a mechanical switch I think the cause is in the circuit. Can draw it or post a picture?

                    1 Reply Last reply
                    0
                    • Cliff KarlssonC Offline
                      Cliff KarlssonC Offline
                      Cliff Karlsson
                      wrote on last edited by
                      #10

                      Well I "tapped" the signal from the speaker wires and as soward stated above "The speaker is probably being sent an AC waveform" -maybe that is causing the strange behaviour. I tried finding other places to use but most of them only gave me ~0.1V when the button was pushed and I thought I needed more power to trigger the octocoupler.

                      But can I modify the code somehow so that I culd use sleep on interrupt but force the arduino to only report the first "trigger" and the go back to sleep again?

                      I will upload a picture too if unclear.

                      AWIA 1 Reply Last reply
                      0
                      • Cliff KarlssonC Cliff Karlsson

                        Well I "tapped" the signal from the speaker wires and as soward stated above "The speaker is probably being sent an AC waveform" -maybe that is causing the strange behaviour. I tried finding other places to use but most of them only gave me ~0.1V when the button was pushed and I thought I needed more power to trigger the octocoupler.

                        But can I modify the code somehow so that I culd use sleep on interrupt but force the arduino to only report the first "trigger" and the go back to sleep again?

                        I will upload a picture too if unclear.

                        AWIA Offline
                        AWIA Offline
                        AWI
                        Hero Member
                        wrote on last edited by AWI
                        #11

                        @Cliff-Karlsson if you have an AC waveform it will probably be a lot of noise and/or a "sine like" wave of a certain frequency.
                        upload-6c2f3ec0-fffc-4b45-b839-886304797eb9. Connected to an optocoupler this will trigger very frequently.

                        What I suggest you do is rectify the signal so that you get a "DC" signal to use as a trigger.

                        upload-768f93c3-149b-4902-8fb3-628813e04a4f
                        thnx wiki

                        Connect the +Vo and GND to your optocoupler (in series with a resistor of around 470 Ohm). C1 = 100uF & R1 = 1kOhm will do to get a reasonable clean signal.

                        You can attach the optocoupler to the interrupt (D2 or D3) and do whatever you want with it using gw.sleep(...)

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        13

                        Online

                        11.7k

                        Users

                        11.2k

                        Topics

                        113.1k

                        Posts


                        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • MySensors
                        • OpenHardware.io
                        • Categories
                        • Recent
                        • Tags
                        • Popular