Reading Analog Input W/Arduino Uno PCB

I am using an Arduino Uno PCB powered by a USB port on my laptop to read a 0-2VDC analog input signal. However, when the analog input signal gets to approx. 1.2VDC the A/D appears to read and over-range value, as the readings on my serial monitor freezes and stop increasing.

Does anyone know why this would occur?

I thought the A/D on the Arduino Uno was capable of reading a 0-5VDC analog input.

It is well capable of measuring in the signal range you want (0-2V) but without seeing your code and without seeing your wiring schematic it's nearly impossible to tell what is going wrong.

You seem to have selected the 1.1V ADC reference. Why?

I did not willingly/knowingly select the 1.1V ADC reference. How would I got about changing the ADC reference to 5V.

Post the code you are using and the connection diagram as has already been asked. There's not much point us all wasting time trying to guess what you might have done and so what you need to change.


Below is the connection diagram between the Arduino PCB and the board that I am testing as well as the test code being used.

// Pin definitions
const int PWM = 9;
const int SCLK = 3;
const int DISC = 4;
const int LED = 5;
const int VADC = A0;

unsigned int ton_clocks = 24;
unsigned int toff_clocks = 4000;
unsigned int loopCount = 0;

// Initialization
void setup()
  // Initialize I/O pins
  digitalWrite(LED_BUILTIN, LOW);

  pinMode(PWM, OUTPUT);
  digitalWrite(PWM, LOW);

  pinMode(SCLK, OUTPUT);
  digitalWrite(SCLK, HIGH);

  pinMode(DISC, OUTPUT);
  digitalWrite(DISC, LOW);
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);

  // Disable interrupts during timer setup

  // Initialize timer1 (PWM)
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;
  TCCR1A |= (1 << COM1A1);  // Clear OC1A on compare match, set at BOTTOM
  TCCR1A |= (1 << WGM11);   // Fast PWM mode, TOP = ICR1
  TCCR1B |= (1 << WGM12) | (1 << WGM13);
  OCR1A = ton_clocks;               // PWM on-time (in clocks)
  ICR1 = toff_clocks + ton_clocks;  // PWM period (in clocks)
  TIMSK1 |= (1 << TOIE1);   // Enable overflow interrupt
  TCCR1B |= (1 << CS10);    // Start timer, no prescaling

  // Enable interrupts

// Timer1 overflow ISR
  // Update the PWM period
  ICR1 = toff_clocks + ton_clocks;  // PWM period (in clocks)

// Main loop
void loop()
  // Drive SCLK low for at least 5 ms (activate sampling circuit)
  digitalWrite(SCLK, LOW);

  // Sample the ADC voltage
  float VADC_voltage = analogRead(VADC) * (5.f / 1023.f);
  float Vcap = -213.48f*VADC_voltage;
  // Enforce the upper bound for toff by checking the cap voltage directly
  // This avoids a potential divide-by-zero condition
  if (abs(Vcap) < 1.43)
    toff_clocks = 250*16;
    toff_clocks = (unsigned int)(16.f * (297.f / abs(Vcap)));
  // Also enforce a lower bound for off time (just to be safe).Val of 11 clkcycs=0.69us min off-time
  if (toff_clocks < 10)
    toff_clocks = 10;

  // Check if we've reached the target voltage or not (-400VDC)
  if (Vcap < -400.f)
    // If so, disable the PWM output
    digitalWrite(PWM, LOW);
    TCCR1A &= ~(1 << COM1A1);
    digitalWrite(LED, HIGH);
  else // Otherwise enable the PWM output
    TCCR1A |= (1 << COM1A1);
    digitalWrite(LED, LOW);

  // Drive SCLK high (done sampling)
  digitalWrite(SCLK, HIGH);

  // Wait to sample again

  // Discharge the capacitors every so often
  if (loopCount >= 150)
    loopCount = 0;

    // Reset toff to ensure we don't saturate the transformer primary
    toff_clocks = 250*16;
    digitalWrite(DISC, HIGH);
    digitalWrite(LED_BUILTIN, HIGH);
    digitalWrite(DISC, LOW);
    digitalWrite(LED_BUILTIN, LOW);

Please confirm:

You use an Uno, not any homebrew PCB?
You have selected the Uno board for compilation?
You have nothing connected to AREF?
What's the AREF voltage?
What if you run one of the basic analog input examples?

  1. Yes, I have an Uno PCB.
  2. Yes, I selected Uno for Compilation.
  3. When I first started out I had nothing connected to AREF. Then I later tried connecting 5VDC to AREF but I got the same results. My ADC readings still over-ranged at 1.2V.
  4. Explained in #3 above.
  5. I have already tried a basic analog input test, where I feed one of the ADC inputs on the Arduino with an external power supply. I tried this test with and without a voltage connected to AREF and I got the same result for both test cases. In both test cases, the (+) side of the Ext. PS connected to the ADC input pin (A0) while (-) side of the Ext. PS connected to a GND pin on the Arduino. During both of these tests, the Arduino was powered by the USB port on my laptop. I assumed that all the grounds on the are tied together in the artwork of the Aduino PCB.

Insert this line right after, // Sample the ADC voltage:


See what the ADC value is.

If you now measure the voltage on the bare AREF pin, what's the value? Perhaps you damaged something during previous experiments?

Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

What is the 0 - 2V source?
Is this your code, or a code you have adapted?
What is the application?

Hows about knocking your test code back to just reading the analog input?
If you wrote this code, did you write it in stages, getting each stage to work, before going to the next.
If so, you should have a bit of code, just reading and scaling the analog input.


  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);

  // Disable interrupts during timer setup

Might be better as;

  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);

  // Disable interrupts during timer setup

Are you measuring the voltage that is applied to the analog input terminal of the UNO?

Tom... :slight_smile: