Reading Analog Values with Arduino Nano Multiplexer
How to Read Analog Values from a 12-Channel IR Sensor Array using an Arduino Nano |
This tutorial will guide you through the process of reading analog values from a 12-channel IR sensor array using an Arduino Nano and a 16-channel multiplexer module. This project is perfect for robotics enthusiasts or those exploring electronics. |
Hardware Requirements |
- Arduino Nano
- 16-channel 74HC4067 multiplexer module
- Breadboard
- 12-channel IR sensor array (custom-made or ordered)
|
Connections |
- Place the Arduino Nano on the breadboard.
- Connect the 5-volt output pin of the Arduino to the positive rail of the breadboard, and the ground pin to the negative rail.
- Place the multiplexer module on the breadboard.
- Connect the VCC pin of the module to the positive rail, and the ground pin to the negative rail.
- Connect the enable pin of the multiplexer to the negative rail to activate it.
- Connect the multiplexer signal pin to one of the Arduino's analog pins according to the pin mapping table.
- Connect the sensor pins to the multiplexer's output pins from 0 to 11 in sequence.
- Finally, connect the sensor ground to the breadboard's negative rail and the sensor VCC to the positive rail.
|
Software Requirements |
|
Code Explanation |
-
- Create an array named sensor of size 12 to store the analog readings for up to 12 channels from the multiplexer.
- Initialize serial communication at a baud rate of 9600 for debugging purposes.
- Configure the single pin connected to the Arduino as an output to control the multiplexer.
- The select channel function configures the multiplexer to select the desired channel by setting the control pins based on the binary representation of the channel number.
|
Code |
const int signalPin = A0; // Define the signal pin
int sensor[12]; // Create an array to store analog readings
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(signalPin, OUTPUT); // Configure the signal pin as an output
}
void loop() {
for (int i = 0; i < 12; i++) { // Iterate through channels 0 to 11
selectChannel(i); // Select the channel on the multiplexer
sensor[i] = analogRead(signalPin); // Read the analog signal from the selected channel and store it in the sensor array
Serial.print(sensor[i]); // Print the sensor reading for the current channel to the serial monitor
Serial.print(" "); // Separate readings with spaces
}
Serial.println(); // New line after readings for all channels are sent
}
void selectChannel(int channel) {
// Configure the multiplexer to select the desired channel by setting the control pins based on the binary representation of the channel number
}
|
Testing and Results |
Open the serial monitor to display the sensor values. When you keep your hand on the sensor, the value will be less than 100. Otherwise, the value will be greater than 800 or 900.
You can extend the channel up to 16 channels by changing the code.
|
What is Arduino? |
Arduino is an open-source electronics platform that allows users to create interactive electronic projects. |
Background |
The Arduino project was started in 2003 by Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino, and David Mellis at the Interaction Design Institute Ivrea in Italy. The goal of the project was to create a platform that would make it easy for people with little or no electronics experience to build interactive electronic projects. |
Key Features |
The Arduino platform consists of a microcontroller board, a programming language, and an integrated development environment (IDE). The board is equipped with digital and analog input/output pins that allow users to connect sensors, actuators, and other devices. |
Programming Language |
The Arduino programming language is based on C/C++ and provides a simple syntax for beginners. The language includes libraries for interacting with hardware components such as LEDs, buttons, sensors, and motors. |
IDE |
The Arduino IDE is a free software application that allows users to write, compile, and upload code to the Arduino board. The IDE includes features such as code completion, debugging, and serial monitoring. |
Community |
The Arduino community is active and large, with millions of users worldwide. The official Arduino website provides documentation, tutorials, and examples to help users get started with their projects. |
Applications |
Arduino boards are used in a wide range of applications including robotics, home automation, wearable technology, and art installations. The platform is also popular among hobbyists, students, and professionals who want to create interactive electronic projects. |
Introduction |
In this article, we will explore the concept of reading analog values using an Arduino Nano and a multiplexer. A multiplexer (or mux) is a device that allows multiple input signals to be transmitted over a single output channel. This can be useful in situations where there are more sensors than available analog input pins on the microcontroller.
|
Hardware Requirements |
To follow along with this article, you will need:
- An Arduino Nano board
- A multiplexer module (such as the CD74HC4067)
- Multiple analog sensors (such as potentiometers or light-dependent resistors)
- Jumper wires and a breadboard for connection
|
Multiplexer Basics |
A multiplexer is essentially an electronic switch that allows multiple input signals to be directed to a single output. In the context of reading analog values with Arduino, we can use a multiplexer to connect multiple sensors to a single analog input pin.
The CD74HC4067 is a 16-channel multiplexer module that can be controlled using four digital pins on the Arduino. By setting these control pins high or low, we can select which of the 16 inputs is connected to the output.
|
Connecting the Multiplexer |
To connect the multiplexer module to your Arduino Nano, follow these steps:
- Connect the VCC pin on the multiplexer to the 5V pin on the Arduino.
- Connect the GND pin on the multiplexer to a GND pin on the Arduino.
- Connect the S0-S3 pins on the multiplexer to digital pins 2-5 on the Arduino (respectively).
- Connect the analog sensors you wish to read from to the input channels on the multiplexer (e.g. CH0, CH1, etc.).
|
Reading Analog Values with Arduino |
To read analog values from the sensors connected to the multiplexer, you can use the following code:
const int muxS0 = 2; // S0 pin on the multiplexer
const int muxS1 = 3; // S1 pin on the multiplexer
const int muxS2 = 4; // S2 pin on the multiplexer
const int muxS3 = 5; // S3 pin on the multiplexer
const int analogInPin = A0; // Analog input pin on the Arduino
void setup() {
pinMode(muxS0, OUTPUT);
pinMode(muxS1, OUTPUT);
pinMode(muxS2, OUTPUT);
pinMode(muxS3, OUTPUT);
}
void loop() {
for (int i = 0; i < 16; i++) { // Loop through each of the 16 channels
// Set the control pins to select the current channel
digitalWrite(muxS0, bitRead(i, 0));
digitalWrite(muxS1, bitRead(i, 1));
digitalWrite(muxS2, bitRead(i, 2));
digitalWrite(muxS3, bitRead(i, 3));
// Read the analog value from the selected channel
int sensorValue = analogRead(analogInPin);
// Print the result to the serial monitor
Serial.print("Channel ");
Serial.print(i);
Serial.print(": ");
Serial.println(sensorValue);
delay(100); // Wait 100ms before moving on to the next channel
}
}
|
Conclusion |
In this article, we have demonstrated how to use a multiplexer module with an Arduino Nano to read analog values from multiple sensors. This can be a useful technique for projects where there are more sensors than available analog input pins on the microcontroller.
|
Q1: What is an analog value in the context of Arduino Nano? |
An analog value refers to a continuous signal that can have any value within a certain range, typically between 0 and 1023 for Arduino's 10-bit ADC. |
Q2: What is the purpose of a multiplexer in reading analog values with Arduino Nano? |
A multiplexer allows multiple analog input signals to be connected to a single analog input pin on the Arduino, enabling the board to read multiple analog values sequentially. |
Q3: Which IC is commonly used as a multiplexer for reading analog values with Arduino Nano? |
The CD74HC4067 or the 4051 are popular choices for analog multiplexers when working with Arduino. |
Q4: How many analog input pins does the Arduino Nano have? |
The Arduino Nano has 8 analog input pins (A0-A7) that can be used to read analog values. |
Q5: What is the maximum resolution of the Arduino's built-in ADC? |
The maximum resolution of the Arduino's built-in ADC is 10 bits, which means it can produce 1024 (2^10) different output values. |
Q6: What is the typical voltage range for analog input on Arduino Nano? |
The typical voltage range for analog input on Arduino Nano is between 0V and 5V, but it can be modified depending on the reference voltage used. |
Q7: Can multiple analog inputs be read simultaneously with a multiplexer? |
No, when using a multiplexer, analog inputs are typically read sequentially, one at a time, due to the nature of how the multiplexer switches between input channels. |
Q8: What is the purpose of the 'analogRead' function in Arduino? |
The 'analogRead' function reads the value from a specified analog pin and returns an integer value between 0 and 1023 representing the voltage measured. |
Q9: How does the multiplexer select which analog input to read? |
The multiplexer selects which analog input to read based on digital signals applied to its control pins, usually following a binary pattern (e.g., A0, A1, and sometimes A2 for 3-8 channel mux). |
Q10: Can the Arduino Nano's analog inputs be used with external voltage references? |
Yes, the Arduino Nano allows the use of an external voltage reference for its analog inputs by connecting it to the AREF pin and setting the appropriate mode using 'analogReference' function. |
Rank |
Pioneers/Companies |
Contribution |
1 |
Arduino |
Developed the Arduino Nano board, a popular platform for reading analog values with multiplexers. |
2 |
Texas Instruments (TI) |
Manufacturers of the CD74HC4067, a widely used analog multiplexer/demultiplexer IC. |
3 |
NXP Semiconductors |
Developed the 74HC4051, a high-speed analog multiplexer/demultiplexer IC. |
4 |
Microchip Technology |
Manufacturers of the MCP23017, a popular I2C-based analog multiplexer IC. |
5 |
STMicroelectronics (STM) |
Developed the MUX16, a high-performance analog multiplexer IC. |
6 |
ON Semiconductor |
Manufacturers of the FSA3157, a high-speed analog multiplexer/demultiplexer IC. |
7 |
Analog Devices (ADI) |
Developed the ADG619, a precision analog multiplexer IC. |
8 |
Maxim Integrated Products |
Manufacturers of the MAX306, a high-speed analog multiplexer/demultiplexer IC. |
9 |
Linear Technology Corporation (LTC) |
Developed the LTC1385, a high-performance analog multiplexer IC. |
10 |
Intersil Corporation (ISIL) |
Manufacturers of the EL5220, a high-speed analog multiplexer IC. |
Component |
Description |
Pins Used |
Technical Details |
Arduino Nano |
Microcontroller board based on ATmega328P |
VIN, GND, A0-A7, D2-D13 |
Operating Voltage: 5V; Operating Temperature: -40°C to +85°C; Flash Memory: 32 KB |
74HC4051 Multiplexer |
8-channel analog multiplexer/demultiplexer |
S0-S2, S, EN, VCC, GND |
Operating Voltage: 2-6V; Switching Time: 200 ns typical; On-State Resistance: 70 Ohms typical |
Analog Sensors (e.g., Potentiometers, Thermistors) |
Varying analog voltage output based on physical parameter changes |
Variable (connected to MUX inputs) |
Resolution and sensitivity vary by sensor type; typically 10-bit resolution for Arduino ADC |
Jumper Wires |
Connecting pins between components |
Variable (connecting Arduino, MUX, and sensors) |
Standard AWG24 or AWG26 gauge; typically used for signal connections |
Breadboard |
Prototyping platform for component assembly |
N/A (physical base only) |
Standard breadboard size: 84 rows x 2 columns; compatible with DIP and SMT components |
Connections |
Description |
Pins Used |
Arduino Nano VIN to Breadboard Power Rail |
Power supply for Arduino and components |
VIN |
74HC4051 VCC to Breadboard Power Rail |
Power supply for MUX |
VCC |
Analog Sensors to 74HC4051 Inputs (S0-S7) |
Analog voltage inputs from sensors to MUX |
S0-S7 |
74HC4051 Output (S) to Arduino Nano Analog Input (A0-A7) |
Analog voltage output from MUX to Arduino ADC |
A0-A7 |
Arduino Nano Digital Outputs (D2-D13) to 74HC4051 Select Lines (S0-S2) |
Digital control signals for MUX channel selection |
D2-D13, S0-S2 |
Arduino Code Snippet |
Description |
const int muxSelectPins[] = {2, 3, 4}; // S0-S2 pins
void setup() {
pinMode(muxSelectPins[0], OUTPUT);
pinMode(muxSelectPins[1], OUTPUT);
pinMode(muxSelectPins[2], OUTPUT);
} |
Set up MUX select lines as digital outputs |
void loop() {
int channel = 0; // Select MUX channel
digitalWrite(muxSelectPins[0], (channel & 1));
digitalWrite(muxSelectPins[1], ((channel >> 1) & 1));
digitalWrite(muxSelectPins[2], ((channel >> 2) & 1));
int sensorValue = analogRead(A0); // Read analog value from MUX output
Serial.println(sensorValue);
} |
Select a MUX channel and read the corresponding analog voltage |
|