LCD screens are versatile components that can be used in a variety of projects. In this guide, we will learn how to work with an LCD screen using the Johnny Five library. Let’s get started!

Getting Familiar with the LCD Screen

LCD Screen

The LCD screen we will be using is the 1602A model, which has 16 pins. Here is how it should be wired:

Pin 1: 0V
Pin 2: Potentiometer (backlight control)
Pin 3: 5V
Pin 4: Arduino Pin 7
Pin 5: 0V
Pin 6: Arduino Pin 8
Pin 11: Arduino Pin 9
Pin 12: Arduino Pin 10
Pin 13: Arduino Pin 11
Pin 14: Arduino Pin 12
Pin 15: 5V
Pin 16: 0V

Wiring the LCD Screen

Wiring Diagram

To control the backlight, connect the middle pin of the potentiometer to the LCD screen, the left pin to 0V, and the right pin to 5V.

Potentiometer

Initializing the LCD Object

Create a new file called lcd.js and add the following code:

const { Board, LCD } = require("johnny-five");
const board = new Board();

board.on("ready", function() { 
  const lcd = new LCD({ pins: [7, 8, 9, 10, 11, 12] }); 
});

This code sets up the Johnny Five board and initializes a new LCD object from the LCD class. The pins array specifies the Arduino pins connected to the LCD screen.

Displaying Text on the LCD Screen

To display a string on the LCD screen, add the following code:

const { Board, LCD } = require("johnny-five");
const board = new Board();

board.on("ready", function () {
  const lcd = new LCD({ pins: [7, 8, 9, 10, 11, 12] });
  lcd.print("Hello World!");
});

Running the program with node lcd.js will display the text on the LCD screen.

Hello World on LCD Screen

Additional Methods for LCD Screens

The LCD class provides convenient methods for controlling the screen. Here are some examples:

  • clear(): Clears the screen.
  • cursor(): Positions the cursor at a specific place.
  • off(): Disables the display.
  • on(): Enables the display.
  • blink(): Blinks the cursor.
  • noBlink(): Stops blinking the cursor.
  • autoscroll(): Enables automatic scrolling when the message exceeds the screen size.

For more information on these methods, refer to the Johnny Five LCD documentation.

With this knowledge, you can start creating projects that incorporate LCD screens using Johnny Five and Arduino. Have fun exploring the possibilities!