Sonar

From ago control wiki
Jump to: navigation, search

Contents

Sonar device

This devices enables measuring distance with sonar SR-HC04 ultrasonic soundwaves. An Arduino is measuring since this is timecritical to send ping trigger pulse and measure the time until echo have been received (I have tried without any good success with a RPI). The measured distance is send out from Arduino via USB interface. Connect USB cable between RPI and Arduino. RPI will provide 5V to Arduino via USB. I made this since I would like to measure the pellet level in my pellet-boiler


Hardware requirements

  • Arduino, 5V with USB interface (Arduino Nano 5V)
  • SR-HC04 sonar can measure 2-400cm range (This is a 5V device)
  • 4 pcs cables between Arduino and SR-HC04
  • USB cable between Arduino and RPI/PC running Agocontrol


Arduino install

Get the Arduino code file sr_hc04_ping.ino from here: [1] Flash your Arduino with the code and your Arduino will start to measure and report the distance to USB serial. You can check the Sensor like this:

sudo minicom -b 9600 -o -D /dev/ttyUSB0
Welcome to minicom 2.7
OPTIONS: I18n 
Compiled on Jan 12 2014, 05:42:53.
Port /dev/ttyUSB0, 21:48:43
Press CTRL-A Z for help on special keys
20
20
20

You shall get measured distances in a continuous stream/loop, this measured 20cm distance

Installation

Files are found here: [2]
Copy the sonar.py script and place it in /op/agocontrol/bin/sonar.py
Ensure it's owned by root and executable chmod a+x (Maybe not needed to be root, but we must be able to read content from USB serial)
Copy sonar.service to here: /lib/systemd/system/sonar.service


Configuration

Configuration file is located at /etc/opt/agocontrol/conf.d/sonar.conf

#Location for this file: /etc/opt/agocontrol/conf.d/sonar.conf
[sonar]
tty=USB0
baud=9600
#interval=600 # maximum time(seconds) between reports
#sr-hc04 range, if out of range, return distance-1
minrange=2
maxrange=400


Enable and start device

 sudo systemctl enable sonar.service
 sudo systemctl start sonar.service


Supported sensors

  • SR-HC04


Known problems

  • none
Personal tools