Arduino Mega - Multi-Function Shield

If you own an Arduino Mega and want a fast way to experiment with displays, buttons, LEDs, a buzzer, and sensors — the Multi-Function Shield is the easiest option. This step-by-step guide covers everything you need:

Because the Arduino Mega's header layout is backward-compatible with the standard Uno pinout, the Multi-Function Shield slides right onto the Mega without jumper wires. The Mega gives you significantly more I/O pins, more memory, and additional serial ports — all while keeping full compatibility with this shield.

Arduino Mega Multi-Function Shield

Hardware Preparation

1×Arduino Mega
1×USB 2.0 cable type A/B (for USB-A PC)
1×USB 2.0 cable type C/B (for USB-C PC)
1×DIYables Multi-Function Shield
1×Recommended: Screw Terminal Block Shield for Arduino Uno/Mega
1×Recommended: Sensors/Servo Expansion Shield for Arduino Uno/Mega
1×Recommended: Breadboard Shield for Arduino Mega
1×Recommended: Enclosure for Arduino Mega

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of Multi-Function Shield

The Multi-Function Shield bundles six commonly used components into one plug-in board. No soldering, no breadboard, no mess. Here is what you get:

  • 4-Digit 7-Segment Display — Driven by a 74HC595 shift register. Shows integers, floats, uppercase letters, and special characters (such as °).
  • 3 Push Buttons (S1, S2, S3) — Active LOW inputs with internal pullups. The library debounces them automatically.
  • 4 LEDs (D1, D2, D3, D4) — Active LOW outputs. Supports on, off, toggle, and two blink modes.
  • Buzzer — Active LOW. Can beep for a set duration or after a programmable delay.
  • Potentiometer — Analog input on pin A0. Returns a raw count or a percentage value.
  • LM35 Temperature Sensor — Analog input on pin A4. Returns Celsius. Remove jumper J1 before use.

The pins used by the shield map identically on the Mega:

Function Pin Function Pin
LED D1 13 Button S1 A1
LED D2 12 Button S2 A2
LED D3 11 Button S3 A3
LED D4 10 Potentiometer A0
Buzzer 3 LM35 Temp Sensor A4
Display LATCH 4
Display CLOCK 7
Display DATA 8
Multi-Function Shield Pinout

Wiring Diagram

Align the shield with the Mega's headers and push it down firmly. The shield occupies the same header rows as on the Uno, so the remaining Mega pins stay accessible for other projects.

The wiring diagram between Arduino Mega Multi-Function Shield

This image is created using Fritzing. Click to enlarge image

Installing the Library

  1. Connect your Arduino Mega to the computer via a USB cable.
  2. Open the Arduino IDE. Pick Arduino Mega or Mega 2560 as the board and choose the correct port.
  3. Go to the Libraries panel on the left side.
  4. Search for "DIYables_MultiFuncShield". Find the entry from DIYables.
  5. Press Install.
Arduino Multi-Function Shield library

The library has zero external dependencies — it is completely self-contained.

Code Skeleton

Every Multi-Function Shield program follows the same two-function pattern:

#include <DIYables_MultiFuncShield.h> void setup() { MFS.begin(); // Initialize the shield hardware } void loop() { MFS.loop(); // Keep display, buttons, LEDs, buzzer running }

MFS.begin() sets up every component. MFS.loop() handles display multiplexing, button polling, blink scheduling, and buzzer timing. You must call both.

Code Example — 7-Segment Display

The sketch below cycles through several display modes: integers, zero-padded numbers, floats, text, dotted text, degree symbol, and dashes.

