controlar multiplexo con arduino

Controlling Multiplexers with Arduino: A Comprehensive Guide

By Matthew Jones
AD

Did you know that you can control a multiplexer (multiplexor) using an Arduino microcontroller? Multiplexers, or muxes, are versatile ICs that allow you to route multiple signals through a single line, becoming an essential tool for reducing the number of required connection pins. By leveraging Arduino's flexibility and simplicity, you can create efficient and dynamic multiplexer control systems for various applications. Let's delve into how you can control a multiplexer with Arduino.

Before we begin, ensure you have a basic understanding of multiplexers. They are data selectors that allow you to connect multiple inputs to a single output line. This is particularly useful when you need to control more inputs than the Arduino has output pins. By using a multiplexer, you can significantly minimize the number of required input pins.

Arduino Multiplexer Control Basics

To control a multiplexer with an Arduino, you'll need to know its pin configuration. Most multiplexers require at least two control signals: an Enable/Select pin and data pins (D0 to Dn). The Enable pin tells the multiplexer which data inputs are active, while the D pins carry the data to be sent.

AD
an electronic circuit with two controllers connected to it, and wires attached to the board
an electronic circuit with two controllers connected to it, and wires attached to the board
an electronic device with multiple wires connected to it and two other devices attached to the board
an electronic device with multiple wires connected to it and two other devices attached to the board
an electronic device is connected to several different devices and the diagram below shows how it works
an electronic device is connected to several different devices and the diagram below shows how it works

For this guide, let's assume you're using a 74HC595, an 8-channel, positive-logic, serial-in-parallel-out shift register/multiplexer. The 74HC595 has a sole Enable pin (ST_CP) and uses a serial data pin (DS) for shifting data.

Setting up the Arduino and Multiplexer

First, connect your Arduino and multiplexer as follows:

CodeProject
CodeProject
controle app celular
controle app celular
Best Arduino Simulators- – Perfect for Testing Your Code!
Best Arduino Simulators- – Perfect for Testing Your Code!
  • Arduino GND to 74HC595 GND
  • Arduino 5V to 74HC595 VCC
  • Arduino digital pin 2 to 74HC595 DS (Data)
  • Arduino digital pin 3 to 74HC595 ST_CP (Storage Clock)
  • Connect the 74HC595 output pins (QA to QH) to your desired targets.

Coding Arduino Multiplexer Control

Now, let's write an Arduino sketch to control the multiplexer. We'll use the bitSet() and bitClear() functions to manipulate the data and ST_CP pins.

Here's a simple Arduino sketch demonstrating multiplexer control:

AD
```cpp const int DATA_PIN = 2; const int ST_CP_PIN = 3; void setup() { pinMode(DATA_PIN, OUTPUT); pinMode(ST_CP_PIN, OUTPUT); } void loop() { // Output data on multiplexer pins (QA to QH) for (int i = 0; i < 8; i++) { digitalWrite(ST_CP_PIN, LOW); bitSet(PORTB, i); // Set data pin high digitalWrite(ST_CP_PIN, HIGH); delay(100); // Adjust delay according to your needs bitClear(PORTB, i); // Set data pin low } } ```

This code sends 8-bit data patterns to the multiplexer, toggling each output pin (QA to QH) high and low sequentially.

IR Remote Control of 5V 4 Channel Relay.
IR Remote Control of 5V 4 Channel Relay.
Arduino NERF Ball Wireless FPV Sentry Turret
Arduino NERF Ball Wireless FPV Sentry Turret
Control con relés por interfaz serie: Domótica (2) | Robots Didácticos
Control con relés por interfaz serie: Domótica (2) | Robots Didácticos
Arduino Project Hub
Arduino Project Hub
the wiring for an arduino wireless sensor and control system, with two wires connected to
the wiring for an arduino wireless sensor and control system, with two wires connected to
CONTROLA TU CASA DESDE EL CELULAR
CONTROLA TU CASA DESDE EL CELULAR

Expanding Complexity: Controlling Multiple Multiplexers

As your project grows, you might need to control multiple multiplexers. To do this, connect each multiplexer's Enable pin to a separate Arduino output pin and use the shiftOut() function instead of bit manipulation.

Here's a sketch controlling two 74HC595 multiplexers connected in cascade:

AD
```cpp #include const int DATA_PIN = 2; const int ST_CP_PIN = 3; const int MUX_ENABLE_PIN_1 = 4; const int MUX_ENABLE_PIN_2 = 5; ShiftOut data(DATA_PIN, MSBFIRST); void setup() { pinMode(DATA_PIN, OUTPUT); pinMode(ST_CP_PIN, OUTPUT); pinMode(MUX_ENABLE_PIN_1, OUTPUT); pinMode(MUX_ENABLE_PIN_2, OUTPUT); } void loop() { // Output data on multiplexers' pins (QA to QH) for (int i = 0; i < 16; i++) { digitalWrite(MUX_ENABLE_PIN_1, HIGH); digitalWrite(MUX_ENABLE_PIN_2, LOW); data.send(i); delay(100); // Adjust delay according to your needs digitalWrite(MUX_ENABLE_PIN_1, LOW); digitalWrite(MUX_ENABLE_PIN_2, HIGH); data.send(i); delay(100); // Adjust delay according to your needs } } ```

This sketch sends 16-bit data patterns to two cascaded 74HC595 multiplexers, toggling each output pin (QA to QH for both multiplexers) high and low sequentially.

Embracing Arduino multiplexer control opens up a world of possibilities for creating compact, efficient, and versatile electronics projects. As you grow more comfortable with this technique, consider exploring other Arduino-compatible microcontrollers, such as the ESP32 or ESP8266, for even more powerful and connected multiplexer control applications.

Multi Task Arduino UNO
Multi Task Arduino UNO
Hands-On Arduino Automation Learning Activity
Hands-On Arduino Automation Learning Activity
Build an Arduino powered MIDI Controller
Build an Arduino powered MIDI Controller
an electronic device with many components attached to it's board and on top of the machine
an electronic device with many components attached to it's board and on top of the machine
Joystick Module
Joystick Module
Programmable Arduino Remote Control
Programmable Arduino Remote Control
ARDUINO IR REMOTE (USE YOUR OLD REMOTE TO CONTROLL HOME APPLIANCES)
ARDUINO IR REMOTE (USE YOUR OLD REMOTE TO CONTROLL HOME APPLIANCES)
Arduino USB Button Box
Arduino USB Button Box
How to Use a Joystick Module with Arduino: From Wiring to Coding
How to Use a Joystick Module with Arduino: From Wiring to Coding
Arduino proyectos electronicos
Arduino proyectos electronicos
Arduino Ejemplos: Mando RC XboxRC24 con NRF24L01 – Transmisor (Parte 1)
Arduino Ejemplos: Mando RC XboxRC24 con NRF24L01 – Transmisor (Parte 1)
Arduino Based Dual Channel Digital Oscilloscope
Arduino Based Dual Channel Digital Oscilloscope
an electronic device with buttons and lights on it
an electronic device with buttons and lights on it
Make a Sticky-Note Fan with Arduino - Maker Challenge
Make a Sticky-Note Fan with Arduino - Maker Challenge
AD