I am currently trying to obtain the input from a 4-20mA sensor. I convert it to voltage by the circuit I have attached.
The code is a simple one
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
float voltage = sensorValue * (5.0/1023);
Serial.println(voltage);
delay(1000); // delay in between reads for stability
}
However, in the serial monitor it only displays 0:00
The code should work.
I expect a problem with the sensor.
There is no protection between the current sensor resistor and the analogue pin.
If you turn the Arduino off and the sensor is on, or if sensor current rises above 25mA. it could be unhealthy for the pin.
Make sure that never happens, or use a 10k resistor between current sense resistor and pin.
For stable results, I would use a 51ohm sense resistor, the internal 1.1volt Aref, and multiple reads.
Leo..
4-20mA sensors are used in Current Loops*. They are simple and that is why I like them. Some loop sensors need a separate external supply while others can take power from the loop (they need more than 5V, 24V is commonly used to power current loop). A zero reading is a good indication that your loop has no power since the 4mA (e.g. loop zero) would read 0.88V with a DMM which is also how you could check if the loop is working.
surendhar:
Anyway, do you guys know if there is a conversion code or sth to convert the voltage value into the sensor reading?
Why convert to voltage. Is this a voltmeter?
Normally the A/D value, e.g. 200-1000, is directly converted to the readout you want.
Tell us what sensor you have, and what range/readout you expect from 4-20mA.
Leo..
It an environment condition monitor which senses temperature, differential pressure, corrosion rate and so on. for differential pressure the range is between 10 and 95.
Anyway, do you guys know if there is a conversion code or sth to convert the voltage value into the sensor reading?
You can do it with Arithmetic Operators or Math functions: Arduino - Home
If you are using 220 Om resistor voltage value is from 0.88 to 4.4 V?
I added to your code this:
int resistorValue = 220; // resistor value
int sensorReading = (voltage / resistorValue) *1000;
or change it to this:
int sensorReading = map(sensorValue, 0, 1023, 0, 20);
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
float voltage = sensorValue * (5.0 / 1023);
int resistorValue = 220; // resistor value
int sensorReading = voltage / resistorValue; // calculate sensor reading from voltage to mA
// int sensorReading = map(sensorValue, 0, 1023, 0, 20);
Serial.println(sensorReading);
delay(1000); // delay in between reads for stability
}