/* * This Arduino Mega code was developed by newbiely.com * * This Arduino Mega code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mega/arduino-mega-multi-function-shield */ /* * Multi-Function Shield - Display Example * * Cycles through display features every 3 seconds: * 1. Integer number * 2. Integer with leading zeros * 3. Float number * 4. Text string with letters * 5. Text string with dot * 6. Degree symbol + C (special chars) * 7. Dashes * * Hardware: DIYables Multi-Function Shield * * COMPATIBLE Multi-Function Shield: * - https://diyables.io/products/multi-function-shield-for-arduino-uno-mega * * TESTED HARDWARE: * - Arduino Uno R3 * - Arduino Uno R4 WiFi * - Arduino Uno R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3: https://diyables.io/stem-v3 * - DIYables STEM V4 IoT: https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT: https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu: https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3: https://diyables.io/atmega2560-board * - DIYables ESP32 S3, Uno-form factor: https://diyables.io/esp32-s3-uno * - It is expected to work with other boards */ #include <DIYables_MultiFuncShield.h> uint8_t step = 0; unsigned long lastUpdate = 0; void setup() { MFS.begin(); } void loop() { MFS.loop(); if (millis() - lastUpdate >= 3000) { lastUpdate = millis(); switch (step) { case 0: // Integer: " 42" MFS.display.print(42); break; case 1: // Integer with leading zeros: "0042" MFS.display.print(42, true); break; case 2: // Float with 2 decimals: "3.14" MFS.display.print(3.14, 2); break; case 3: // Text string: "HELP" MFS.display.print("HELP"); break; case 4: // Text with dot: "Ab.Cd" MFS.display.print("Ab.Cd"); break; case 5: // Degree + C using special chars: "25°C" MFS.display.clear(); MFS.display.setNumber(1, 2); MFS.display.setNumber(2, 5); MFS.display.setChar(3, SegChars::DEGREE); MFS.display.setChar(4, SegChars::C); MFS.display.show(); break; case 6: // Dashes: "----" MFS.display.print("----"); break; } step = (step + 1) % 7; } }

Steps to Upload

  • Mount the Multi-Function Shield on the Mega.
  • Plug the Mega into your computer.
  • In Arduino IDE, select the board and port, then paste the code.
  • Hit Upload.

Every 3 seconds the display switches to the next mode so you can see each format in action.

Display — Method Reference

Method Purpose Example
print(int) Render an integer MFS.display.print(42)
print(int, true) Render with leading zeros MFS.display.print(42, true) → 0042
print(float, dp) Render a float MFS.display.print(3.14, 2)
print(text) Render a string MFS.display.print("HELP")
setNumber(pos, val) Write a single digit (pos 1–4) MFS.display.setNumber(1, 5)
setChar(pos, ch) Write a character MFS.display.setChar(2, 'A')
setChar(pos, SegChars) Write a special symbol MFS.display.setChar(3, SegCharsDEGREE)
setDot(pos) Activate the dot segment MFS.display.setDot(2)
clear() Wipe the display MFS.display.clear()
show() Apply pending changes MFS.display.show()

print() calls show() for you. For manual composition, use clear()setNumber()/setChar()/setDot()show().

Special symbols available via SegChars: DASH, UNDERSCORE, C, E, F, DEGREE.

Code Example — Buttons

Read button events and send them to the Serial Monitor.

/* * This Arduino Mega code was developed by newbiely.com * * This Arduino Mega code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mega/arduino-mega-multi-function-shield */ /* * Multi-Function Shield - Buttons Example * * Detects button presses and releases, prints to Serial Monitor. * * Hardware: DIYables Multi-Function Shield * * COMPATIBLE Multi-Function Shield: * - https://diyables.io/products/multi-function-shield-for-arduino-uno-mega * * TESTED HARDWARE: * - Arduino Uno R3 * - Arduino Uno R4 WiFi * - Arduino Uno R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3: https://diyables.io/stem-v3 * - DIYables STEM V4 IoT: https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT: https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu: https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3: https://diyables.io/atmega2560-board * - DIYables ESP32 S3, Uno-form factor: https://diyables.io/esp32-s3-uno * - It is expected to work with other boards */ #include <DIYables_MultiFuncShield.h> void setup() { Serial.begin(9600); MFS.begin(); } void loop() { MFS.loop(); if (MFS.button1.isPressed()) Serial.println("Button 1 pressed"); if (MFS.button1.isReleased()) Serial.println("Button 1 released"); if (MFS.button2.isPressed()) Serial.println("Button 2 pressed"); if (MFS.button2.isReleased()) Serial.println("Button 2 released"); if (MFS.button3.isPressed()) Serial.println("Button 3 pressed"); if (MFS.button3.isReleased()) Serial.println("Button 3 released"); }

Steps to Upload

  • Paste the code and click Upload.
  • Open the Serial Monitor (9600 baud).
  • Press and release S1, S2, S3 to see events logged.

Buttons — Method Reference

Method Purpose
isPressed() True on the falling edge (button goes down)
isReleased() True on the rising edge (button comes back up)
setDebounceTime(ms) Change debounce period (default 50 ms)

