PDA

View Full Version : pH Transmitter & DS2450


pista01
12/11/2007, 05:53 PM
I finally connected my newly acquired pH transmitter I picked up on eBay. I know there has been some discussion on how to read pH probes for use in a DIY controller, so I thought I'd post what I did. I'm no electrical engineer, but it seems to work.

http://i22.photobucket.com/albums/b316/pista01/pHTransmitter.jpg

I'm using an old laptop power adapter that puts out 19 volts. The DS2450 is reading the voltage difference across the resistor. The transmitter adjusts the load on the current loop based on the pH reading. A good transmitter like the one pictured will let you adjust the output levels. For example, my transmitter is configured to draw 4ma at pH 7 and 20ma at pH 10. These are completely adjustable. I used these setting because my current software is setup to calibrate using pH7 and pH10 references. Then I just have to set the voltages read by the DS2450 at pH7 and pH10 within the controller. With my previous pH transmitter, I had to adjust these voltages every time I calibrated the probe. Now I just calibrate the probe to the transmitter. The voltage at pH7 is around 1 volt. At pH10 it's around 4.3 volts. I'm using the 0-2.5 volt mode for better resolution. I used a voltmeter to read the pH10 value because it's beyond the 2.5volts that the DS2450 can read. I'll only need to do this once since all further calibration is done in the transmitter. Normal pH values are in the 2.1 volt range. If the transmitter encounters an error, it sets the output to 20ma, which will show as 0 volts by the DS2450 since it throws the voltage out of range, but still under the max of 7 volts that the DS2450 can handle. The value my controller calculates is within .05 of the display on the transmitter. I suspect this is because I didn't use the DS2450 to read the pH10 reference. I may switch the DS2450 into 0-5 volt mode to read this value. The transmitter also provides the slope in mV/pH. The manual says between 54 and 62 mV/pH is optimal. My one year old probe is 50. Since it provides the slope, I may adjust my controller to use this slope value rather than using the voltages at 7 and 10 to calculate the slope. I can then use the voltage at pH7 as a starting point.

I have a second transmitter, so I'll try ORP next. I suspect it will work the same.


Steve

ufans
01/02/2008, 07:37 AM
Steve,

How did you connect your Ph Probe to your transmitter. Does your transmitter have a BNC connection?

UFANS

pista01
01/02/2008, 08:25 AM
It didn't come with a BNC connector. I attached one to the side of the case, then wired it to the terminals of the transmitter.

funman1
01/02/2008, 08:25 AM
What controller are you using? PLC based or other?

pista01
01/02/2008, 08:43 AM
I'm using a mini-ITX board running Linux. The controller is written in Java, with an embedded SQL server (Derby) and embedded web server (Jetty). All the sensors and switches are 1-wire devices. I develop it on Windows, then deploy the changes to the Linux box.

funman1
01/02/2008, 01:05 PM
Wow, do you have a thread on that controller?
I'd like to know more..

pista01
01/02/2008, 08:26 PM
<a href=showthread.php?s=&postid=11504929#post11504929 target=_blank>Originally posted</a> by funman1
Wow, do you have a thread on that controller?


No, not really. I did start a thread on another board several months ago, but the controller wasn't anywhere near finished then.

