Measuring Ultrasound Probe Angle with Two MPU6050 Sensors

Two MPU6050s on one Arduino measure a handheld Doppler ultrasound probe’s angle relative to the arm, for more accurate blood flow measurement.
Healthcare
Signal Processing
Author
Published

January 28, 2021

I was measuring blood flow volume in the arm with a handheld Doppler ultrasound, and I needed to know the angle of the probe relative to the arm. Measuring the probe alone isn’t enough, because the arm moves too. The fix is to put one sensor on the arm and one on the probe, and take the difference.

Why the angle matters

Doppler ultrasound measures blood speed from the frequency shift of the echo off moving blood cells. But it only sees the part of the motion along the ultrasound beam. If the beam meets the vessel at an angle θ, the measured speed is the true speed times cos θ:

true velocity = measured velocity / cos θ

Blood flow volume is then the true velocity times the vessel’s cross-sectional area. So any error in θ goes straight into the flow estimate, and it gets worse at steeper angles: at 60°, being off by 5° changes the result by about 15%. Holding a handheld probe at a fixed, known angle by eye is hard, so I measured it instead.

The MPU6050 is a cheap, common accelerometer and gyroscope module, so two of them on an Arduino Uno did the job.

Code: Zilch123/Angle-Between-2-MPU6050

Two sensors on one I2C bus

Both MPU6050s talk over I2C, and they share the same two wires (SDA on A4, SCL on A5). The problem is that they also share the same default address, 0x68, so the Arduino can’t tell them apart.

The MPU6050 has an AD0 pin for exactly this. Tie it to 5V on one module and its address becomes 0x69. Now there’s one sensor at each address.

Wiring: both sensors share SDA and SCL, with AD0 high on one so it answers at 0x69. The 10K resistors are I2C pull-ups.
const int MPUarm=0x68;    // AD0 low
const int MPUprobe=0x69;  // AD0 high

Each sensor starts in sleep mode, so the setup wakes both by writing 0 to the power management register:

Wire.beginTransmission(MPUarm);
Wire.write(0x6B);  // PWR_MGMT_1 register
Wire.write(0);     // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);

and the same for MPUprobe.

Angle from gravity

When a sensor is still, its accelerometer only measures gravity. How gravity splits between the sensor’s axes tells you how it’s tilted, so the roll angle is one atan2:

Wire.beginTransmission(MPUarm);
Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPUarm,14,true);
AcX=Wire.read()<<8|Wire.read();
AcY=Wire.read()<<8|Wire.read();
AcZ=Wire.read()<<8|Wire.read();
RollArm = atan2(AcY, AcZ) * 180/M_PI;

Each axis comes in as two bytes (high and low), so they’re joined into one 16-bit value. The same block runs for the probe, and the relative angle is the difference:

Serial.println(RollProbe-RollArm);

The sketch prints the arm angle, the probe angle and the difference every 100 ms, which you can watch in the Serial Plotter.

Limitations

  • It only works well when still. Any movement adds acceleration on top of gravity, and the angle jumps. Fusing the accelerometer with the gyroscope (a complementary or Kalman filter) would fix that.
  • It’s one axis. Roll alone covers tilt in one plane. A full relative orientation needs all three axes, best handled with quaternions.
  • Placement matters. The two sensors need to be mounted with their axes lined up, or the difference includes a fixed offset. Zeroing both in a known starting position takes care of most of it.

For a quick, cheap way to measure a relative angle, two MPU6050s and a few lines of code go a long way.