cloudraider
Posts: 1
Joined: Tue Jun 12, 2018 3:51 pm

Raspbery Pi 3 + Node.js and Two Push Buttons

Tue Jun 12, 2018 4:18 pm

Hey there,
I am new to this Forum so I hope that I am in the right place.

I have the following idea:

I want to connect two buttons to my Raspberry Pi 3 and trigger functions on my Node.js Sever when pressed.

Code: Select all

var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO

var pushButton = new Gpio(17, 'in', 'rising', {debounceTimeout: 10});
var pushButton2 = new Gpio(18, 'in', 'rising', {debounceTimeout: 10}); 


pushButton.watch(function (err, value) {
//Watch for hardware interrupts on pushButton GPIO, specify callback function
  if (err) { //if an error
    console.error('There was an error', err); //output error message to console
  return;
console.log("Btn1");
});

pushButton2.watch(function (err, value) { 
//Watch for hardware interrupts on pushButton GPIO, specify callback function
  if (err) { //if an error
    console.error('There was an error', err); //output error message to console
  return;
  }
console.log("Btn2");
});
Below I have my wiring:
2-Button-Circuit.png
2-Button-Circuit.png (94.5 KiB) Viewed 421 times

Now the Issue I am running into is, that whenever I press Button1 the Button2 is pressed as well and if i try to press Button2 it is not working 100% of the time, meaning if i press it around 5 times it registers one event.

Anyone any ideas?

User avatar
DougieLawson
Posts: 33352
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Raspbery Pi 3 + Node.js and Two Push Buttons

Tue Jun 12, 2018 5:57 pm

Move the red wire to 3V3 or you could destroy your Raspberry.

You may have already damaged it irreperably.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

Return to “Other programming languages”

Who is online

Users browsing this forum: No registered users and 2 guests