Getting Started with Johnny-Five: An Introduction to Robotics and IoT Programming

Vikash DevZ
4 min readMay 29, 2023

--

Are you interested in exploring the world of robotics and Internet of Things (IoT) development? If so, then Johnny-Five is the perfect package to kickstart your journey! Johnny-Five is a JavaScript robotics and IoT framework that allows you to interact with a wide range of hardware components using a simple and intuitive API. In this guide, we’ll walk you through the basics of Johnny-Five, showcase its LED feature, and demonstrate how to connect new components like Bluetooth, Wi-Fi, and sensors.

What is Johnny-Five?

Johnny-Five is a JavaScript framework that brings the power of JavaScript to the physical world. It enables you to control and interact with various hardware components, such as sensors, actuators, and displays, using JavaScript code. Whether you’re a beginner or an experienced developer, Johnny-Five makes it easy to prototype, experiment, and build real-world projects without the need for complex low-level programming.

Getting Started

To get started with Johnny-Five, follow these simple steps:

  1. Install Node.js: Ensure that Node.js is installed on your system. You can download and install it from the official Node.js website (https://nodejs.org).
  2. Create a New Project: Open your terminal and create a new directory for your Johnny-Five project. Navigate to the project directory.
  3. Initialize Node.js Project: Run the following command to initialize a new Node.js project and generate a package.json file.
  • npm init -y
  1. Install Johnny-Five: Install the Johnny-Five package by running the following command in your project directory:
  • npm install johnny-five
  1. Connect Your Hardware: Connect the hardware components you want to control or interact with, such as an Arduino board or Raspberry Pi, to your computer.
  2. Write Your First Johnny-Five Code: Create a new JavaScript file, let’s say index.js, and start writing your Johnny-Five code.
const { Board, Led } = require('johnny-five');  
// Initialize Johnny-Five board
const board = new Board();

// When the board is ready
board.on('ready', () => {

// Create an LED instance
const led = new Led(13);

// Blink the LED every 500ms
led.blink(500);
});

Run Your Johnny-Five Code: Save the file and run your Johnny-Five code using Node.js:

  • node index.js

You should see the LED connected to pin 13 on your hardware board blinking every 500 ms.

Exploring the LED Feature

The LED feature in Johnny-Five allows you to control LED connected to your hardware board. Let’s dive into some of the key functionalities of the LED class:

  • Blinking: You can make an LED blink at a specified interval using the blink() method. For example, led.blink(500) will make the LED blink every 500ms.
  • Turning On and Off: You can manually turn the LED on and off using the on() and off() methods, respectively. For instance, led.on() will turn the LED on, and led.off() will turn it off.
  • Pulsing: If you want to create a pulsing effect on the LED, you can use the pulse() method. It allows you to control the brightness of the LED by specifying the fade-in and fade-out duration.

These are just a few examples of what you can do with the LED feature in Johnny-Five. Feel free to explore the official Johnny-Five documentation (https://example.com/johnny-five-docs) for more detailed information and additional functionalities.

Connecting New Components

Johnny-Five not only supports LED but also a wide range of other hardware components. Here’s a high-level overview of how you can connect new components:

  1. Identify the Component: Determine the type of component you want to connect, such as Bluetooth, WiFi module, sensors (temperature, motion, etc.), or actuators (servos, motors, etc.).
  2. Find the Appropriate Class: Consult the Johnny-Five documentation to find the relevant class for your component. Each component usually has a dedicated class or set of classes to interact with it.
  3. Import the Class: In your JavaScript file, import the required class from the Johnny-Five package.
  4. Create an Instance: Create a new instance of the component class, providing any necessary configuration or pin assignments.
  5. Interact with the Component: Use the methods and properties provided by the component class to control or retrieve data from the connected component.

By following these steps, you can easily expand your Johnny-Five project and connect a variety of hardware components to unleash the full potential of your robotics or IOT application.

Additional Resources

To further enhance your Johnny-Five development skills, consider exploring the following resources:

  • Official Johnny-Five Documentation: The official documentation is a comprehensive resource that covers all aspects of using Johnny-Five, including supported hardware components, API references, examples, and troubleshooting guides.
  • Johnny-Five GitHub Repository: Visit the Johnny-Five GitHub repository (https://github.com/rwaldron/johnny-five) to access the source code, contribute to the project, or raise issues if you encounter any problems.
  • Online Tutorials and Projects: Explore online tutorials, articles, and projects shared by the Johnny-Five community. These resources provide practical examples, project ideas, and tips for building various robotics and IOT applications.

Remember, the key to mastering Johnny-Five is practice and experimentation. Start small, gradually add new components, and enjoy the process of bringing your hardware projects to life using JavaScript.

This blog post serves as the first part of our comprehensive guide to Johnny-Five. We hope you found the information and code examples provided helpful in getting started with Johnny-Five, exploring its LED feature, and connecting new components. Stay tuned for the upcoming second part of this blog, where we’ll delve deeper into advanced functionalities and showcase more exciting projects you can build with Johnny-Five. Be sure to subscribe to our newsletter or follow us on social media to receive updates when the next part is released. Happy tinkering and stay excited for the next installment!

Happy coding!

--

--