Hi all. I want to finish some robot projects and dug out hsr04 ultrasonic rangefinders and code.
The code I used for a working robot vehicle used include sr04 and not sure how it works.
I noticed all my sr04 units I've soldered a 2.2k resistor between echo and trig and use just trig to one port.
The gcb sr04 include sends a ping by turning a port on,wait 10 us,turn pot off,then I don't know.
I found this link about sr04 and the method is bit different and range is different conversion value. https://www.mpja.com/download/hc-sr04_ultrasonic_module_user_guidejohn.pdf last page.
Some code I'l try. Any thoughts?
The GCB SR04 library works. It is sends a ping and wait for a ping. If supports many devices.
I do not think I posted any demos as it is very simple to use.
#chip 16f1939,32#config MCLRE_ON, PLLEN_ON,#include<srf04.h>#include<glcd.h>#define GLCD_TYPE GLCD_TYPE_KS0108 ' This is the Default value, not required.#define GLCDDirection 1#define GLCD_CS1 PORTC.1 'D12 to actually since CS1, CS2 can be reversed on some devices#define GLCD_CS2 PORTC.0#define GLCD_DB0 PORTD.0 'D0 to pin 7 on LCD#define GLCD_DB1 PORTD.1 'D1 to pin 8 on LCD#define GLCD_DB2 PORTD.2 'D2 to pin 9 on LCD#define GLCD_DB3 PORTD.3 'D3 to pin 10 on LCD#define GLCD_DB4 PORTD.4 'D4 to pin 11 on LCD#define GLCD_DB5 PORTD.5 'D5 to pin 12 on LCD#define GLCD_DB6 PORTD.6 'D6 to pin 13 on LCD#define GLCD_DB7 PORTD.7 'D7 to pin 14 on LCD#define GLCD_RS PORTe.0#define GLCD_Enable PORTe.2#define GLCD_RW PORTe.1#define GLCD_RESET PORTC.2'Timingfor32mhz#define KS0108ReadDelay 6#define KS0108WriteDelay 0#define KS0108ClockDelay 0;-----Constants#define US1Ping PORTC.7#define US1Echo PORTC.6#define AlarmDistance 50;-----VariablesDimDistanceAsword;-----Mainbodyofprogramcommenceshere.GLCDCLSglcdprint0,0,"GCBasic 2016"glcdprint0,8,"SRF04 Demo"wait2sDoForever'TakeadistancereadingfromtheSRF04Distance=USDistance(1)'Checkthereading,istheobjecttooclosetotheSRF04?ifDistance<AlarmDistancethenGLCDPrint(0,24,"Close")GLCDPrint(0,32,str(Distance)+" ")ElseGLCDPrint(0,24,"Far ")GLCDPrint(0,32," ")endif'DelayforafewmillisecondsbeforetakingthenextreadingWait10msLoopend
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks. There were demos. The ping is one pulse that makes the device oscillate or "ring" for a few cycles at it's resonant frequency but that wasn't explained in the link I posted.
4 pin devices are more common but if you connect echo and trig via 2K2 resistor you just use the trig pin and the 3 pin sro4 device option. You save a port.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The link I posted and others, make it seem you need a 40KHz signal to drive the sr04. It says "8 pulses at 40KHz"... not so as I found with more searching.
I also found the devices work better upright than horizontal as there's an offset to near objects ie not at a right angle to sr04.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all. I want to finish some robot projects and dug out hsr04 ultrasonic rangefinders and code.
The code I used for a working robot vehicle used include sr04 and not sure how it works.
I noticed all my sr04 units I've soldered a 2.2k resistor between echo and trig and use just trig to one port.
The gcb sr04 include sends a ping by turning a port on,wait 10 us,turn pot off,then I don't know.
I found this link about sr04 and the method is bit different and range is different conversion value.
https://www.mpja.com/download/hc-sr04_ultrasonic_module_user_guidejohn.pdf last page.
Some code I'l try. Any thoughts?
The GCB SR04 library works. It is sends a ping and wait for a ping. If supports many devices.
I do not think I posted any demos as it is very simple to use.
another demo,
and, look at the demo folders .... I did post demos.
https://github.com/Anobium/Great-Cow-BASIC-Demonstration-Sources/tree/master/UltraSonic_Sensor_Solutions
Thanks. There were demos. The ping is one pulse that makes the device oscillate or "ring" for a few cycles at it's resonant frequency but that wasn't explained in the link I posted.
4 pin devices are more common but if you connect echo and trig via 2K2 resistor you just use the trig pin and the 3 pin sro4 device option. You save a port.
Are you asking? or, telling us?
The link I posted and others, make it seem you need a 40KHz signal to drive the sr04. It says "8 pulses at 40KHz"... not so as I found with more searching.
I also found the devices work better upright than horizontal as there's an offset to near objects ie not at a right angle to sr04.