Keypad + Display system that shows user input and sends the number to a database

The purpose of this project is to allow operators to enter in a number, then have that number sent over to a secure database as well as printed on the OLED Screen. This process is ideal for one or two systems, but if the process needs to be replicated I recommend getting a ribbon cable to connect the pins of the ESP32 to the pins of the keypad. 


On the main test machines, there is a computer installed that lets an operator control the settings. Along with that, it displays a number, called the R and D number, that keeps track of the test we are running for a specific machine. However, the non-main test machines (ovens, drill presses, etc) assist with the testing process but do not have a computer displaying or a way of tracking the corresponding R and D number. This system will allow an operator to enter a 5-digit R and D number, have it displayed on the screen and have that number sent over the network to the database. 

Each pin on the keypad corresponded to a specific row or column. Then it was connected to the GPIO pins of the ESP32 so the microcontroller can accept user input. Then, the ESP32 sends the data over to the OLED screen through I2C and SPI connections. It also powers the OLED screen with 3V and GND connections.  Also, there is an added "clear screen feature" so when the 'A' key is pressed the screen is cleared allowing for additional user input. 

MicrosoftTeams-image (3).png

Prototype of the system

        /* Program used to take user input from 4x4 matrix keypad and output it to OLED using ESP32 board */
/* Also, sends the number to the database */ 
#include "Keypad.h"
#include "Arduino.h"
#include <WiFi.h>
#include <PubSubClient.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "WiFi.h"

const char* ssid       = "Ball";
const char* password   = "Nick";
const char* broker_ip = "";

/* instatiate wifi, mqtt clients */
WiFiClient wifi_client;
PubSubClient mqtt_client(wifi_client);

/* Setting up the keypad */
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns

char keys[ROWS][COLS] = {

/* For ESP32 Microcontroller */
byte rowPins[ROWS] = {15, 32, 14, 21}; 
byte colPins[COLS] = {13, 12, 27, 33};

Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); // instantiating a keypad object 

/* callback function for mqtt connection- called when a new message is received
 * for a topic that we're subscribed to.*/
void mqtt_cb(char* topic, uint8_t *msg, uint32_t len){


/* handle a reconnect to the broker if the connection is dropped */
void mqtt_reconnect(void){
        Serial.printf("Connecting to broker '%s'...", broker_ip);
        if(mqtt_client.connect("R&D #")){
            Serial.println("\r\nRetrying in 5 seconds.");


void setup() {
  Serial.println("OLED FeatherWing test");
  /* SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally */
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32

  Serial.println("OLED begun");

  /* Show image buffer on the display hardware. */
  /* Since the buffer is intialized with an Adafruit splashscreen */
  /* internally, this will display the splashscreen. */

  /* Clear the buffer. */

  Serial.println("IO test");

  /* text display tests */
  display.display(); // actually display all of the above

// connect to WiFi
  Serial.printf("Connecting to '%s'...", ssid);

  WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
    Serial.println(" CONNECTED");

  /* initialize (but don't connect yet) to the MQTT broker */
  mqtt_client.setServer(broker_ip, 1883);


void loop() {
  char key = keypad.getKey();


   /* handle/maintain the MQTT connection, including any new messages */

  if (key == 'A'){
  } else if (key) {

    char msg[4]; // stores R&D # in an string
    snprintf(msg, 4, "%d", key);
    mqtt_client.publish("R & D Number: ", msg); // sends it to database
Keypad Setup.PNG

Electrical Diagram of Prototype

MicrosoftTeams-image (7).png

System on protoboard


3D model of enclosure for the board

Nick Khormaei