Post a diagram of what is connected where - that way you will get a definitive answer, rather than guesses as to your problem.
Most (industrial standard) 4-20 units require at least 18 volts (preferably 24) to drive them properly.
Even if your problem is a software issue it would be beneficial to see your circuit hook-up diagram.
Krodal:
250 Ohm is very low.
Which sensor are you using ?
250 ohms is a very popular 'standard' value to use as it converts a 2-wire 4-20ma current loop to a easy to read 1-5vdc range, easily read with a arduino analog input pin. Again thing we need is a detailed wiring drawing of the complete current loop to Arduino including loop voltage source and ground wire details.
Thanks for the reply, I've made a "schematic" of the connection:
however, I take current for the sensor from the DC IN of Arduino, and then I simply wire the middle of 2 resistor (sensor and 251 ohm) with one of the analog pin (the A0 pin is used by the monitor however, so I can only use A1-2-3-4-A5)
If the 250 Ohm was not connected by accident, the input pin might have been blown.
Can you add a protection resistor of 10k in series to the analog input, and use a different analog input?
The buffers in your code are too small.
This will mess up your variables on the stack:
char valadc[4] = "0"; // 4 characters
char pres[4] = "0";
...
dtostrf(val, 4, 0, valadc); // width is 4 plus terminator is 5 !
A string is ended with a string-terminator, also called zero-terminator or '\0'.
I also prefer to initialize the string in the program (but that's just me, ignore it if you like).
During development, send it back as an integer.
You can use floats if that is working.
You need something like this:
char valadc[20]; // buffer, large enough
char pres[20];
...
if (everything_is_ok)
{
val = analogRead(analogpin);
Serial.println(val, DEC);
// do some calculation: sensor = ((double) val - offset ) * gain
dtostrf .....
}
else
{
strcpy (valadc, "INF"); // "INF", or "not valid", or "0"
}
}
I've read the two topics you linked (I had already seen them when looking for a solution to interface the sensor with Arduino), I will add the resistor as you suggested: it must be EXACTLY 10 Kohm or it can be 8Ko or 12Ko (for example)?
This evening I will try to fix this buffer problem, I sensed that something was wrong with DTOSTRF function.
During development, send it back as an integer.
You can use floats if that is working.
Explain this to me please
char valadc[20]; // buffer, large enough
char pres[20];
that's ok
if (everything_is_ok)
{
what is "everything_is_ok"? (what kind of checks I can do to say that's ok or not?)
Normally 1k to 10k is used for a protection resistor. Since you use 12V: (12-5) / 1k = 7mA maximum. So 1k would already be enough.
I ment, sending it with Serial.println as an integer.
The return value of analogRead is an integer (it's the raw value of the ADC, 0...1023), so just send that.
Once you get normal readings, you can do the calculation with floats.
The "everything_is_ok" was just an example. If you are able to detect if the sensor is working, you can add this. Nothing special, just something that came to mind.
You see, once you know a little more, it's not that hard.
4-20MA sensors, as mentioned above, usually require a loop power supply of 18 to 24 volts.
Has anyone been successful using a lower voltage like 12 volts? The sensor is powered from the loop, and may not work properly if the applied voltage is too low.
I have some nice low-cost 40 amp Solid-State-Relay form dimmers. They are phase control, but the control is 4-20ma and they have an internal resistance of about 1.2K. So that looks like 24 volts is needed to run them. They look this this:
Any easy solutions?? Adding a 24V supply to a project bumps the cost up quite a bit..
So I can use the first resistor I will find in my lab, that's good.
Yes, to do calculations with the raw value was my first target but when I encountered this "reading obstacles" I got stopped...
Mmm i don't think that there are ways (in this case) to know if it's all ok, but I've understood the hint, thanks!
This evening when I return home I will do some try.
The sensor seems to work properly even with 12 V, but maybe not full range... The try that I can do is to power all the system with something like 15V.... Arduino can support it? (I read that max is 12V, but it can work even with 20V)
P.S.: little job dome with arduino:
P.P.S.: sorry for my english, I only studied it in high school!
terryking228:
Any easy solutions?? Adding a 24V supply to a project bumps the cost up quite a bit..
No, but SSR's like that for 5V control are not very expensive.
Search google for [ssr-25*], they switch on at 3V and cost about 5 dollars.
You can use the output pin of the Arduino to switch such relays.