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

Next revision
Previous revision
oak:tutorials:ultrasonic_2 [2016/08/05 08:16]
brohan created
oak:tutorials:ultrasonic_2 [2017/01/09 23:55]
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 26: Line 26:
 ===== Concepts ===== ===== Concepts =====
  
-==== 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 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 49: Line 50:
 The HC-SR04 has 4 pins: VCC, Trig, Echo, and Gnd. The particular bi-directional level shifter being used in this example has 20 pins, we will be using 8 of them. The connections get a little tricky, be sure to refer to the schematic above. ​ The HC-SR04 has 4 pins: VCC, Trig, Echo, and Gnd. The particular bi-directional level shifter being used in this example has 20 pins, we will be using 8 of them. The connections get a little tricky, be sure to refer to the schematic above. ​
  
-  *      Connect ​the VCC pin to the Oak VCC +  *      Connect the Oak VCC to level shifter VCCA + OE 
-  *      Connect ​both GND pins to the Oak GND (via GND rail) +  *      Connect ​Oak GND to level shifter ​GND 
-  *      Connect ​the Trig pin to Oak pin #+  *      Connect Oak Pin to level shifter A1 
-  *      Connect ​the Echo pin to Oak pin #4+  *      Connect Oak Pin to level shifter A2 
 +  *      Connect Oak VIN to level shifter VCCB 
 +  *      Connect Level Shifter VCCB to sensor VCC 
 +  *      Level shifter B1 to sensor Echo 
 +  *      Level shifter B2 to sensor Trig 
 +  *      Level shifter GND to sensor GND   
  
  
Line 60: 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 85: Line 110:
 int LEDPin = 1; // Onboard LED int LEDPin = 1; // Onboard LED
  
-long duration+long Time_Echo_us
 long inches; ​ long inches; ​
  
Line 129: 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>​
Line 169: Line 194:
  
 What can **you** use an ultrasonic sensor for? What can **you** use an ultrasonic sensor for?
-  * "​eyes"​ to keep robot from running into something +  * Trigger ​buzzer when someone / something ​walks past 
-  * Connect an RGB, put in your garage for parking distance guide+  * Use a sensor on a servo to create ​map
oak/tutorials/ultrasonic_2.txt · Last modified: 2017/01/09 23:55 by Rover#18