When ARDUINO MET JULIA: E#2 Bridging the ...

When ARDUINO MET JULIA: E#2 Bridging the Physical and Digital – Building an Arduino Powere

Apr 21, 2026

Disclaimer: This post is not a paid promotion and is not intended to influence the choice of one programming language over another. The intent is solely to add value to the engineering and maker community by sharing author’s personal understanding and practical experience with these tools.


In our last chapter, we set up Julia and established how to give this math-heavy powerhouse the ability to “talk” to the physical world using the LibSerialPorts package. But in real-world test and measurement environments, a terminal output isn’t always enough. Whether you are building a custom UI to trigger a data acquisition system, inputting parameters for a predictive model, or just controlling a complex IoT array, a web dashboard is often the best way to interact with your backend logic.

Today, we are going to bridge the physical and the digital. We will build a simple hardware interface an Arduino powered matrix keypad and connect it to a live web dashboard built entirely in Julia.

Step 1: The Hardware Setup (Arduino)

For the physical side, we are keeping it classic and reliable. We’ll use a standard 4×3 Matrix Keypad (the classic telephone layout) and an Arduino Uno (or Nano).

Wiring: A 4×3 keypad has 7 pins. Connect them to digital pins 2 through 8 on your Arduino. (Pins 2-5 for the four rows, and pins 6-8 for the three columns).

The Arduino Code: We will use the standard Keypad.h library to read the key presses and push them over the Serial port. Upload this C++ sketch to your board:

#include <Keypad.h>
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns

// Define the standard 4x3 layout

char keys[ROWS][COLS] = {

{'1','2','3'},

{'4','5','6'},

{'7','8','9'},

{'*','0','#'}

};

// Connect keypad ROW1, ROW2, ROW3 and ROW4 to these Arduino pins.

byte rowPins[ROWS] = {2, 3, 4, 5}; 

// Connect keypad COL1, COL2, and COL3 to these Arduino pins.

byte colPins[COLS] = {6, 7, 8}; 

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {

Serial.begin(9600); // Ensure this matches our Julia baud rate

}

void loop() {

char key = keypad.getKey();

// If a key is pressed, send it over the serial port

if (key) {

Serial.println(key);

}

}

Explanation

This code sets up an Arduino to read a 4×3 matrix keypad and send the pressed keys to a computer. It starts on line 1 by including the Keypad.h library, which handles the complex logic of scanning the keypad grid. Lines 3 and 4 define the hardware dimensions as 4 rows and 3 columns, while lines 7 through 12 map this physical grid to a 2D character array called keys, assigning specific characters (like ‘1’, ‘5’, or ‘#’) to their respective buttons. To connect the software to the hardware, lines 15 and 17 specify that the keypad’s row wires plug into Arduino digital pins 2, 3, 4, and 5, and the column wires into pins 6, 7, and 8. On line 19, a Keypad object named keypad is instantiated using all these mapped configurations, so the library knows exactly how to interpret the electrical signals. In the setup block (lines 21-23), line 22 initializes the USB serial connection at a speed of 9600 baud so the Arduino can communicate outward. Finally, the continuously running loop function (lines 25-33) actively scans for presses: line 26 checks for an active button press and stores it in the key variable, and the if statement on lines 29-31 ensures that if a valid key is detected, line 30 immediately transmits that character over the serial port using Serial.println(key)

Подобається цей допис?

Купити для Serin Thomas каву

Більше від Serin Thomas

КонфіденційністьУмовиПоскаржитись