Buttons are accessed as MFS.button1, MFS.button2, MFS.button3 or via the index helper MFS.button(1) to MFS.button(3). Debouncing and pullup configuration are handled internally.

Code Example — LEDs

Turn the LEDs on one after another, then blink all four simultaneously.

/* * This Arduino Mega code was developed by newbiely.com * * This Arduino Mega code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mega/arduino-mega-multi-function-shield */ /* * Multi-Function Shield - LEDs Example * * Demonstrates turn on, turn off, and blink for each LED. * * Hardware: DIYables Multi-Function Shield * * COMPATIBLE Multi-Function Shield: * - https://diyables.io/products/multi-function-shield-for-arduino-uno-mega * * TESTED HARDWARE: * - Arduino Uno R3 * - Arduino Uno R4 WiFi * - Arduino Uno R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3: https://diyables.io/stem-v3 * - DIYables STEM V4 IoT: https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT: https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu: https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3: https://diyables.io/atmega2560-board * - DIYables ESP32 S3, Uno-form factor: https://diyables.io/esp32-s3-uno * - It is expected to work with other boards */ #include <DIYables_MultiFuncShield.h> void setup() { Serial.begin(9600); MFS.begin(); // Turn on all LEDs one by one Serial.println("Turn ON LEDs one by one"); for (uint8_t i = 1; i <= 4; i++) { MFS.led(i).turnON(); delay(500); } delay(1000); // Turn off all LEDs one by one Serial.println("Turn OFF LEDs one by one"); for (uint8_t i = 1; i <= 4; i++) { MFS.led(i).turnOFF(); delay(500); } delay(1000); // Blink individual LED (LED 1 only) Serial.println("Blink LED 1 individually"); MFS.led(1).blink(300); unsigned long start = millis(); while (millis() - start < 3000) MFS.loop(); MFS.led(1).turnOFF(); delay(1000); // Blink all LEDs together Serial.println("Blink all LEDs together"); MFS.allLedsBlink(500); } void loop() { MFS.loop(); }

Steps to Upload

  • Paste the code and click Upload.

You will see D1 through D4 light up in order, followed by a synchronized blink pattern.

LEDs — Method Reference

Method Purpose
turnON() Light the LED
turnOFF() Extinguish the LED
toggle() Reverse the current state
blink(interval) Symmetric blink
blink(onTime, offTime) Asymmetric blink
isOn() Check whether the LED is currently lit

Group shortcuts on MFS:

Method Purpose
allLedsOn() All four LEDs on
allLedsOff() All four LEDs off
allLedsBlink(interval) Synchronized blink
allLedsBlink(onTime, offTime) Synchronized asymmetric blink

LEDs are active LOW. Address them as MFS.led1MFS.led4 or MFS.led(1)MFS.led(4).

Code Example — Buzzer

Sound a brief beep every two seconds.

/* * This Arduino Mega code was developed by newbiely.com * * This Arduino Mega code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mega/arduino-mega-multi-function-shield */ /* * Multi-Function Shield - Buzzer Example * * Beeps the buzzer every 2 seconds. * * Hardware: DIYables Multi-Function Shield * * COMPATIBLE Multi-Function Shield: * - https://diyables.io/products/multi-function-shield-for-arduino-uno-mega * * TESTED HARDWARE: * - Arduino Uno R3 * - Arduino Uno R4 WiFi * - Arduino Uno R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3: https://diyables.io/stem-v3 * - DIYables STEM V4 IoT: https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT: https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu: https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3: https://diyables.io/atmega2560-board * - DIYables ESP32 S3, Uno-form factor: https://diyables.io/esp32-s3-uno * - It is expected to work with other boards */ #include <DIYables_MultiFuncShield.h> unsigned long lastBeep = 0; void setup() { MFS.begin(); } void loop() { MFS.loop(); if (millis() - lastBeep >= 2000) { lastBeep = millis(); MFS.buzzer.beep(100); } }

Steps to Upload

  • Paste the code and click Upload.

You should hear a short beep repeated every 2 seconds.

Buzzer — Method Reference

Method Purpose
beep(ms) Sound the buzzer for a given duration
beep(ms, delayMs) Delay first, then beep
stop() Cut the buzzer immediately
isBeeping() True while the buzzer is sounding

Code Example — Potentiometer

Read the potentiometer and print the value and percentage to Serial.

