Skip to content

Johnny Five, how to work with an LCD Screen

THE AHA STACK MASTERCLASS

Launching May 27th

This post is part of the Johnny Five series. See the first post here.

An LCD screen is a pretty cool component because we can use it for many different projects in creative ways.

This one I have is named 1602A.

It has 16 pins. I wired it in this way:

The potentiometer has 3 pins. The middle one is connected to the LCD screen, the left one is 0V and the right one 5V:

That’s it for the wiring.

Create a new lcd.js file and load this code:

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

board.on("ready", function () {})

Now initialize a new LCD object from the LCD class.

The exact initialization procedure depends on the kind of display used. In my case, it was this:

const lcd = new LCD({ pins: [7, 8, 9, 10, 11, 12] })

Finally, call the print() method to display a string:

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!")
})

and run the program using node lcd.js to see it work:

The LCD class also offers those cool methods:

You can find out more on http://johnny-five.io/api/lcd/.


→ Get my JavaScript Beginner's Handbook

I wrote 20 books to help you become a better developer:

  • Astro Handbook
  • HTML Handbook
  • Next.js Pages Router Handbook
  • Alpine.js Handbook
  • HTMX Handbook
  • TypeScript Handbook
  • React Handbook
  • SQL Handbook
  • Git Cheat Sheet
  • Laravel Handbook
  • Express Handbook
  • Swift Handbook
  • Go Handbook
  • PHP Handbook
  • Python Handbook
  • Linux Commands Handbook
  • C Handbook
  • JavaScript Handbook
  • CSS Handbook
  • Node.js Handbook
...download them all now!

Related posts that talk about js: