Author Topic: Is this sensor safe for Oak (3.3v)  (Read 4393 times)

brohan

  • Jr. Member
  • **
  • Posts: 59
Is this sensor safe for Oak (3.3v)
« on: July 27, 2016, 10:14:57 pm »
I am working on putting together the Ultrasonic tutorial. I have been working with a sensor (us-100, see link below)  that says it works with 3.3 volts. It appears to me that the distance it measures is accurate (whereas the HC-SR04 5v sensors aren't accurate at 3.3v). My concern is that the input pin isn't receiving more than it can safely handle. How can I check? I've been running my setup for about 20 minutes, and no funny smells.

On a side note, when I contribute to a wiki tutorial, do I need to do the entire entry at once, or can I work on it over a period of days.

Thank you for the input.

Sensor:
http://air.imag.fr/index.php/US-100_Ultrasonic_Distance_Sensor_Module

aztorell

  • Newbie
  • *
  • Posts: 6
Re: Is this sensor safe for Oak (3.3v)
« Reply #1 on: July 28, 2016, 06:12:58 am »
As long as you powered the sensor from the regulated 3.3V supply on the Oak, you'll be fine.

brohan

  • Jr. Member
  • **
  • Posts: 59
Re: Is this sensor safe for Oak (3.3v)
« Reply #2 on: July 28, 2016, 06:37:08 am »
Thank you. The HC-SR04 info I read showed one needing a voltage divider to protect a 3.3v device, even with giving it 3.3 on the trig pin.
« Last Edit: July 28, 2016, 06:49:37 am by brohan »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Is this sensor safe for Oak (3.3v)
« Reply #3 on: July 28, 2016, 05:38:20 pm »
Yes, if were a HC-SR04-type model that supports running from 3.3v and 5v (like the HC-SR04+), it will be safe to use when run from 3.3v without any level shifting. That particular model appears to a more specialised one, in that it has a jumper on the back that changes the echo and trigger pins to become Serial RX and TX pins, and enables a serial link. You'll need to be very clear in the tutorial that it is not the common ultrasonic sensor that people will encounter / get it starter kits. The normal cheapie unit that people would buy or get in starter kits would need a level shifter (resistive one being the simplest) of some description unless they were lucky enough that it runs from 3.3v.

As far as the wiki, put a note at the top of the page that it is a work in progress and you'll be fine to work on it incrementally.

And for future tinkering, you might find a logic level shifter like one of these handy handy to have - and because its bi-directional, it should work with just about any sensor or module you throw at it. You can get cheaper two channel ones, but for just a bit more you can't beat the dedicated 8CH modules. They are always handy to have, especially when you suddenly realise the part you wanted to use has 5v I/Os, and you just want to get the darn thing working! ;)

brohan

  • Jr. Member
  • **
  • Posts: 59
Re: Is this sensor safe for Oak (3.3v)
« Reply #4 on: July 29, 2016, 08:42:13 am »
PeterF: As always thank you for the response and insight. I didn't realize there was an HC-SR04+, I grabbed the US-100 as it was available on Amazon Prime, and had the lower voltage specs. I has surmised that one had to use what was included in the starter parts list in the starter tutorial, but was perplexed with the 5v req of the HC-SR04, but no shifter in the kit. I'm excited to put together a tutorial for the Ultrasonic, and will be sure to clearly specify that I am using something other than a standard HC-SR04.

I now have an 8 channel logical bi-directional level shifter on the way to add to what was my small collection of micro-electronics :-).


Rando

  • Newbie
  • *
  • Posts: 8
Re: Is this sensor safe for Oak (3.3v)
« Reply #5 on: August 01, 2016, 08:40:02 am »
Hi!,

Thanks for the pointer to the + model. I wasn't aware there was a low voltage version the HC-SR04.

Rando

brohan

  • Jr. Member
  • **
  • Posts: 59
Re: Is this sensor safe for Oak (3.3v)
« Reply #6 on: August 04, 2016, 04:33:59 pm »
I picked up a TXB0108 level shifter to start working with the HC-SR04. Below is how I connected the pins:


