# Arduino Micro Comparator not working as expected

The following sketch will run on both the Arduino Micro and the Uno. However the behaviour is not the same.

``````int sensorValue = 0;

//let's set up the hardware
void setup() {

Serial.begin(9600);

//analogComparator.setOn(AIN0, A0);
//initialize the analog comparator (AC)
ACSR &= ~(1<<ACIE); //disable interrupts on AC
ACSR &= ~(1<<ACD); //switch on the AC
ACSR &= ~(1<<ACBG); //set pin AIN0
ADMUX &= ~31; //reset the first 5 bits

}

//main loop
void loop() {
if (ACSR & _BV(ACO))
{
Serial.println("high");
}
else
{
Serial.println("low ");
}

delay(500);
}
``````

To get the same behaviour the line
containing

``````  //sensorValue = analogRead(A0);
``````

needs to be uncommented for the Arduino Micro to allow the comparator output to be read.

I have two adjustable voltage sources connected to both boards, one to AIN0 the other to A0.
If AIN0 is set to about 2.5V and A0 is adjusted around that voltage I would expected to see “High” and “Low” as alternating outputs, depending on the timing of the voltage changes.
With the UNO no problem
With the Micro no change, unless the identified line is uncommented.

It would appear that the issue lies with a misunderstanding relating to pin outs between the Atmega32u4 and the Arduino Micro

``````ADMUX |= 0; //choose the ADC channel
``````

Selects ADC0 which is mapped to Ardunio Micro A5.

Moving the input voltage to A5 and it then works as expected.