This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
|
oak:tutorials:ultrasonic_2 [2017/01/09 22:06] Rover#18 [Circuit] Added voltage divider alternative circuit |
oak:tutorials:ultrasonic_2 [2017/01/09 23:48] Rover#18 [Alternative Circuit: Voltage Divider] formatting |
||
|---|---|---|---|
| Line 20: | Line 20: | ||
| - | ** *Note:** The HC-SR04 sensor is a 5v sensor, while the Oak is 3.3v. We will be using a bi-directional level shifter for compatibility. Given the plethora of micro electronic devices, and the race to use less and less power, it's not unusual to have a need for level shifting. Alternatively, a voltage divider may be used to drop the echo signal down from 5V to 3.3V. | + | ** *Note:** The HC-SR04 sensor is a 5v sensor, while the Oak is 3.3v. We will be using a bi-directional level shifter for compatibility. Given the plethora of micro electronic devices, and the race to use less and less power, it's not unusual to have a need for level shifting. Alternatively, a [[https://digistump.com/wiki/oak/tutorials/ultrasonic_2#alternative_circuitvoltage_divider|voltage divider]] may be used to drop the echo signal down from 5V to 3.3V. |
| Particle.publish will be used to send the sensor data to the cloud. To view the data, you will need your free Particle account. You most likely created one when you first set up your Oak. If you don't have one already get yours here: [[https://build.particle.io/signup]]. | Particle.publish will be used to send the sensor data to the cloud. To view the data, you will need your free Particle account. You most likely created one when you first set up your Oak. If you don't have one already get yours here: [[https://build.particle.io/signup]]. | ||
| Line 81: | Line 81: | ||
| GND ---+------- GND | GND ---+------- GND | ||
| </code> | </code> | ||
| + | |||
| + | {{:oak:tutorials:oak_hc-sr04_voltage_divider_echo.jpg?direct&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> | ||