Author Topic: Detecting button press (false detections)  (Read 1548 times)

Lukapple

  • Full Member
  • ***
  • Posts: 202
Detecting button press (false detections)
« on: January 13, 2020, 01:37:31 AM »
Hi,
I've installed a temporary doorbell button, using Moteino, button from Arduino kit and ~10m utp cable.
When Moteino detects a button press, it sends a "RING" command to other Moteino (doorbell node), so it triggers chime.
Everything works fine, except that sometimes it rings randomly, without button press, which is kinda scary if it rings in the middle of the night :(
That random event is not that common, it happens every few days or so.

My question is if this is a hardware problem, like occasional short circuit or am I detecting button press wrong.
Here is part of the code that I'm using for reading button state:

Code: [Select]
#define RING_PIN 14

void setup() {
  SERIAL_BEGIN;
  pinMode(RING_PIN, INPUT_PULLUP);
}


void loop() { 
  ...

  if (digitalRead(RING_PIN) == 0) { //0=button is pressed
    ring();
  }
}

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Detecting button press (false detections)
« Reply #1 on: January 13, 2020, 08:31:32 AM »
...~10m utp cable.
I suspect that the cable is picking up electrical noise and is giving you false triggers.  You could try to use software to filter it out and maybe that would work.   Using an external resistor with much lower resistance (like 270ohm) will help quite a bit unless you're operating off of battery for the Moteino. Then you can't afford the current required by the resistor.  In this case I'd put a relatively large capacitor (1 to 10uF) across the input and this will help filter.

In any case, I recommend the Bounce2 library to filter out any switch bounce and 'some' electrical noise.

Lukapple

  • Full Member
  • ***
  • Posts: 202
Re: Detecting button press (false detections)
« Reply #2 on: January 13, 2020, 08:43:43 AM »
Thanks for the hints Tom.
Moteino is powered by 12DC power supply - seperate unshielded UTP cable, but it’s near other UTP cable, which leads to bell button.
Today I got 2 false rings in 10 minutes. I’ll try to use that software filter first to see if it will help.

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Detecting button press (false detections)
« Reply #3 on: January 13, 2020, 08:47:38 AM »
I’ll try to use that software filter first to see if it will help.
The capacitor will provide some additional protection against noise spikes that exceed the processor's input voltage.

Lukapple

  • Full Member
  • ***
  • Posts: 202
Re: Detecting button press (false detections)
« Reply #4 on: January 13, 2020, 08:53:04 AM »
Should I use both then - software filter + capacitor?
So 10uF will be good (sorry, I'm not so good at electronics, i'm a software guy)? Should I also add a resistor, or is capacitor enough?

Lukapple

  • Full Member
  • ***
  • Posts: 202
Re: Detecting button press (false detections)
« Reply #5 on: January 17, 2020, 07:16:35 AM »
Ok, now I got required components on stock:
- capacitors: 10 µF 350 V and 10 µF 25 V  (any of those would probably work?)
- resistor 270 Ω

My current wiring diagram (using Moteino instead of Arduino):


Fixed diagram:


Is fixed diagram wiring correct ?   :)

« Last Edit: January 18, 2020, 10:18:05 AM by Lukapple »

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: Detecting button press (false detections)
« Reply #6 on: January 17, 2020, 10:35:56 AM »
Ok, now I got required components on stock:
- capacitors: 10 µF 350 V and 10 µF 25 V  (any of those would probably work?)
- resistor 270 Ω
...
The 10uF 25V cap is fine, it could even be as small as 10uF/4V, but overrating won't hurt you in this case.
I wouldn't bother with the resistor.  You don't have it wired exactly as it should be and it probably won't affect the result with just the cap and the bounce2 software.

Quote
One more question,
if I use this Moteino GND, reading input doesn't work:
 Aren't those ground pins connected?
Yes, they are supposed to be connected so this makes no sense at all.

Lukapple

  • Full Member
  • ***
  • Posts: 202
Re: Detecting button press (false detections)
« Reply #7 on: January 17, 2020, 10:38:58 AM »
The 10uF 25V cap is fine, it could even be as small as 10uF/4V, but overrating won't hurt you in this case.
I wouldn't bother with the resistor.  You don't have it wired exactly as it should be and it probably won't affect the result with just the cap and the bounce2 software.
Please let me know how should I wire it the correct way.

Yes, they are supposed to be connected so this makes no sense at all.
Sorry, my mistake, it works.
« Last Edit: January 18, 2020, 10:17:12 AM by Lukapple »