This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
oak:tutorials:ultrasonic_2 [2016/08/05 14:18] brohan |
oak:tutorials:ultrasonic_2 [2017/01/09 23:55] (current) Rover#18 [Alternative Circuit: Voltage Divider] |
||
|---|---|---|---|
| Line 16: | Line 16: | ||
| | Breadboard|1| | | | Breadboard|1| | | ||
| |Ultrasonic Sensor|1|HC-SR04| | |Ultrasonic Sensor|1|HC-SR04| | ||
| - | |Level Shifter|1|TXB0108| | + | |Level Shifter*|1|TXB0108| |
| |Jumper wires|11| | | |Jumper wires|11| | | ||
| - | **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. | + | ** *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 28: | Line 28: | ||
| ==== Level Shifting ==== | ==== Level Shifting ==== | ||
| - | Level shifters are devices / chips that resolve mixed voltage incompatibility between different parts of a system that operate in multiple voltage domains. Bi-directional shifters, such as the one used here will convert voltages in both directions, and do this automatically, protecting your devices all the way around. The TXB0108 model contains an Output Enable Control (labeled OE on the device), that when left LOW, the TXB translator buffer will be disabled and the outputs are put into a high impedance state for increased power savings. In this state, output leakage (IOZ) will be less than ±2 mA. When the OE is HIGH (in this example the VCC power from the Oak), the outputs are put in a low impedance state. | + | Level shifters are devices / chips that resolve mixed voltage incompatibility between different parts of a system that operate in multiple voltage domains. Bi-directional shifters, such as the one used here will convert voltages in both directions, and do this automatically, protecting your devices all the way around. The TXB0108 model contains an Output Enable Control (labeled OE on the device), that when left LOW, the TXB translator buffer will be disabled and the outputs are put into a high impedance state for increased power savings. In this state, output leakage will be less than ±2 mA. When the OE is HIGH (in this example the VCC power from the Oak), the outputs are put in a low impedance state. |
| Line 66: | Line 66: | ||
| Here's a picture of the actual setup. | Here's a picture of the actual setup. | ||
| + | |||
| + | |||
| + | ==== Alternative Circuit: Voltage Divider ==== | ||
| + | If you don't have a level shifter, it is advised that you acquire one; they're handy to have around when working with 3.3V microdevices such as the Oak. That said, you can build this circuit using a voltage divider to drop the echo signal from 5V to 3.3V to interface with the Oak. It is not necessary to level shift the trigger signal. In the following circuit, we'll use Oak pin 2 to trigger the range finder, and pin 4 to read the echo. | ||
| + | <code> | ||
| + | Oak HC-SR04 | ||
| + | ----- ------- | ||
| + | VIN ----------- Vcc | ||
| + | P2 ----------- TRIG | ||
| + | P4 ---+--1K--- ECHO | ||
| + | | | ||
| + | 2K (Any pair of 500-20k Ohm resistors with roughly 2:1 ratio will work) | ||
| + | | | ||
| + | GND ---+------- GND | ||
| + | </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 | ||
| Line 91: | Line 110: | ||
| int LEDPin = 1; // Onboard LED | int LEDPin = 1; // Onboard LED | ||
| - | long duration; | + | long Time_Echo_us; |
| long inches; | long inches; | ||
| Line 135: | 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> | ||