In this post, we will learn how to use Johnny Five, a JavaScript library, to communicate with electronic devices. Specifically, we will focus on lighting a LED.
To get started, follow these steps:
-
Create a new folder and initialize npm by running the command
npm init -y
. -
Install Johnny Five locally by running the command
npm install johnny-five
. -
Create a file named
app.js
and add the following code:
const { Board, Led } = require("johnny-five");
const board = new Board();
board.on("ready", () => {
const led = new Led(13);
led.blink();
});
This code initializes a new board and sets up a LED on pin 13. The LED will blink continuously.
The Led
object and the Board
object are just two of the many functionalities offered by the Johnny Five library.
Pin 13 on the Arduino Uno board is connected to the built-in LED.
To run the program, use the command node app.js
. You should see the LED turning on and off.
If you want to connect a physical LED, connect the negative pin to GND (0V) and the positive pin to pin 13. Make sure to use a resistor to limit the flow of current through the LED.
To stop the program, press Ctrl-C twice.
That’s it! You have successfully learned how to light a LED using Johnny Five.
Tags: Johnny Five, LED, JavaScript, Electronics