It's not like any of the controllers I've read about. It's probably far too complicated, but I wanted something with more control than using something like OWFS and batch files. With the 1-wire Java API, I'm able to have more granular access to the devices. I can trap for the various errors that crop up on the 1-wire bus, mostly CRC errors. Embedding a SQL server and web server keeps the entire controller within a single Java virtual machine. No need to load separate processes for SQL and web server. A single command line starts it all, on Linux or Windows (maybe MAC too, but I don't have one). Another aspect I'd like to explore is storing configuration data directly on the devices. Some devices can store files. Imagine a total cold boot (no configuration data in SQL) and having the missing configuration data load off the network. Another area worth exploring is a PC on standby that will remove the controller from the network if it dies, then insert itself as the bus master and take over.

I don't have the internals documented yet. I generated javadocs once for it and realized then how much coding I did on it. I'll go into a high level version of what I have.

Outside of Derby and Jetty, there are 3 main parts of the controller. Devices, profiles, and a logger. The devices are just objects that are centered around a specific hardware device, like a DS2450 A/D converter. These objects handle the I/O with the physical devices, as well as the error handling. One of the devices is a DS2409, which is a 2 port MicroLAN controller. I have three, which means I have 6 separate 1-wire networks. This gives me a bit more flexibility wiring the network and prevents one bad network from bringing down the entire network. Profiles are the logic. For example, one such profile is a lighting object. Within this I can configure the 1-wire device that controls the light and the schedules that determines when to turn the light on. A single schedule can be created to turn a light on between two time ranges on any day (or multiple days) of the week. Any number of schedules can be created for a light. I plan on dynamically changing these based on the sunrise/sunset of a particular latitude/longitude, but that will come later. I also have profiles for temperature, pH, and switches in general. I still need to add a moonlight profile. I'm adding a second temp sensor as input to the temperature profile to act as a backup for heater/chiller control. The temp sensors are cheap. I will put the second one in the sump and watch for too large of a differential between the two (could indicate a return flow problem). I may even strap one to the individual heaters to verify they are working. It would be trivial to monitor the temp sensor in the ballast and shut the power off if the ballast gets too high. All profiles can read/write to all devices. Profiles log data as well, at intervals specified in the profile configuration. The logger is the 3rd piece of the controller. Any errors are registered in the logger object, which then controls the notification. All events, whether they are errors or normal status messages, go through the logger. I can set different debug levels and control the log output. Some errors only notify if there are several errors from the same location in a row, like if a sensor repeatedly returns CRC errors or a temp sensor is reading too high or too low. CRC errors happen once in a while, especially with the temp sensor I stuck inside the magnetic MH ballast. It's rare to get notification for CRCs. Most of the time they happen once or twice in a row. Of course temps outside the set range produce notifications, as do any reoccurring device I/O errors. Right now I'm just notifying via e-mail, next I will have it IM me at work if I'm online. I'm thinking of SMS notification directly through a cell phone as well. I always loose my internet connection when there are power failures, even though everything I have is on a UPS. No point in notifying anyone of a power failure when the internet isn't working. I may put one of those flashing siren like lights behind the tank and trigger it when an error is triggered.

These three object types run in a loop. Once all the devices process (reads/writes), then all the profiles are processed, then the logger checks to see if it needs to process any error messages. Then the loop starts over. It takes about 8.5 seconds to run through a loop. Here is the normal log output for a single loop.


Run # 2252/10000
02-01-08 20:05:58.169: (Channel 1:setAllPortsOff) Channel 1
02-01-08 20:05:58.719: (Channel 3:setChannelState) Changing channel 0 - true
02-01-08 20:06:00.499: (Main tank temp:readTemperature) Current temperature is 26.75
02-01-08 20:06:00.849: (Sump Light:readSwitchState) Switch is on
02-01-08 20:06:01.199: (Heater:readSwitchState) Switch is off
02-01-08 20:06:01.549: (PC Actinic:readSwitchState) Switch is off
02-01-08 20:06:01.899: (PC White:readSwitchState) Switch is off
02-01-08 20:06:02.609: (Channel 2:setChannelState) Changing channel 0 - true
02-01-08 20:06:03.039: (Channel 3:setAllPortsOff) Channel 3
02-01-08 20:06:04.869: (Left MH Ballast Temp:readTemperature) Current temperature is 67.75
02-01-08 20:06:04.869: (Channel 1:setChannelState) Changing channel 0 - true
02-01-08 20:06:05.299: (Channel 2:setAllPortsOff) Channel 2
02-01-08 20:06:05.899: (Sump Temperature Profile:process) Fahrenheit: 80.15
02-01-08 20:06:05.907: (Left MH Ballast Temp Profile:process) Fahrenheit: 153.95
02-01-08 20:06:05.909: (Sump pH Profile:readpH) Current pH is 8.247021043661945
02-01-08 20:06:05.912: (Left MH Profile:process) on
02-01-08 20:06:05.914: (Right MH Profile:process) on
02-01-08 20:06:05.917: (Sump Light Profile:process) on
Loop completed in 8350 milliseconds



The first 12 lines are the devices and the MicroLAN devices switching between channels. In order to access a device, it's LAN segment must be turned on. I once thought about nesting LAN segments, but determined that the insanity level would be higher than my normal threshold. No, it doesn't print smiley faces in the log :)

