User Tools

Site Tools


oak:tutorials:ultrasonic_2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
oak:tutorials:ultrasonic_2 [2017/01/09 22:07]
Rover#18 [Components] noted voltage divider alternative
oak:tutorials:ultrasonic_2 [2017/01/09 23:55]
Rover#18 [Alternative Circuit: Voltage Divider]
Line 81: Line 81:
    GND ---+------- GND    GND ---+------- GND
 </​code>​ </​code>​
 +
 +{{http://​digistump.com/​wiki/​_media/​oak/​tutorials/​oak_hc-sr04_voltage_divider_echo.jpg?​300}}
 +
 +Alternative build option using voltage divider instead of level shifter
 +
  
 ===== Code ===== ===== Code =====
Line 105: Line 110:
 int LEDPin = 1; // Onboard LED int LEDPin = 1; // Onboard LED
  
-long duration+long Time_Echo_us
 long inches; ​ long inches; ​
  
Line 149: Line 154:
 <​code>​ <​code>​
  
-// pulseIn HIGH starts measuring the time until it hears the echo + // pulseIn HIGH starts measuring the time until it hears the echo 
-Time_Echo_us = pulseIn(echoPin,​ HIGH);  ​+ ​Time_Echo_us = pulseIn(echoPin,​ HIGH);  ​
    
-// Calculate distance to object. Divide by 2 because echo time is roundtrip + // Calculate distance to object. Divide by 2 because echo time is roundtrip 
- ​inches = (duration/2) / 74;+ ​inches = (Time_Echo_us/2) / 74;
  
 </​code>​ </​code>​
oak/tutorials/ultrasonic_2.txt · Last modified: 2017/01/09 23:55 by Rover#18