Skip to content
Example using js-gpiozero library to toggle internal activity LED on the Raspberry Pi Zero W.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Example using js-gpiozero library to toggle internal activity LED on the Raspberry Pi Zero W.

Note that the "zero" in gpiozero doesn't imply the Raspberry Pi Zero (although that's the platform I developed this on). It's related to the original gpiozero Python library which has now been ported in JavaScript as js-gpiozero.


Here, I'm assuming that your Raspberry Pi Zero W is named pizero but that might not be the case. Make sure to update for your Pi's hostname below.

First make sure that your Raspberry Pi Zero is up-to-date.

$ ssh pi@pizero.local
$ sudo apt-get update

Next, make sure that you have the latest version of Node for the Raspbian distribution. Note that this will be different for a Raspberry Pi 3 and you shouldn't run this.

$ cd ~
$ wget
$ tar -xJf node-v6.10.3-linux-armv6l.tar.xz
$ cd node-v6.10.3-linux-armv6l
$ ./bin/node -v
$ sudo cp -R * /usr/local
$ node -v
$ npm -v

Now you're ready to pull the code and run it, noting that it takes root privileges to talk to the GPIO pins so npm start has to run via sudo.

# This command will temporarily turn off the
# standard behavior for the built-in activity
# LED on the Raspberry Pi. This will revert back
# to normal upon reboot.
$ echo none | sudo tee /sys/class/leds/led0/trigger
$ ssh pi@pizero.local
$ cd ~
$ mkdir sites
$ cd sites
$ git clone
$ cd gpiozero-toggle-led
$ npm install
$ sudo DEBUG=gpiozero-toggle-led:* npm start
# You can do this from your own workstation
# with a browser if you'd like
$ open http://pizero.local:3000

Exercising the code

The Express-generated website is very simple. The main index page (HTTP GET) exercises the js-gpiozero library to blink the built-in activity light on the Raspberry Pi Zero. It presents a button which will post back to the same page. On HTTP POST it will run a different function in the routes file to toggle off the same LED.

Note that the interface level of a Raspberry Pi Zero is reversed from that of a Raspberry Pi 3. So the call to gpio.LED(pin, false) has a second argument which must be called for it to work as expected.

Donate Cryptocurrency
eth-receive btc-receive
Ethereum Bitcoin
You can’t perform that action at this time.