View Single Post
  #2   Spotlight this post!  
Unread 27-01-2017, 10:31
rich2202 rich2202 is offline
Registered User
FRC #2202 (BEAST Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Wisconsin
Posts: 1,279
rich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond repute
Re: HC-SR04 Ultrasonic Distance Sensor wiring and programming

Seems like you would:

VCC: +5VDC
Trig : Trigger (INPUT) - DIO<mm>
Echo: Echo (OUTPUT) - DIO<nn>
GND: GND

To use the sensor you would:
1) Reset a Timer to 0
2) Set DIO<mm> to high
3) wait 10us
4) Set DIO<mm> to low
5) See if DIO<nn> is High
6) If high, read Timer, otherwise back to 5 (abort after 1 second)
7) Distance is per the formula

Alternative to 5-7 (which also serves as a double check), see how long DIO<nn> is held high.
__________________

Reply With Quote