Category Archives: openHAB

Raspberry Pi Oil Meter Reader

This project uses a Raspberry Pi with a NOIR camera and IR lighting to take a picture of an oil tank analog meter and convert to a percentage using OpenCV for use with a home automation system. OilMeterSetup The camera resolution is high enough that the Pi can be place back far enough to get a reasonable focus. The image will be cropped show the meter on the output.

This uses a single python script running every minute from cron. The script depends on openCV and picamera.

The basic algorithm is:

  1. Rotate the image as needed
  2. Find the meter background contour
  3. Find the needle contour within the background
  4. Find the pivot point within the needle (used for adjusting the angle orientation)
  5. Fit a line to the needle contour
  6. Adjust the line vector +/-180 degrees based on which side of the pivot point the needle is on. Ex. adjusts a horizontal line to be either pointing left or pointing right.
  7. Convert the angle to a percentage based on the empty/full angles if the meter
  8. Crop the image based on the bounds of the meter background for display
  9. Upload the percentage value to openHAB for use by the home automation system
oil

Output of the processing script

openHAB charting

openHAB charting

The sources can be found on Github: https://github.com/techsavi/OilLevelReader