Stable voltage reference for Arduino Nano

Hi guys, I'm building a small project with Arduino Nano. Basically i'm using analogRead() and analogWrite() to alter a signal from my.

So far so good, the circuit is working fine, all caps and resitors are OK but it seems to have a problem with reference voltage

I've tried using 7805 or 78L05 but the reference voltage still jumps from 4.98v to 5.02 . In my case this is a problem because even 0.1 volts can cause the engine to stop.

It seems that the internal reference voltage in the arduino is not 5.00 but something like 4.80-4.96... In that case this is not working since on two different arduinos the internal reference is different.

I found this function to measure the internal 1.1 reference voltage and calculate the Vin (Vin should work for me) https://github.com/cano64/ArduinoSystemStatus

Well if i change the Vcc voltage from 4.6 to 5.12 for example the internal 1.1 changes too . So in the end analogRead and analogWrite are not in the specifications .

So i want to read a sensor that is from 0 to 4.7 volts with high precision . ADC with 10bits is fine for me , but the reference volgate still bothers me. I don't want to use batteries .

Any ideas ? Maybe external voltage for reference or should tinker the 1.1 volt internal reference ?

Hi, and welcome to the forum.

mtrx: Hi guys, I'm building a small project with Arduino Nano. Basically i'm using analogRead() and analogWrite() to alter a signal from my.

From my what?

To measure a voltage, you basically calculate the voltage divider to output ~1volt max. Then you measure with 1.1volt Aref enabled.

Post your code (with code tags) if you want help with that. Leo..

Well if i change the Vcc voltage from 4.6 to 5.12 for example the internal 1.1 changes too .

I'm pretty sure the internal reference is much more stable.

So in the end analogRead and analogWrite are not in the specifications .

analogWrite() is a different story, and it's not really analog. ;)

wow that was fast :slight_smile:

Anyway i know the limitations of the analogWrite() and PWM problem so i used PWM.h to raise the frequency and smoother the output.

May main problem is reading the analog input.

Here is some snippet from my code. It is very simple
This one is for my ATTiny85 but is almost the same as Arduino Nano. They both suffer from the same problem

float MAP_IN_Volts= 0.000;
float FCD_OUT_Volts = 0.000;
//PIN ports po;l
int MAP_IN_PIN = 3;
int FCD_TO_ECU_PIN = 1;
float vCC = 0.000;
float CCC = 0.000;
float multp = 000;

long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX =  _BV(MUX3) | _BV(MUX2); // For ATtiny85                                                                                                                             

  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1100000L  / result; // Back-calculate AVcc in mV
  return result;
}



// Setup (Push reset to start from here)
void setup() {
  //Switch to external 5v reference
 

    pinMode (FCD_TO_ECU_PIN, OUTPUT);

  }


// the loop function runs over and over again forever
void loop() { 
  vCC = readVcc()/1000;
  CCC = vCC/256  ;
  // READ all the sensors 
  int MAP_IN_PIN_VALUE= analogRead(MAP_IN_PIN);
  MAP_IN_Volts = (MAP_IN_PIN_VALUE * vCC) / 1023.0;

  
  //If MAP sensor output is more than 4.34 volts then clamp the output to prevent FUEL CUT 
  if ((MAP_IN_Volts) >= 4.33) {
    multp = 4.33/CCC;
    analogWrite(FCD_TO_ECU_PIN,multp);

   
  }

  else {
    
     analogWrite(FCD_TO_ECU_PIN,MAP_IN_PIN_VALUE);
 
  }

  

}

edit : I’ve tried to change this line too
result = 1100000L

It is unacceptable to hard code the volt reference variables

And a little more info.

I have the same code in my car running for more than thousand miles . It is a simple voltage clamp . The main problem is that if the reference voltage changes , analogRead() shows different input and based on that my output sucks too.

If the voltage goes more than desired 4.34 then the car hits a fuel cut and the engine stops :) On boosted engines this is not an option.

I did this schematic before with analog OP amp but i want to use arduino for some more information and to alter more sensors in the car Crack, O2 , Throttle positioning sensor. All of them need to be accurate as much as possible .

If i need to simple the code it is just

pin1val = AnalogRead(Pin1); voltage = ((pin1val* 5.00)/1023);

But this is the ideal case when the reference voltage is 5.00. In my it is not and it is fluctuating between 4.98 and 5.02 (or in some cases more)

The internal reference isnt exactly precision and varies chip by chip. If you want real precision take an external reference from something like a mcp1525

I saw MCP1525 before but i was thinking that if i use it as Aref i can measure only 4.0X voltages without using voltage divider.