skip to Main Content

RPi Node-Red: Push Button

Authors: Ben, Chester, Sprinkels

You can use the GPIO pins can be used for output, like making the RGB Module change colors, but most of the time you will using them as in input device. Sensors like the BME-280 can send data about weather, or a sonic sensor can tell you how close something is. However the simplest possible sensor is a button that simply reports on or off. The goal of this lesson is to learn how to start using node-red to receive input through the GPIO pins.

What you will learn:
How to read the state of a push-button wired to the GPIO pins through node-red.

Parts List:

What is a Push Button?

A push button is a momentarily activated button.  When the button mechanism is fully depressed an internal electrical connection is made and this newly made connection can be read as the activation of the button.

Video Tutorial:

This is what the pin connections look like for the Button Module

  • VCC -> 3.3V
  • OUT -> PIN 22#25
  • GND -> GND

The VCC and GND supply power, and in #25 will be used to read the signal.



Setting up Node-Red

Start Node-Red and navigate to  Drag a Raspberry Pi input node and a Debug node into the flow area.

Double click on the Raspberry Pi input node to open its configuration menu.  Set the Pin to GPIO25. Set Resistor? to pulldown.  You can Name the node anything, I chose “button”.

The debug node can be left with it’s default settings, wire the button node to the debug node and deploy the flow.

If everything has been put together correctly you should see the number under the button node in the Node-Red flow change from a 0 to a 1 when the button is activated and from 1 to 0 when the button is deactivated.  You should also be able to see a record of the button activation in the debug tab of Node-Red.

Whats Next:

Back To Top