Hello, I am very much a newbie at this code stuff and I have a problem with figuring how to do this. I wish to have two analog inputs to my arduino with one referenced to 1.1 INTERNAL and the other to the default 5vdc.
I am aware the analog input is broken up into 1023 parts, be it 1 volt or 5 volts (is that how it's said?).
One will be a temperature input using the INTERNAL reference voltage of 1.1 volts.
The other I would like to measure a voltage input of 16 vdc. This 16 volts dc and I would use a voltage divider to drop max voltage to 5vdc. I could have the voltage divider drop voltage to 1vdc, but it seems like more accuracy would be provided by using 5vdc.
The examples I've seen show the analogReference(INTERNAL) set in the declarations section at beginning of code. That makes all the analog inputs referenced to 1.1 volts.
Is it possible to set ths analogReference(INTERNAL) down in the loop section and switch between the 5vdc default and the 1.1 INTERNAL analogReference?
If not, is it possible to use the Aref pin with 5 vdc applied and switch between INTERNAL and Aref in different sections of the code?
If either of these are feasible, can someone point to (or provide) an example how this is done?
From reading my post you can tell I am VERY new at this, so if it's not presented correctly, please don't hesitate to correct.
Is it possible to set ths analogReference(INTERNAL) down in the loop section and switch between the 5vdc default and the 1.1 INTERNAL analogReference?
Yes you can switch the ADC reference from INTERNAL to DEFAULT using the analogReference(type) statement in your loop code. However you may have to play with adding delays and/or making multiple analogRead statements to get a stable/accurate reading after changing references.
Thanks for the response - is this anything like what should work on switching between INTERNAL and DEFAULT analogReference? Are the delays shown just before the analogReference what you were referring to?
OK, I just came back and did a modify after figuring how to do the scrollable code.
This code will compile, but I have not had a chance to run on Arduino - don't have it here.
Thanks for any and all help (as you can see I NEED all the help I can get:(
Ken H>
int tempPin = 0;
int voltPin = 1;
float temperature = 0;
float volt = 0;
void setup()
{
Serial.begin(9600);
}
void loop() {
//this starts the temperature section
int spantemp = 20;
int tempRead = 0;
for (int i = 0; i < spantemp; i++)
{
tempRead = tempRead+analogRead(tempPin);
tempRead = tempRead / 20;
delay(500); //is a delay needed here?
analogReference(INTERNAL);
temperature = ((1.1*tempRead)/1024); // convert voltage to temperature
}
Serial.print("Temp "); // print temperature value on serial monitor
Serial.println(temperature);
//this starts the voltage section
int spanvolt = 20;
int voltRead = 0;
for (int i = 0; i < spanvolt; i++)
{
voltRead = voltRead+analogRead(tempPin);
voltRead = voltRead / 20;
delay(500); // will 500ms help make the change from INTERNAL to DEFAULT?
analogReference(DEFAULT);
volt = ((5.0*voltRead)/1024); // convert voltage to voltage
}
Serial.print("Voltage "); // print temperature value on serial monitor
Serial.println(volt);
delay(500);
}
Is this were the analogReference(INTERNAL); should be located? with the delay right after the analogReference statement?
for (int i = 0; i < spantemp; i++)
{
analogReference(INTERNAL);
delay(500);
tempRead = tempRead+analogRead(tempPin);
tempRead = tempRead / 20;
temperature = ((1.1*tempRead)/1024); // convert voltage to temperature
}
Can I start a new section and change to analogReference(DEFAULT); with the delay here?
for (int i = 0; i < spanvolt; i++)
{
analogReference(DEFAULT);
delay(500);
voltRead = voltRead+analogRead(tempPin);
voltRead = voltRead / 20;
volt = ((5.0*voltRead)/1024); // convert voltage to voltage
I thank you for taking time to respond with the help - I'm very much a newbie here and enjoying this new stuff a LOT!!
No. The analogReference and delay statements go BEFORE the for loop:
analogReference(INTERNAL);
delay(500);
for (int i = 0; i < spantemp; i++)
{
tempRead = tempRead+analogRead(tempPin);
tempRead = tempRead / 20;
temperature = ((1.1*tempRead)/1024); // convert voltage to temperature
}
Thanks PaulS - I will try that tonight. I'm trying to build a 35 amp power supply monitoring system with the arduino to monitor heatsink temperature, voltage, and current. There will be a shut down if voltage exceeds 15vdc or if heatsink exceeds 100C.
I think I've got most of it worked out now with a prototype breadboarded up. Now to etch a PCB and build the circuit.