Difficulty Level: Intermediate
This project will show you how to connect and read multiple analog sensors using an Arduino. You can use sensors such as potentiometers, light-dependent resistors (LDRs), or temperature sensors and display their data in the serial monitor.
Follow these steps to connect three analog sensors to your Arduino:
Analog sensors output a voltage signal that varies based on the environmental condition they measure (like light intensity or temperature). The Arduino reads these voltages and converts them to digital values ranging from 0 to 1023 using its built-in ADC (Analog to Digital Converter).
This Arduino code reads the values from three analog sensors connected to pins A0, A1, and A2. The values are displayed in the serial monitor for each sensor.
// Define the analog input pins
int sensor1Pin = A0;
int sensor2Pin = A1;
int sensor3Pin = A2;
void setup() {
// Start serial communication for debugging
Serial.begin(9600);
}
void loop() {
// Read the values from the analog sensors
int sensor1Value = analogRead(sensor1Pin);
int sensor2Value = analogRead(sensor2Pin);
int sensor3Value = analogRead(sensor3Pin);
// Print the values to the Serial Monitor
Serial.print("Sensor 1 Value: ");
Serial.print(sensor1Value);
Serial.print(" | Sensor 2 Value: ");
Serial.print(sensor2Value);
Serial.print(" | Sensor 3 Value: ");
Serial.println(sensor3Value);
// Wait before the next reading
delay(500);
}
The analogRead()
function is used to read the values from each analog sensor. Since the Arduino has a 10-bit ADC, the output value ranges from 0 to 1023, where 0 represents 0V and 1023 represents 5V.
You can modify the code to include more sensors if needed, by simply adding more analogRead()
functions for additional analog pins (A3, A4, etc.).
Reading multiple analog sensors with an Arduino opens up endless possibilities for sensor-based projects. You can measure various environmental factors and react accordingly, making this a core concept for advanced projects like home automation, environmental monitoring, or robotics.