I have a Arduino LilyPad ATmega328V with a temperature sensor MCP9700. I have a correct read of temperature when the LilyPad is connected by USB FTDI of fixed 3.3V, because when I read the value of analog pin, I do this: lectura = lectura * (3.3/1024.0); But the problem occurs when I supply the LilyPad with a LilyPad Power Supply (AAA battery) (LilyPad Power Supply - DEV-08466 - SparkFun Electronics), because I think it does not supply a fixed 5V. It has fluctuation, and probably supply less than 5V because of the resistence of wire and other factors.
So I want to know the real power supply that the LilyPad is receiving, in order to do correctly this: lectura = lectura * (powersupply/1024.0);
I have read something about internal reference of 1.1V, but I dont know how to use it.
I am an amateur in Arduino, so I will very grateful of all helps. Thanks!
The wire thread designed for use with fabric and lilypads has a high resistance I believe, so yes you might get poor voltage regulation this way. Using analogReference(EXTERNAL) and feeding 3.3V to the AREF pin could be a solution? Can't remember if the lilypad brings out AREF to one of the pads though.
I have could decrease the fluctuation. Now, with the battery supply, I am getting values between 56-63. But these should be around 22-23 degrees. With the FTDI USB, that supply 3.3V, I do: read = read * (3.3/1024.0); and I get the correct 22-23. The battery supply provides 5V. In adittion, I am using the internal reference with the rule of thrre I show in the last post. It seems to be that the ADC is not using Vcc as the reference, why?
Thanks!
I show the code I am using (I use a bluetooth mate gold in order to transmit the value to an Android Aplication, so I only transmit a value of byte because the degrees measured wont be higher than 255, and bluetooth only write a byte).
//LilyPad + Temperature Sensor
int tsensorPin = 2; // Temperature sensor is connected to analog pin 2.
int tempValue; // Variable to store the value coming from de temperature sensor.
#define BANDGAPREF 2 // Special indicator that we want to measure the bandgap.
float lectura=0;
float supplyvoltage;
int refReading;
float temp;
void setup()
{
Serial.begin(115200);
}
void loop()
{
//Read the temperature.
lectura = analogRead(tsensorPin);
//Get voltage reading from the secret internal 1.1V reference
refReading = analogRead(BANDGAPREF);
//Now calculate our power supply voltage from the known 1.1V reference.
supplyvoltage = (1.1 * 1024.0) / refReading;