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 1492 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: 39799
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

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.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Return to “Other programming languages”