Hi everybody, exuse me if I do some mistake with my english, i'm a french student.
I meet a weird problem, I put a voltage in the A1 pint (4.43V) and with a little program, I want to read this voltage on a LCD screen ' le deuligne / snootlab' shield.
The problem is that i read 4.50 V on the LCD screen when the arduino is powered with USB and 4.45 V with an external supply.
I've been check the voltage between A1 and GND (==>4.43V).
So, I have two questions : why I don't have the good value on my LCD screen ? and why the value change depending on the supply ?
Their is nothing between the voltage and the arduindo.
I put the code if you want. (Their is other thing that the reading of the voltage)
Thanks you.
// include the library code:
#include "Wire.h"
#include <Deuligne.h>
// initialize the library with the numbers of the interface pins
Deuligne lcd;
// variables
int analogInput = 1;
int refresh = 1000;
float vout = 0.0;
float vin = 0.0;
float P = 0.0;
float R1 = 1000.0; // !! resistance of R1 !!
float R2 = 1000.0; // !! resistance of R2 !!
// variable to store the value
int value = 0;
// function to print float scientific version
char * float2s(float f)
{
return float2s(f, 2);
}
char * float2s(float f, unsigned int digits)
{
int index = 0;
static char s[16]; // buffer to build string representation
// handle sign
if (f < 0.0)
{
s[index++] = '-';
f = -f;
}
// handle infinite values
if (isinf(f))
{
strcpy(&s[index], "INF");
return s;
}
// handle Not a Number
if (isnan(f))
{
strcpy(&s[index], "NaN");
return s;
}
// max digits
if (digits > 6) digits = 6;
long multiplier = pow(10, digits); // fix int => long
int exponent = int(log10(f));
float g = f / pow(10, exponent);
if ((g < 1.0) && (g != 0.0))
{
g *= 10;
exponent--;
}
long whole = long(g); // single digit
long part = long((g-whole)*multiplier); // # digits
char format[16];
sprintf(format, "%%ld.%%0%dld E%%+d", digits);
sprintf(&s[index], format, whole, part, exponent);
return s;
}
void setup() {
// declaration of pin modes
pinMode(analogInput, INPUT);
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.init();
// Print a message to the LCD.
// lcd.print("PRESSION (mbar):");
}
void loop() {
// read the value on analog input
value = analogRead(analogInput);
lcd.print(value);
// print result over the serial port
vout = (value * 5.0) / 1024.0;
lcd.setCursor(10,0);
lcd.print(vout);
vin = vout / (R2/(R1+R2));
P = pow(10.0,(vin - 6.0));
// set the cursor to column 4, line 1
lcd.setCursor(4,1);
lcd.print(float2s(P, 1));
// sleep...
delay(refresh);
}
Apologies for digging this up. I believe my issue is related to the OP's.
I'm powering the Arduino directly through Vin @ 5V, and I realize that the analog readings have shifted up by a lot (~20%).
Why? If I power it through the USB connector, Vin is lower than 5V, and substantially lower if I'm powering additional hardware through that pin.
So I thought this was a good way of getting around that, but it seems that when I power the Arduino via Vin, the opposite happens: the microcontroller itself is being powered at lower than 5V, and this is making the analogRead() calls return unexpected (higher) readings.
So I have two questions, if someone will have the kindness to help
Do you suggest any other way of powering the Arduino + additional hardware without suffering this voltage drop, considering that the hardware is stacked on top of the Arduino?
By default (not messing with analogReference()), if I'm powering it through Vin and if I also connect Vin to AREF:
a) will the readings return to the expected values, since I'd be supplying 5V to the AREF pin, thus changing the reading "range" to 0-5V?
b) won't this damage the microcontroller in the long run? Since it's being powered at a lower voltage than AREF?
EDIT: in this case, am I good by NOT calling analogReference() ?
From what you're saying, I understand that the 5V pin will power the Arduino directly.
But something isn't making sense here for me:
Since I have additional hardware stacked on top of the Arduino, and I need to power that hardware through Vin, I suppose I can't connect 5V to both the 5V pin and Vin. It seems like the direct feed and the voltage regulator's output would "collide".
Ok, sorry for insisting, but is it bad in any way to power the Arduino with 5V through Vin?
Apart from the analogRead() value shifting - and I have tried connecting Vin to AREF, which seems to solve the issue - it's been working flawless for the last 4 hours.
It's the "You can't put 5V on Vin and get meaningful operation" part that's scaring me
EDIT: the hardware I'm using has its own regulator for 3.7V. So it can take as many voltage as the Arduino, but doesn't need at least 7V to work properly.
Use an external 7.5 to 9V 1A supply, I do as a plugin to my breadboards and I have yet to have a problem, I don't use the board 3V3 or 5V sources just the ground. one day I changed an analog thermometer from a dark to a backlit LCD and my voltage readings shifted by about 15%. After I had rechecked everything (I thought) I plugged in an AC supply as I needed to take my computer down for an upgrade... and the issue was fixed again.
It involves using the internal 1.1V reference voltage to measure your Vcc voltage before then reading your ADC voltage and using that calculated Vcc reading as your reference when calculating the incoming voltage.
This is indeed great for precision reading it only makes me question myself about every time I used analogRead() in the past
But guys, can you help me? Will my Arduino eventually "explode" by being powered with these 4V?
(powering with 5V directly on Vin)
The device that is powering the Arduino has a 5V output. It's an all-in-one solution for unlimited power supply (solar+battery+mains power).
There's no way around this...
The behavior is not strange nor random. It makes perfect sense, and the previous replies just confirmed that.
I'm not sure what you mean by "reliable". Because that's what my question is about: since everything is working well right now, will it be reliable in the long run? You seem to think it won't, but you also say that it "probably" won't damage the microcontroller. So I'm confused.
But thanks for your input nonetheless.
footswitch:
I'm not sure what you mean by "reliable".
Initially I meant reliable in regards to the regulator's output and the effect on the other components on the Arduino board, namely, the ATmega328. You are operating the regulator outside of its specs. Its output will not be reliable. If board's temperature changes its output will change. If the load on the regulator increases, its output will change (go down). If the input voltage drops so will the regulator. The whole reason for using a regulator is to prevent this change from happening.
footswitch:
Because that's what my question is about: since everything is working well right now, will it be reliable in the long run?
No. At some point you will see problems. Just because something works today doesn't mean it isn't damaged and will fail later.
footswitch:
but you also say that it "probably" won't damage the microcontroller
What I did not bring up before, but you should consider are other aspects of the ATmega328.
For example, the Absolute Input Voltage for any input before damage occurs is rated as 0.5volts + Vcc. In your case, you put 5volts into a regulator and you are getting less out; probably 4.4volts. So 0.5volts + 4.4volts = 4.9volts. If you are applying 5volts on Vin and that same 5volts to any other pin on the ATmega328, you are going to eventually damage it.
This is where "probably" comes in. You're doing a bunch of borderline things and asking for a definitive answer. So I will just keep repeating myself: Do not put 5volts on Vin.
Since 5V is my only option, I'll just find a way to split the additional hardware, so that I can power the Arduino alone on the USB header, and the rest I will power directly. All good?