To acquire an analog signal using an Arduino, you can use the analog input pins, which are labeled A0 to A5. The following steps can be taken to read an analog signal:
- Connect the analog signal to one of the analog input pins.
- Use the
analogRead()
function to read the analog signal. The function takes the analog input pin number as an argument and returns a value between 0 and 1023. - Convert the 10-bit value to a voltage by multiplying it by 5 and dividing it by 1023.
Example code:
int analogPin = A0; // select the input pin for the analog signal
int sensorValue = 0; // variable to store the value read from the sensor
void setup() {
Serial.begin(9600); // initialize serial communication
}
void loop() {
sensorValue = analogRead(analogPin); // read the analog signal
Serial.println(sensorValue); // print the value to the serial monitor
delay(100); // wait for 100ms
}
The voltage level of the analog signal should be within the range that the analog input pin can handle, which is typically 0 to 5V.
Connection diagram: