# Johnny Five Tutorial

> Learn how to control an Arduino from Node.js with Johnny-Five, upload StandardFirmataPlus, connect the board, and blink its built-in LED.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2021-04-13 | Updated: 2026-07-18 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/johnny-five/

[Johnny-Five](https://johnny-five.io/) is a library that allows us to **interface with electronic devices using [JavaScript](https://flaviocopes.com/javascript/)**.

Devices like [Arduino](https://flaviocopes.com/arduino-introduction/) are usually programmed in the [Arduino Language](https://flaviocopes.com/arduino-programming-language/), which is a particular framework for C/C++.

Small microcontrollers generally do not run Node.js themselves. With Johnny-Five, the JavaScript program runs on a computer and sends commands to the board.

The two sides communicate through [Firmata](https://github.com/firmata/protocol), a protocol for controlling a microcontroller from software on a host computer.

Johnny-Five gives us a friendly JavaScript API on top of that protocol.

## Setting up your Arduino to work with Johnny-Five

Install the current [Arduino IDE](https://www.arduino.cc/en/software).

Open it, and you'll see something like this:

![Arduino IDE interface showing a blank sketch with setup and loop functions](https://flaviocopes.com/images/johnny-five/Screenshot_2020-03-26_at_10.38.24.png)

Connect the Arduino board to your USB port.

Go to Tools -> Port and make sure the port selected is the one the Arduino is connected to (in my case `/dev/cu.usbmodem14101`). You should have a few options, and Arduino IDE should already pre-detect it for you.

![Arduino IDE Tools menu showing Port selection with Arduino Uno port highlighted](https://flaviocopes.com/images/johnny-five/Screenshot_2020-03-26_at_10.41.22.png)

Go to Tools -> Board and make sure the device you have is correctly selected.

![Arduino IDE Tools menu showing Board selection with Arduino Uno selected from dropdown list](https://flaviocopes.com/images/johnny-five/Screenshot_2020-03-26_at_10.41.16.png)

In my case, the device is an Arduino Uno compatible board.

Then go to File -> Examples -> Firmata and choose `StandardFirmataPlus`. This is still the firmware recommended for an Arduino Uno in the [official Johnny-Five platform guide](https://johnny-five.io/platform-support/):

![Arduino IDE File menu showing Examples submenu with Firmata expanded and StandardFirmataPlus highlighted](https://flaviocopes.com/images/johnny-five/Screenshot_2020-03-26_at_10.41.32.png)

This will load a new window:

![Arduino IDE window displaying StandardFirmataPlus sketch code with copyright and licensing information](https://flaviocopes.com/images/johnny-five/Screenshot_2020-03-26_at_10.51.19.png)

Click Upload to compile the sketch and load it on the Arduino board:

![Arduino IDE showing Done uploading message with program storage and memory usage statistics](https://flaviocopes.com/images/johnny-five/Screenshot_2020-03-26_at_10.51.53.png)

Great! Now you're all set on the hardware side. Close the Serial Monitor and any other program using the board's serial port before running Johnny-Five.

## The Arduino device must remain connected

One thing that you need to note about this approach is that the Arduino must remain connected to the computer running the Node.js program.

Usually when you upload an Arduino sketch written in C/C++, you can disconnect the board from your computer. The sketch is stored in flash memory and starts again when the board is powered.

A classic Arduino Uno does not run a full operating system or Node.js. It runs the uploaded sketch together with the small Arduino core and, during startup, its bootloader.

The sketch loaded in flash memory now is `StandardFirmataPlus`. It implements the [Firmata protocol](https://github.com/firmata/protocol), which Johnny-Five uses through the USB serial connection.

As soon as we disconnect the Arduino, the Johnny-Five program can no longer control it.

One way we can deploy the project somewhere is to use a Raspberry Pi, connect the Arduino to it, and run the Node.js app there. We can then access the Raspberry Pi using a VNC or SSH connection.

This is out of the scope of this lesson, but check out [How to connect to a Raspberry Pi using a Mac](https://flaviocopes.com/raspberry-pi-connect-vnc/) and [How to make sure the Raspberry Pi has always the same IP address](https://flaviocopes.com/raspberry-pi-static-address-lan/) if you're interested in doing so.

For the sake of understanding how we can program electronics with JavaScript, however, it will be enough to have the device connected to our computer.

## An overview of the functionality offered by Johnny-Five

Johnny-Five offers APIs for commonly used electronic components:

- [LED](https://flaviocopes.com/electronics-components-leds/)
- [Buttons](https://flaviocopes.com/electronics-components-buttons/)
- Sensors
- [Servo motors](https://flaviocopes.com/electronics-components-servo-motors/)
- Stepper motors
- Thermometers
- [LCD screens](https://flaviocopes.com/electronics-components-1602-lcd-display/)
- [Joysticks](https://flaviocopes.com/electronics-components-analog-joystick/)
- Gyroscopes
- Accelerometers

and much more.

## Install Johnny-Five

Create a folder for the project, initialize it, and install the `johnny-five` [npm](https://flaviocopes.com/npm/) package:

```sh
mkdir johnny-five-blink
cd johnny-five-blink
npm init -y
npm install johnny-five
```

Create a file named `blink.js`:

```js
const { Board, Led } = require('johnny-five')
const board = new Board()

board.on('ready', () => {
  const led = new Led(13)
  led.blink(500)
})
```

Run it:

```sh
node blink.js
```

Johnny-Five usually detects the serial port automatically. If you have several boards or serial devices connected, pass the port explicitly:

```js
const board = new Board({ port: '/dev/tty.usbmodem1101' })
```

On Windows, the value looks like `COM3`. Use the actual port shown by the Arduino IDE.

If the board does not become ready, check that:

- the correct board and port were selected when uploading `StandardFirmataPlus`
- the upload completed successfully
- the Arduino IDE Serial Monitor is closed
- the USB cable supports data, not just charging
- your user account has permission to access the serial port on Linux

The [Board API](https://johnny-five.io/api/board/) documents connection options and the [platform support page](https://johnny-five.io/platform-support/) lists the firmware or I/O plugin required by each supported board.

## Controlling the LED

The example creates a `Led` object for pin 13, which controls the built-in LED on a classic Arduino Uno.

Once you have the `led` object, you can call its methods, which include:

- `led.on()` to turn it on
- `led.off()` to turn it off
- `led.toggle()` to toggle its current state
- `led.blink()` to toggle it indefinitely, every 100ms by default
- `led.stop()` to stop the interval

Calling `led.stop()` does not necessarily turn the LED off. Use `led.stop().off()` when you want both actions.

See the official [LED API](https://johnny-five.io/api/led/) for brightness, fading, pulsing, and other operations.

One final detail: put Johnny-Five code in a file and run it with Node.js. The project documentation warns against starting it directly inside Node's own REPL because a board creates its own contextual REPL.
