Zarmond's Digital Bodyguard
Zarmond's Digital Bodyguard
What I wanted to learn, and why it interested me: I wanted to learn how to use the thermal receipt printers. I've seen these be used in interactive art pieces before but never knew how they worked or how I would integrate them into an Arduino build.
Final outcome: My final build is a "digital bodyguard". If you are too close, if I page my bodyguard (hit the button), it will tell you to back up. If you are a certain distance away (<20cm) and I page my bodyguard, it will tell you you're a good distance away and to stay there!
Images of final creative/exploratory output
The two possible outputs from the "page" button.
Video of my bodyguard in action!
Process images from development towards creative/exploratory output
All of my scrap receipts from my code not working :(
First trial of getting a bitmap to print! But the file needed to have thicker lines in order to show up on the paper...
Process and reflection:
I am very, very surprised at how long this took me to set up. I had many more issues than I expected-- particularly with learning how to implement bitmaps. I also had to end up changing my final project because I couldn't get nested if/else statements to work with the printer. This is something I hope to get to work more on figuring out because I think it would be cool to make a "choose your own adventure" style game! But, I ended up getting to make my second favorite idea, which was using data from an input source and using the printer to visualize it.
Technical details
Electrical schematic
/*Zarmond D. Goodman (azarrill)
60-223 - Intro to Physical Computing
Fall 2025
References:
https://learn.adafruit.com/mini-thermal-receipt-printer/overview
https://courses.ideate.cmu.edu/60-223/f2025/tutorials/ultrasonic-ranger
Arduino pin | role | details
------------------------------
6 input Arduino transmit YELLOW WIRE labeled RX on printer
5 input Arduino receive GREEN WIRE labeled TX on printer
A5 input trigger pin on ultrasonic ranger
A4 input echo pin on ultrasonic ranger
9 input tactile pushbutton
*/
#include <Adafruit_Thermal.h>
#include <SoftwareSerial.h>
#include <NewPing.h>
#define TX_PIN 6 // Arduino transmit YELLOW WIRE labeled RX on printer
#define RX_PIN 5 // Arduino receive GREEN WIRE labeled TX on printer
#define TRIGGER_PIN A5 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN A4 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 350 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial); // Pass addr to printer constructor
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
const int BUTTONPIN = 9;
void setup() {
pinMode(BUTTONPIN, INPUT_PULLUP);
mySerial.begin(9600); // Initialize SoftwareSerial communication
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
printer.begin(); // Initialize printer
}
void loop() {
int buttonState = digitalRead(BUTTONPIN);
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
int distance = sonar.ping_cm();
Serial.print("Ping: ");
Serial.print(distance); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm");
if(buttonState == LOW) {
if(distance > 20) {
printer.println("you're a good distance away from me. stay there.");
printer.println();
printer.println();
printer.println();
} else {
printer.println("girl, back up...");
printer.println();
printer.println();
printer.println();
}
}
}