Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to turn Arduino into 16-bit IO port

By Ashutosh Bhatt March 26, 2024

In this project, we’ll design a 16-bit IO port (input-output port) library for Arduino. It’s possible to send direct 16-bit data to any Arduino board using this library. It connects any of Arduino’s 16 pins, so they work as a 16-bit IO port. 

First, you must select 16 pins from Arduino to combine as the 16-bit port and configure the data direction as input or output. The data direction is set by the character ‘O’ for output and ‘I’ for input.  

The library has five functions, as explained below. Two constructors create the port object(s). One object sends 16-bit digital output to the port pins, and another receives the 16-bit digital input from the port pins. One additional object alters or sets the port’s IO direction. 

The library’s functions
This library can interface any 16-bit device, such as ADC, DAC, MUX, or any other digital device, to receive 16-bit input or send 16-bit output. 

 Here are the library’s five functions: 

Here are the library’s five functions:

1. IO_Port_16bit(int pin1,int pin2,int pin3,int pin4,int pin5,int pin6,int pin7,int pin8,int pin9,int pin10,int pin11,int pin12,int pin13,int pin14,int pin15,int pin16, char dir)

This is the constructor. It creates the object(s) of this class and one or many 16-bit port(s) by combining specific Arduino pins. You must specify which Arduino pins to combine for the port and the data direction (input or output). The constructor’s last argument (“dir”) defines whether the port works as input or output.

  • If dir=’O,’ it means the port works as output
  • If dir=’I’, port works as input.

The same port cannot work as input and output, whether simultaneously or alternatively. If the data direction is not selected properly, you’ll see an error message.

2. IO_Port_16bit(int pin1,int pin2,int pin3,int pin4,int pin5,int pin6,int pin7,int pin8, int pin9, int pin10,int pin11,int pin12,int pin13,int pin14,int pin15,int pin16)

This is another constructor. It also creates the object(s) of this class and one or many 16-bit port(s) by combining specific Arduino pins. You must specify which Arduino pins to combine for the port. However, this constructor does not indicate the data direction as input or output. After creating the port object, you must set the port direction using the set_IO_direction function. This constructor lets a programmer alter the port data direction in run time, and the same port can work as input or output alternatively (but not simultaneously).

3. set_IO_direction(char dir)

This function specifies the input or output direction of a port. It has one character argument, which is ‘I’ for the input port and ‘O’ for the output port. If the data direction is not selected, it displays an error message on Arduino’s Serial Monitor.

4. send_16bit_data(unsigned int byt)

This function sends 16-bit data to the specified pins. It gives “int” data (must be < 65535) as an argument directly to Arduino’s 16 pins. If the data is > 65535, Arduino’s Serial Monitor displays an error message.

5. get_16bit_data(void)

This function receives 16-bit data from the specified pins. It returns 16-bit unsigned “int” data by reading the status of Arduino’s 16 pins

Example 1: Taking the 16-bit input and display it on Arduino’s serial monitor

#include <IO_Port_16bit.h>
IO_Port_16bit my16bitport(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17);
int i;
long input_double_byte;
void setup()
{
  // put your setup code here, to run once:
  my16bitport.set_IO_direction(‘I’);
  Serial.begin(9600);
}

void loop()
{
  input_double_byte = my16bitport.get_16bit_data();
  Serial.print(“input data: “);
  Serial.println(input_double_byte);
  delay(1000);
}

Example 2: The 16 LED chaser program

#include <IO_Port_16bit.h>
IO_Port_16bit my16bitport(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17);
void setup()
{
  // declare port direction as output specifying ‘O’
  my16bitport.set_IO_direction(‘O’);
}

void loop()
{
  unsigned int i;
  for(i=1;i<65535;i*=2)
    {
      my16bitport.send_16bit_data(i);    // send data as 2,4,8,16
      delay(200);                    // 32,..,..,…65534
    }
}

 

You may also like:

  • beginners guide
    Basic Electronics 01 – Beginners guide to setting up an…

  • How to design an Arduino library for an 8-bit IO…

  • CAN communication between PIC and Arduino

  • How to make HTTP requests using Arduino for the IoT

  • How to convert Arduino into a Modbus device

  • How to use Arduino’s analog comparator

Filed Under: Arduino Projects, Electronic Projects
Tagged With: Arduino, electronicproject, led, library
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Voltage mode pushpull is a nonsense SMPS?
  • Input impedance matching network
  • High Side current sensing
  • The comparison of different Tcl script checkers
  • Reducing "shoot-through" in offline Full Bridge SMPS?

RSS Electro-Tech-Online.com Discussions

  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe