3

Is it possible to use digital pin 6 (PD6_PCINT22/AIN0) to read an analog voltage with analogRead()?

According to the ATMega datasheet, this should be possible.

If yes how is it done ? (pin configuration)

Avamander
6242 gold badges11 silver badges35 bronze badges
asked Oct 8, 2015 at 9:59

2 Answers 2

3

That is not possible. AIN0 is an input to the analog comparator, not the analog-to-digital converter. Only ADC0 through ADC8 (connected to the internal temperature sensor), the 1.1V reference, and ground can be connected to the ADC.

answered Oct 8, 2015 at 10:16
1

Maybe. The Arduino board contains a 6 channel (8 channels on the Mini and Nano, 16 on the Mega) and the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega).

As you can see in the image below the pin PD6 is not an analog input. To be an analog pin it should be write ADCx, like the PC0..5.

enter image description here

So, if you are not using and Arduino Uno you can't use PD6 as analog input but you can use PC0..5.

To read an analog value using analogRead() method you can do like this:

int analogPin = 3; 
int val = 0; // variable to store the value read
void setup()
{
 Serial.begin(9600); // setup serial
}
void loop()
{
 val = analogRead(analogPin); // read the input pin
 Serial.println(val); // debug value
}
answered Oct 8, 2015 at 14:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.