Example Code for Arduino-GPIO Analog Read

Last revision 2026/01/08

This article showcases how to use Arduino's GPIO pins for reading analog signals with sample code, wiring instructions, and insights into ADC conversion using the Beetle RP2350 and an analog angle sensor.

Hardware Preparation

Wiring Diagram

Connection

Mainboard Pin name Module Pin name
Beetle RP2350 GND Analog Angle Sensor GND
Beetle RP2350 VCC Analog Angle Sensor VCC
Beetle RP2350 27 Analog Angle Sensor A

Sample Code

const int analogInPin = A1;  
int sensorValue = 0;        

void setup() {
  Serial.begin(9600);
}

void loop() {
  sensorValue = analogRead(analogInPin);
  Serial.println("sensor = ");
  Serial.println(sensorValue);
  delay(200);
}

Result

Open the serial monitor, you can see the window prints the current value of the angle sensor. Rotate the angle sensor, and the printed value changes accordingly.

Additional Information

ADC (Analog-to-Digital Converter, also known as A/D converter), is a way to convert analog signals into digital signals. Real-world analog signals, such as temperature, pressure, sound or images, etc., need to be converted into a more easily stored, processed and transmitted digital form. The ADC of Beetle RP2350 is 10-bit, with a maximum output value of 1023.

Was this article helpful?

TOP