Analog sensors, potentiometers, and other variable inputs require an Analog-to-Digital Converter (ADC) to be read by a microcontroller. With CodeCell, reading an analog signal is as simple as calling pinADC()
.
pinADC()
To read an analog value, use:
uint16_t myADC = myCodeCell.pinADC(uint8_t pin_num);
pin_num
→ The ADC pin you want to read from (IO1, IO2, or IO3).If you connect a potentiometer to IO2, you can read its position with:
uint16_t potValue = myCodeCell.pinADC(2);
Serial.println(potValue);
Since the maximum voltage on CodeCell’s ADC pins should not exceed 3.3V, you should connect the potentiometer to 3V3 instead of Vo:
3V3 → One end of the potentiometer
GND → Other end of the potentiometer
IO2 → Middle pin of the potentiometer
The onboard microcontroller uses a 2.5V internal voltage reference. This means:
To scale readings properly:
float voltage = (myCodeCell.pinADC(2) / 4095.0) * 2.5;
Serial.println(voltage);
pinADC()
Whether you're reading a potentiometer, sensor, or other analog signals, CodeCell makes ADC reading easy.
Join our Community ~ Be the first to know about new products and get exciting deals!
© 2025 Microbots.