THERMAL PRINTER INTERFACING WITH ARDUINO

Photo of author

By Jackson Taylor

Home » Electronics Topics » Arduino » THERMAL PRINTER INTERFACING WITH ARDUINO

As an Amazon Associate we earn from qualifying purchases.

A thermal printer is a handy output device for Arduino projects. It prints on heat-sensitive paper, so it needs no ink or ribbon, and it is small enough for receipts, tickets, labels and simple data logs. This guide shows how to connect a serial (TTL) thermal printer to an Arduino and print text with a short sketch.

The video below walks through the same build, and the full program follows after it.

How a thermal printer works

A thermal printer has a row of tiny heating elements in the print head. When heated paper passes under them, the coating turns dark and forms the characters. Because of this, the paper must be thermal paper, and it has to be loaded with the heat-sensitive side facing the print head.

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video

Most small thermal printers used with Arduino understand a set of commands known as ESC/POS. You send plain text over a serial connection, mixed with a few control bytes that change the text style or move the paper.

What you need

Wiring the printer to Arduino

The printer talks to the Arduino through a serial link, so it needs only two data lines and a common ground.

  1. Connect the printer’s RX pin to the Arduino TX pin (pin 1 on an Uno).
  2. Connect the printer’s TX pin to the Arduino RX pin (pin 0), if you want to read status back. For printing only, this line is optional.
  3. Connect the printer’s GND to the Arduino GND. The grounds must be shared.
  4. Power the printer from its own supply, not from the Arduino’s 5V pin.

Why a separate power supply matters

A thermal print head draws far more current when it is heating the paper than the Arduino can supply. If you power the printer from the board, you may see faint print, garbled output or random resets. Use a supply that meets the printer’s voltage and current rating, and keep the grounds joined.

See also
Best Cameras for Adventure Photography: 5 Picks by Depth, Cold and Weight

Uploading with pins 0 and 1

The sketch below uses the hardware serial port, which is also used by the USB connection for uploading. Disconnect the printer wires from pins 0 and 1 while you upload, then reconnect them. If you want to avoid this, use the SoftwareSerial library on two other pins and send the same bytes to that port.

Arduino program

The sketch opens the serial port at 9600 baud, switches the print mode, prints two lines of text and then feeds the paper so the text clears the tear bar.

PROGRAM -ARDUINO


void setup()
{
Serial.begin(9600);   delay(100);
Serial.write(0x1b);//increase width and bold of letter
Serial.write(0x21);//increase width and bold of letter
Serial.write(0x19);//increase width and bold of letter
Serial.print("THERMAL PRINTING BY");
Serial.write(0xa);//end and feed new line
Serial.print("EMERGING TECHS");
Serial.write(0xa);//end and feed new line
Serial.write(0xa);//end and feed new line
Serial.write(0xa);//end and feed new line
Serial.print(" ");
Serial.write(0xa);//end and feed new line
Serial.print(" ");
}
void loop()
{
}

How the code works

  • Serial.begin(9600) starts the serial port at 9600 baud. This must match the baud rate set in the printer.
  • 0x1b, 0x21, 0x19 is the ESC ! n command, which selects the print mode. On standard ESC/POS printers, the value 0x19 turns on emphasized (bold) text and double height, and selects the smaller font. Different models can respond a little differently, so check your printer’s command list if the result looks off. To make text wider, a value with bit 5 set (0x20) is normally used.
  • Serial.print(“…”) sends the text to be printed.
  • Serial.write(0xa) sends a line feed, which ends the current line and moves the paper forward.
  • The extra line feeds push the printed text past the tear bar so you can tear the paper off without cutting through the message.

The code sits in setup(), which runs once, so the message prints each time the Arduino is powered or reset. The loop() is empty on purpose. Move the print calls into it if you want repeated output, and add a delay or a trigger so the printer does not run continuously.

See also
COLOUR SORTING MACHINE USING ARDUINO

Reference images

The images below come from the original build and show the setup and the printed result.

Arduino and thermal printer setup for the serial printing example Thermal printer output from the Arduino serial printing example

Troubleshooting

  • Garbled or random characters: the baud rate probably does not match. Many printers can print a self-test page that shows their settings. Check it and update Serial.begin() to match.
  • Nothing prints: check that TX and RX are crossed correctly, the grounds are shared and the printer has power.
  • Blank paper: the roll is probably loaded the wrong way round. Flip it so the heat-sensitive side faces the print head.
  • Faint print or resets: the power supply is too weak. Use a proper external supply for the printer.
  • Upload errors: unplug the printer from pins 0 and 1 while uploading.

Ideas for using the printer

Once basic text works, you can combine the printer with other parts. Read a weight from a load cell and print a receipt, or enter values on a matrix keypad and print a ticket. You can also use an RGB LED as a status light that shows when the printer is busy.

If you are using a different model, the EPM 207 thermal printer guide covers another common module.

FAQ

Which thermal printers work with Arduino?

Serial TTL thermal printers that accept ESC/POS commands are the easiest to use. Check that the printer’s logic level and power requirements suit your setup before connecting it.

Sustainable Tech

Keep Toxic E-Waste Out of Landfills

Don't throw away your failing laptop, phone, or car batteries. Learn how to recondition them at home in just a few hours. It's better for the planet—and your wallet.

Learn How It Works

Can I power the printer from the Arduino?

It is not recommended. The print head needs a lot of current while printing, so use a separate supply rated for the printer and connect its ground to the Arduino ground.

What baud rate should I use?

This example uses 9600 baud. Some printers default to a different rate, so check the datasheet or the self-test printout and match it in Serial.begin().

Why does the printed text look different from what I expected?

The ESC ! n byte controls bold, height, width and font. Different values give different styles, and not all printers treat every bit in the same way. Try other values and compare against your printer’s command list.

See also
COMPLEMENTARY PWM

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works