For the SQL server part, everything is stored in the SQL database. Each profile saves it's state to SQL in every loop. If the controller dies for some reason (never has), the very last state is saved. The state data is loaded at initialization. It updates it configuration after so many loops have passed, which is currently set to 10,000. I can manually reload via the web page.

The web interface is a series of servlets. Some display historical data from SQL, some display data directly from the profile and device objects. Changing profiles is possible from the web interface as well, such as overriding a lighting schedule and force a light to go on or off for a certain number of minutes. One time I got notified because the tank temp had dropped too low. The heater wasn't large enough for the room temp. I logged in to the controller from work and turned on the MH lamps a couple hours early. There are a few servlets that output data in XML so it can be easily read by outside programs. I threw a quick Flash app together that displays the current status. Maybe one day I'll create an entire interface using Flash. More than likely I will create a front end for my BlackBerry, as I use it more than anything to monitor the controller.

I still have a lot more I'll be adding, like sump level monitoring/control (more monitoring than control at first) and water sensors around the tank and sump. Will be adding switch logging to SQL too. Eventually I will be adding a smoke alarm with a built in light, so I can trigger on the voltage across the bulb. I'm almost finished with the main functionality I wanted in the web interface, so I'll start moving on to the extra monitoring next.

The hardware itself is an old slot machine controller based on a mini-ITX board with 128MB RAM. I had a 2.5" hard drive I bolted on to the frame. I once ran the controller off a bootable USB memory stick loaded with Linux. It worked well, but had to come up with a way to move the SQL db to permanent storage. CD based Linux like Knoppix didn't work so well because of the 128MB RAM. Using a HD was easier by far.

On the surface it's seems way too complicated, but in reality everything is just a small piece that functions as a larger whole. The only limit is the number of 1-wire devices on a network. I effectively have 6 networks, so I can have hundreds of devices. Of course that wouldn't be very practical. There are other parts I didn't go into, like web security, preference settings, and the charting (which I still need to complete), debug levels, etc. Sometime soon I'll need to prioritize what needs to be completed first. So far I've been very happy with the performance and reliability. The basic controller (temp monitoring and light control) has been running for 2 years now, if not more. I've just been slowly adding functionality as I needed it.

ufans
02/17/2008, 08:36 AM
Pista,

I am wiring the DS2450, but I can't figure out the pin assignment. Which pin is 1? There is no indication looking at the chip.

There is writing on one side and a small imprint of M4 in one corner. There is also a circle imprint on the opposite size in the opposite corner.

pista01
02/17/2008, 10:24 AM
The dimple on the top of the chip indicates pin 1.

slug
02/17/2008, 11:50 AM
Maybe I'm not following what you did correctly but usually you calibrate the meter and then get the data acquisition device to read the same value. From then on you only need to calibrate at the meter.

If you change the value of the resistor you could read the full range of the meter. V=IR so right now your max voltage 10 volts because 0.04amps x 250 Ohms = 10v. A 62.5 Ohm resistor should give you 2.5v at 10 pH.

ufans
02/17/2008, 01:58 PM
Also, please verify my wiring to my 1wire Network...
Vcc & Ground -> 1-wire GND (Blue/White)
and
Data -> 1-wire Data (Blue)

That means that the 18vDC negative lead that I am using will connect to the GND on the 2450 and the GND on the 1-wire network

pista01
02/17/2008, 03:26 PM
Even though the DS2450 can be powered off the bus, you really should add a voltage regulator and power it with 5 volts directly. The Hobby Boards HVAC Monitor (http://www.hobby-boards.com/catalog/links/hvac2-r1/HVAC%20Monitor%20v2.2%20Schematic.pdf) is a good example.

Post you schematic.

Whatever you do, make sure you never apply more than 7 volts or it will fry the chip. Use a volt meter first before you connect chip to verify the voltage.

pista01
02/17/2008, 03:49 PM
<a href=showthread.php?s=&postid=11869750#post11869750 target=_blank>Originally posted</a> by slug
Maybe I'm not following what you did correctly but usually you calibrate the meter and then get the data acquisition device to read the same value. From then on you only need to calibrate at the meter.

If you change the value of the resistor you could read the full range of the meter. V=IR so right now your max voltage 10 volts because 0.04amps x 250 Ohms = 10v. A 62.5 Ohm resistor should give you 2.5v at 10 pH.


4 mA = 0.004 amps

0.004 A X 250 Ohms = 1 volt
0.020 A X 250 Ohms = 5 volts

slug
02/17/2008, 04:01 PM
Yeah I messed my math up sorry. I was just trying to say you could adjust it to read the full range of your meter. Even at 12bit(sorry I don't know what the chip reads at) you aren't losing significant resolution.

ufans
02/17/2008, 04:20 PM
Here is my schematic...

http://reefcentral.com/gallery/data/500/55642phmonitorwiring-med.JPG

Do I need to connect the 1wire GND or the Negative from the 5VDC?

pista01
02/17/2008, 04:40 PM
<a href=showthread.php?s=&postid=11871501#post11871501 target=_blank>Originally posted</a> by ufans

Do I need to connect the 1wire GND or the Negative from the 5VDC?

Both

ufans
02/17/2008, 04:57 PM
What do I connect the 5VDC lead to?... I don't connect it to the 1Wire ground do I?

ufans
02/17/2008, 05:53 PM
I added a Power Injector to get a regulated 5VDC.. Anything missing from this schematic

http://reefcentral.com/gallery/data/500/55642phmonitorwiring2-med.JPG

Only thing missing is whether I need to connect the 1 Wire Return GND (Pin 5) to anything. I figure I can't connect it to the GND on the 2450 since it is connected to the -28VDC lead from the power supply

pista01
02/17/2008, 06:10 PM
Pin 5 of the wire connector goes to gnd. Even though it's called 1-wire, you technically need 2 wires, data and gnd.

ufans
02/17/2008, 07:02 PM
okay.. final diagram.. hopefully..

http://reefcentral.com/gallery/data/500/55642phmonitorwiring3-med.JPG

The only thing that scares me is the 19VDC->DS2450 GND->1WireGND->Computer_USB

pista01
02/17/2008, 07:12 PM
Use a volt meter before you connect the chip. I did some research on isolating the 1-wire network, but it appeared to be more trouble than it's worth.
That's one of the benefits of using cheap PC hardware. If it all blows up, I can easily replace the hardware with stuff I have laying around. All it needs is something with 128MB RAM that can run Linux and Java.

ufans
02/22/2008, 09:47 AM
Pista

When you installed your second GLI Pro for your ORP monitor did you use a second DS2450 or did you just use another resistor and a second analog input on the single DS2450?

pista01
02/22/2008, 05:11 PM
I haven't actually got around to installing it. When I do, I'll just add it to a free input with another resistor.

ufans
02/23/2008, 04:01 PM
All Done !!! Here is my final wiring ....

http://reefcentral.com/gallery/data/500/55642phmonitorwiringfinal-med.JPG

The only thing left is to setup the applications on the server to receive, log, and graph the results. The application that I am currently using for my temp logging/charting is DS18x Service, which only supports 1 wire Temp sensors. I have used WServer, which supports the DS2450, but had problems. I really want a Windows Service that can log everything to TXT files or a database.

:D

pista01
02/23/2008, 04:35 PM
<a href=showthread.php?s=&postid=11922798#post11922798 target=_blank>Originally posted</a> by ufans
I really want a Windows Service that can log everything to TXT files or a database.:D

Take a look at the 1-wire Java API (you'd need a Java Developer Kit). They include samples that can be executed from a DOS prompt. The source for each sample is available. You should be able to modify the samples to print the value to the screen. Then create a batch file that executes the java program every X minutes (run the program, sleep for a few minutes, then run the batch file again).

Most databases will let you add a record from the command line. Should be possible to do both within the same batch file. You can add the java code for the database calls directly to the modified java sample. I used Apache Derby, which was pretty simple to use. It only takes a few lines of code to instantiate the db and a few more to add a record.


Steve