So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By shoelessone
#80404 This question has been asked in one form or another a bunch of times in a bunch of places, but to be honest I'm still a bit confused and would really appreciate some specific practical advice for my situation.

I am creating a custom PCB for a project I'm working on, and the input voltage for the board will be from USB, so 5V. I have a regulator that will give me a clean 3.3V for the ESP.

I also have a Sharp distance sensor (http://www.sharp-world.com/products/dev ... 21yk_e.pdf) that operates on 5V. I figure (feel free to tell me I'm wrong!) I can provide power to this sensor from the USB 5V, but that leaves me with an issue actually reading the output from the sensor via an ADC pin.

My question is, how can I do this while still getting accurate readings? I've googled and read "shift register" is an answer, but that seems to be more for digital signals (?).

I don't need anything super "fast", if that matters, I hope to monitor the distance at regular intervals but it's nothing where milliseconds count or anything.

Any specific advice to my specific situation would be very much appreciated!!
User avatar
By btidey
#80408 The sensor has an analog output ranging from 0 - 3.2V.

So you need to feed this into an ADC.

You could use the internal ADC of the ESP8266. This has a basic range of 0- 1.0V so you would need a potential divider to step down the output of the sensor to that range. Something like sensor to 220K resistor, 100K to 0V, and the junction into the ADC input.

The internal ADC is not brilliant. Theoretically it is a 10 bit converter, but internal conversion noise limits it to more like 7 bits. One can do some software averaging to improve it a bit. Also its absolute accuracy varies from unit to unit so it is best to calibrate that out. Overall even with caibration one is talking about 1% accuracy in the readings corresponding to about 1cm distance.

This may be OK for your purposes. If you do need better ADC performance then one can use an external ADC interfaced via I2C.
User avatar
By schufti
#80413 somehow the datasheet is inconsistent:
the table says Vout max is vcc +0.3V and vcc to be 5V ideally, so Vout can be assumed to reach 5V
the curves (asuming 5V Vcc) show Vout allways lower than 3.3V.
I would check real device first ... or at least have some clamping circuit.
User avatar
By btidey
#80422 The data sheet is not brilliant. However, with the output stepped down through a divider into the ADC there is no real danger of damaging the input. The worst that could happen is that it would readings would top out if the AD voltage exceeded 1V.