/* * This Arduino Mega code was developed by newbiely.com * * This Arduino Mega code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mega/arduino-mega-multi-function-shield */ /* * Multi-Function Shield - Potentiometer Example * * Reads the potentiometer and shows the percentage on the display. * * NOTE: The potentiometer on the shield is a multi-turn trimmer. * You need to rotate it MANY turns to go from 0% to 100%. * If the value stays at 0% or 100%, rotate in the opposite direction. * * Hardware: DIYables Multi-Function Shield * * COMPATIBLE Multi-Function Shield: * - https://diyables.io/products/multi-function-shield-for-arduino-uno-mega * * TESTED HARDWARE: * - Arduino Uno R3 * - Arduino Uno R4 WiFi * - Arduino Uno R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3: https://diyables.io/stem-v3 * - DIYables STEM V4 IoT: https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT: https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu: https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3: https://diyables.io/atmega2560-board * - DIYables ESP32 S3, Uno-form factor: https://diyables.io/esp32-s3-uno * - It is expected to work with other boards */ #include <DIYables_MultiFuncShield.h> unsigned long lastUpdate = 0; float lastPct = -1; void setup() { Serial.begin(9600); MFS.begin(); Serial.println("Rotate potentiometer knob (multi-turn trimmer)."); Serial.println("It requires many turns to go from 0% to 100%."); } void loop() { MFS.loop(); if (millis() - lastUpdate >= 500) { lastUpdate = millis(); int raw = MFS.readPot(); float pct = MFS.readPotPercent(); Serial.print("Raw: "); Serial.print(raw); Serial.print(" Percent: "); Serial.print(pct, 1); Serial.print("%"); if (pct <= 0.1) Serial.print(" ← MIN (rotate clockwise to increase)"); else if (pct >= 99.9) Serial.print(" ← MAX (rotate counter-clockwise to decrease)"); Serial.println(); lastPct = pct; } }

Steps to Upload

  • Paste the code and click Upload.
  • Open the Serial Monitor.
  • Twist the knob and observe the live reading on the monitor.

Potentiometer — Method Reference

Method Returns Purpose
readPot() int Raw ADC count (0–1023 on Mega)
readPotPercent() float Normalized to 0.0–100.0 %

Code Example — Temperature Sensor (LM35)

Read the LM35 and show degrees Celsius on the display and Serial.

Note: You must remove jumper J1 before using the temperature sensor. Pin A4 doubles as the I2C SDA line, and the jumper connects it to I2C by default.

/* * This Arduino Mega code was developed by newbiely.com * * This Arduino Mega code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mega/arduino-mega-multi-function-shield */ /* * Multi-Function Shield - Temperature Example * * Reads the LM35 temperature sensor and shows Celsius on the display. * Note: Requires jumper J1 removed (pin A4). * * Hardware: DIYables Multi-Function Shield * * COMPATIBLE Multi-Function Shield: * - https://diyables.io/products/multi-function-shield-for-arduino-uno-mega * * TESTED HARDWARE: * - Arduino Uno R3 * - Arduino Uno R4 WiFi * - Arduino Uno R4 Minima * - Arduino Mega * - Arduino Due * - Arduino Giga * - DIYables STEM V3: https://diyables.io/stem-v3 * - DIYables STEM V4 IoT: https://diyables.io/stem-v4-iot * - DIYables STEM V4B IoT: https://diyables.io/stem-v4b-iot * - DIYables STEM V4 Edu: https://diyables.io/stem-v4-edu * - DIYables MEGA2560 R3: https://diyables.io/atmega2560-board * - DIYables ESP32 S3, Uno-form factor: https://diyables.io/esp32-s3-uno * - It is expected to work with other boards */ #include <DIYables_MultiFuncShield.h> unsigned long lastUpdate = 0; void setup() { Serial.begin(9600); MFS.begin(); MFS.display.print(0); } void loop() { MFS.loop(); if (millis() - lastUpdate >= 500) { lastUpdate = millis(); float temp = MFS.readTemperature(); MFS.display.print(temp, 1); Serial.print("Temp: "); Serial.print(temp, 1); Serial.println(" C"); } }

Steps to Upload

  • Remove jumper J1 first.
  • Paste the code, click Upload, and open the Serial Monitor.
  • The temperature is displayed in real time.

A 4-sample moving average ensures stable readings. The first call pre-fills the averaging buffer so there is no cold-start glitch.

Platform Support

The library supports all Arduino platforms (architectures=*).

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!