OAK   ->   txb0108   <-   hc sr04
3.3vcc->   VCCA      
                 VCCB   <-   VCC
                 GND   <-   GND
3.3vcc ->    OE   
Pin 2 ->      a1      
Pin 4 ->      a2         
                   b1   <-   trig
                   b2   <-   echo

Here is the sketch:

Code: [Select]
/*
 HC-SR04 with TCB0108 level shifter
 VCC to Oak vcc
 GND x2 to Ground Rail to Oak Ground
 Trig to Oak Pin 2
 Echo to Oak Pin 4
 */


int trigPin = 2; // Trigger Pin
int echoPin = 4; // Echo Pin
int LEDPin = 1; // Onboard LED

long duration;
long inches;


char post_Distance[16]; //particle post variable

void setup() {
 
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(LEDPin, OUTPUT); // Use onboard LED as indicator
 
}

void loop() {
/* The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. */

 //reset trig pin
 digitalWrite(trigPin, LOW);
 delay(100);

//send pulse
 digitalWrite(trigPin, HIGH);
 delay(10);
 
 //stop sending signal
 digitalWrite(trigPin, LOW);
 
//listen for echo pulse
duration = pulseIn(echoPin, HIGH); 
 
// Calculating distance by pulse width
 inches = (duration/2) / 74;

//Send distance to cloud for viewing
 sprintf(post_Distance, "%06d", inches); //convert int to string for Particle.publish
  Particle.publish("distance:", post_Distance);
 
//use onboard LED for visual feedback             
 if((inches < 144) && (inches > 1)) {   // Length effective range (1, 3000).
 
digitalWrite(LEDPin, HIGH);
 }
 else {
 digitalWrite(LEDPin, LOW);
 }                           
   
 delay(1000);                               
 
}


When I power up the Oak, I still receive all zeros for my distance in the Particle logs.

Is this the correct way to use the level shifter?
Is this level shifter responsive enough to listen to the return echo and report it?

Thanks for helping me understand the level shifter.

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Is this sensor safe for Oak (3.3v)
« Reply #7 on: August 04, 2016, 05:18:35 pm »
Two things jump out unless I'm misreading your connections...

You need to make sure that GND is connected to all devices - so connect the Oaks GND to the txb0108, and the oak,txb0108 and hc sr04 will all have a common ground (reference). Doesn't matter what the voltage is, generally you want a common ground for all devices. - although it seems from your sketch comment that you have connected ground all the way through...

You've connected the Oaks 3.3v to one side of the shifter, but it doesn't look like you've connected any power to the HC-SR04... the level shifter doesn't provide any power, it just does the translation. You need to connect the low voltage to one side (like you've done with VCCA) and the higher voltage to the other (VCCB). Since you're probably powering the Oak from the USB port, you can use the VIN pin to get the 5v supply for the high side, so just connect VCCB to VIN (if powering from the usb port).

OAK   ->   txb0108   <-   hc sr04
3.3vcc->   VCCA     
VIN ->       VCCB   <-   VCC
GND->       GND   <-   GND
3.3vcc ->    OE   
Pin 2 ->      a1     
Pin 4 ->      a2         
                   b1   <-   trig
                   b2   <-   echo

brohan

  • Jr. Member
  • **
  • Posts: 59
Re: Is this sensor safe for Oak (3.3v)
« Reply #8 on: August 04, 2016, 05:38:00 pm »
My limited experience did have me wondering how the chip could take in 3.3 and put out 5, in reference to pluging the VIN to the 5V side of the TXB0108
In my diagram (and reality) I didn't have the Oak grounded. I ran a ground from the Oak to the same breadboard line with the TXB0108 GND and the HR-SR04 GND

Viola, It works. Many, many more wires than using the 3.3v sensor, but doable, and I'm glad for the experience that I will no doubt need.

Thank you sir.




PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Is this sensor safe for Oak (3.3v)
« Reply #9 on: August 04, 2016, 06:04:14 pm »
Lol... yes it does get messy due the need to translate the voltages :D Glad it it's working for you now...