How to use AnalogReference

Hi

i'm new in the environement of arduino and im having some problem with a program im doing.
i have a pressure sensor that gives me 0V to 5V as output depending on the pressure in it.
how should i use this voltage that im get from the sensor to connect it to my analog input pin?

i have already written a program to do this and it is working only when im using the 5V that the board is giving.
i have done some research i found that 'analogReference(EXTERNAL) should be use.
but im not understanding how to use it in my program and how to do the connection on my board.

i have done some research i found that 'analogReference(EXTERNAL) should be use.

Why do you think that?

If analogreference should not be use so what i should do?

my pressure sensor work like this:
-it is powered by 24v dc.
-when pressure vary it gives an output signal of 0-5V dc.

i should use this output voltage as input in the arduino analog input.

If your sensor puts-out 0-5V, the default 5V reference is perfect!

You need to know what 0V and 5V correspond to as pressure. Then you can calculate the ratio and your sketch needs to calculate the proportional pressure. (Note that the ADC doesn't directly "volts" and you don't need "volts" in your sketch. It reads 0-1023, where 0 is 0V and 1023 is 5V.)

So for example, if 0V is zero PSI and 5V is 100 PSI, then 100 PSI will give an ADC reading of 1023 and 50 PSI will give a reading of 511 or 512 (assuming the sensor is linear and assuming no tolerance/variation in the readings.)

-it is powered by 24v dc.
-when pressure vary it gives an output signal of 0-5V dc.

Make sure it never can put-out more than 5V... More than 5V can damage the Arduino.

i should use this output voltage as input in the arduino analog input.

Is that a question? Start by just reading the raw ADC numbers. The [u]Analog Read Serial[/u] shows you how to do that.

If your sensor is working and if you have a way of varying the pressure, you can just connect the sensor and you don't need the potentiometer used in the example. But, it might be handy to have a pot around for troubleshooting.

when im using a potentiometer that is powered by the 5v of the board, it is working but i use my sensor it does not work.

What is the sensor?
Do you have the 24V system ground connected to the Arduino ground?

yes the sensor ground is connected to the arduino ground.

Is the sensor ground the same point as one of the sensor output pins?
Are you presenting the sensor o/p voltage + to the Arduino analog i/p?

Check the output of the sensor with a multimeter. If you don't have one, now is the time to buy one!

LarryD:
Is the sensor ground the same point as one of the sensor output pins?
Are you presenting the sensor o/p voltage + to the Arduino analog i/p?

yes, the output voltage of my sensor is connected the arduino analog input pin.

jremington:
Check the output of the sensor with a multimeter. If you don't have one, now is the time to buy one!

im getting the 0-5v at the output of my sensor when varying the pressure.

All ground are connected at the same point.

Show a current circuit wiring image, and your current sketch.

LarryD:
Show a current circuit wiring image, and your current sketch.

int sensorPin = A0; // select the input pin for the pressure sensor
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

// variables:
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);

}

void loop() {

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
if (sensorValue == sensorMax) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}

Streetdevil:
int sensorPin = A0; // select the input pin for the pressure sensor
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

// variables:
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);

}

void loop() {

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
if (sensorValue == sensorMax) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}

i have taken an example and modify only the last part for what i need.

the +ve 5v of the sensor is connected to A0 and the 0V to ground on the breadboard.
all the ground are connected together.

any external 0-5v is not working both for the sensor and when i use a potentiometer powered by an external 5V power supply.

it work only when i use the 5v of the arduino board.

Assuming your wiring is all correct, you have very rigid test coniditions.

5v/1023=0.005v (ish). So if your sensor '5v' output is 4.994v, your ADC currently would report a value for the sensor of 1022. Your logical test is based upon 1023, so it wouldnt pass.

Maybe try lowering how rigid your criteria are to account for real world variations? (eg set sensormin to 100 and sensormax to 923, then test again).

scrumfled:
Assuming your wiring is all correct, you have very rigid test coniditions.

5v/1023=0.005v (ish). So if your sensor '5v' output is 4.994v, your ADC currently would report a value for the sensor of 1022. Your logical test is based upon 1023, so it wouldnt pass.

Maybe try lowering how rigid your criteria are to account for real world variations? (eg set sensormin to 100 and sensormax to 923, then test again).

hey thank.now it work. :slight_smile: