Homebuilt underwater robot

 

Pressure sensor

Pressure is used to calculate depth at which rov operates.
Pressure at 1m is equal to 0.098bar, at 100m it is 9.8bar. In real world depth and pressure relationship isn’t constant. It depends on location, water temperature, salinity, etc. You can read more in this article “A Sea Water Equation of State Calculator”. For most applications you can simply assume that pressure at 100m is 9.8bar.

Pressure sensor must be chosen according to maximum depth that rov can operate. For example if you assume maximum depth 100m you must use 10bar sensor.

Interface

Most pressure sensors give voltage or current as output. To read this analog value, you need Analog to Digital converter. I describe here how to connect sensor with current output to Atmel ATmega8 micro controller, but it is valid for any AVR chip with ADC (e.g. ATmega16). ATmega8 has built 10bit ADC converter with 6 (for PDIP package) or 8 multiplexed inputs. A/D converter needs reference voltage for conversion. For this chip you can use one of the three options:
  1. AVCC – equal to VCC, e.g. 5V
  2. AREF – external reference voltage connected to AREF pin.
  3. 2.56V – internal reference 2.56V.
Reference voltage can be selected by setting appropriate bits in ADC register. For our purposes we’ll be using AVCC reference, which means 5V for chip powered by 5V. To use entire ADC range, input must be from 0V to Vref, in this case equal to 5V.

Sensor

For this example I’ll use ST09 pressure sensor from Nuovafima:
  1. Max pressure: 10bar
  2. Output: 4mA to 20mA
  3. Supply: 9-30V
Pressure sensor ST09Pressure sensor ST09 It outputs 4mA for 0 bar to 20mA for 10bar. A/D converter needs voltage input, but this sensor has no voltage output. To convert current output to voltage output we need additional resistor. Voltage drop can be used as input for ADC. We need resistor that gives 5V (max voltage for ADC) voltage drop for 20mA (max current). From Ohm’s law:

R=U/I=5V/0.02A=250Ω

For 250Ω resistor we’ll get 5V for 20mA and 1V for 4mA. 20mA is unofficial standard for many different sensors, so it is very common to use 250Ω resistor.
Note that if measured output is less than 1V (=4mA) sensor is not connected. This useful feature allows you to detect broken wires or hardware problems.

For other values of reference voltage different resistor have to be used. For example for 2.56V (AVR internal reference voltage): R=2.56V/0.02A=128Ω. But there is no 128Ω resistor on the market, nearest available (but less then 128Ω) value must be chosen. In this example it is 120Ω.

Diagram

Here you have simplified schematic how to connect pressure sensor to ATmega8 chip. ATmega8 and pressure sensor: Pressure sensor connected to ADC pin of ATmega8ATmega8 and pressure sensor: Pressure sensor connected to ADC pin of ATmega8

Software

To obtain pressure value and then depth value form ADC, simple conversion of ADC result must be performed.
10bit ADC converter gives maximum 210-1=1023 value. If you connect 5V to ADC input you get 1023 as ADC conversion result (for reference voltage 5V). 0bar is 4mA or 1V, 10bar is 20mA or 5V
ADC output is 1023 for 20mA and ~204 (=4*1024/20) for 4mA.

Here are some equations, ADC is value read from ADC:
Voltage: U=ADC*5/1023
Current: I=U/250
Pressure: P=(I-0.004)*10/(0.02-0.004)
(bar) Depth: D=100*P/9.8 (assuming pressure at 100m is 9.8bar)

Finally we get this:
Depth: D=ADC*5000/(256000*9.8*0.016)-40/(9.8*0.16)
Result value is in meters.

Playing a bit with math, a general equation can be written for sensor with 4-20mA output as:
equation
It is not handy to use floating point numbers in micro controller. For this example simplified equation using only integer numbers is:
P=((ADC*5000000)/256-4000000)/(16*X)
where:
ADC - value read from A/D converter
X - pressure at 100m in bars multiplied by 10, e.g. for 9.8bar X=98
Result is in centimeters (100cm=1m)

Errata: U=ADC*5/1024 not U=ADC*5/1023. All above equations assume wrong value of U. You can still use those equations because an error is less than A/D converter error.

If A/D conversion result changes by 1, it means depth was changed by 12.5cm. For example, if ADC result is 700, the depth is 61.68m; for ADC=701, the depth is 61.81m.

That simply means maximum accuracy depth can be measured is about 12cm. In fact the real accuracy is worst because of:

  1. error of A/D conversion, for AVR ADC accuracy is ±2LSB which means 2*12.5cm=25cm
  2. Reference voltage instability, tolerance of 2.56V reference is 10%
  3. error of the pressure sensor, for ST09 it is 0.5% max

Summarizing: you can read depth with 12cm resolution but accuracy of the measure is much worst. For example you can ignore sanity of the water because it affects accuracy less than mentioned factors.

BASCOM example

Here is a simple example in BASCOM-AVR. It sends depth value to serial port based on ADC value. Sensor must be connected as shown in diagram.
$regfile = "M8DEF.DAT"

$crystal = 8000000

Config Serialin = Buffered , Size = 20

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

$baud = 9600

'configure ADC
Config Adc = Single , Prescaler = Auto , Reference = Avcc

'ADC conversion result
Dim C As Long

'Depth in cm
Dim D As Long

'Pressure * 10 at 100m
Const X = 98

'D =((C*5000000)/256-4000000)/(16*X)
Const Z1 = 5000000 / 256
Const Z2 = 16 * X

'power ADC
Start Adc

Do

   C = Getadc(0)

   D = C * Z1
   D = D - 4000000
   D = D / Z2

   Print "Depth: " ; D ; "cm"

   'wait 1s
   Wait 1

Loop


AttachmentSize
pressure_sensor_example.bas707 bytes