Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Connecting 5v sensors to AnalogInput


  • Please log in to reply
11 replies to this topic

#1 drischar

drischar

    Member

  • Members
  • PipPip
  • 13 posts

Posted 22 March 2012 - 06:11 AM

I am working on converting a project of mine over from an Arduino to a Netduino. I'm definitely a noob when it comes to this sort of stuff. From what I understand, the analog inputs on the Netduino use 3.3V rather than the 5V on the Arduino. This causes a bit of trouble as some of my sensors require 5V in order to work correctly. My temperature sensors are great at 3.3V, but I have 3 gas pressure sensors that require 5.1V +- .25V to work correctly. The output of the pressure sensor is a linear value that corresponds to a value between 0 and 250kPa. In order to get these sensors working on the Netduino, I need to figure out a way to convert the 0-5V analog signal into aa 0-3.3V analog signal. I *might* be able to get by without doing this, as I should never exceed ~110kPa and therefore won't break the 3.3V limit, but that's playing a bit more dangerous than I would like. Is there a decent method to drop the voltage down to 3.3 while keeping the accuracy. From what I understand, this is where I would use a voltage divider, but I also don't understand how I can make that accurate enough that I still get the full range of my sensor since the values of resistors are not exact. I ssuppose I could give it a try (15k to 10k?), but I'd like to know if there are better options. Thanks.

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 22 March 2012 - 06:15 AM

Hi drischar, A voltage divider would be the first option I'd look at. If that doesn't give you the accuracy you need, you can use an external ADC chip (via SPI or I2C) that can accept 5V analog voltages. Chris

#3 drischar

drischar

    Member

  • Members
  • PipPip
  • 13 posts

Posted 22 March 2012 - 06:24 AM

Hi drischar,

A voltage divider would be the first option I'd look at. If that doesn't give you the accuracy you need, you can use an external ADC chip (via SPI or I2C) that can accept 5V analog voltages.

Chris

Thanks for the quick reply. It just occured to me that the digital I/O is also 3.3V based, which actually cuts out a number of digital sensors I am using as well, so I am rethinking this whole move. Unfortunately, everything I have for this project right now is 5V based (serial LCD, digital sensors, analog sensors).

I assume there is no way I can just force the board to use 5V all over without frying things :-P At this point, I would be converting every device I have.

#4 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 22 March 2012 - 06:56 AM

Hi drischar, If you know that your analogue sensor output will not be above 3.3V, then there is not a problem. (I am using some 5V range sensors whose analogue output is always below 3.3V.) If you have others that do generate above 3.3V, then the first thing to try is a voltage divider. Yes, resistors are not 100% accurate, 5% is typical. You can get round this by calibration of the readings, or buying a batch of resistors and selecting ones that are a good match. e.g. choose a pair that are both +5%, rather than one that is +4% and one that is -3%. That way you get an accurate ratio with inaccurate resistors. As for digital sensors, 5V input levels to the Netduino are OK. But, you might have some issues driving devices with the 3.3V outputs. There are some shields that will convert digital voltages. Its a lot to take in, but I'll think you will get on with the Neduino. Hope this helps - Paul

#5 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 22 March 2012 - 07:06 AM

At this point, I would be converting every device I have.

There is a relatively easy way to convert 5V <-> 3.3V signal using a MOSFET - see Bi-directional level shifter (pdf) application note or SparkFun's Logic Level Converter to get the idea.

#6 drischar

drischar

    Member

  • Members
  • PipPip
  • 13 posts

Posted 22 March 2012 - 07:46 AM

Hi drischar,

If you know that your analogue sensor output will not be above 3.3V, then there is not a problem. (I am using some 5V range sensors whose analogue output is always below 3.3V.)
If you have others that do generate above 3.3V, then the first thing to try is a voltage divider.
Yes, resistors are not 100% accurate, 5% is typical. You can get round this by calibration of the readings, or buying a batch of resistors and selecting ones that are a good match.
e.g. choose a pair that are both +5%, rather than one that is +4% and one that is -3%. That way you get an accurate ratio with inaccurate resistors.

As for digital sensors, 5V input levels to the Netduino are OK.
But, you might have some issues driving devices with the 3.3V outputs.
There are some shields that will convert digital voltages.

Its a lot to take in, but I'll think you will get on with the Neduino.

Hope this helps - Paul

Given that I can use 5V inputs (I have a few digital sensors that will output 5v), this may still be doable. In total I have:
- 2 analog temperature sensors (TMP36, designed for 3.3v so no problem there)
- 3 analog pressure sensors (from freescale, don't recall model but they require 5v)
- 3 swissflow SF800 flow sensors, no input but will output (input on the Netduino) 5v pulses at about 100-300/second.
- BlueSmirf bluetooth modem, which works fine on 3.3v
- 5V serial LCD, which won't work, but I could just get a 3.3v version and use the 5v elsewhere. Of course, my wife thinks I should leave the LCD out completely, so she may get her wish.

Sounds like this can all still work. I don't need to output 5V anywhere, and as long as the 3.3v inputs won't smoke at 5V I might be able to make this.

This is designed to record data from the 3 tap kegerator I have in my kitchen, if I were to run enough CO2 pressure in the lines to raise the analog input over the 3.3v threshold, I would be in danger of bursting my lines, so I might be able to get by just hooking them straight up to the analog pins.

Thanks everybody, I'll let you know how it goes.

#7 MDS

MDS

    Member

  • Members
  • PipPip
  • 16 posts

Posted 22 March 2012 - 10:13 AM

You really need to scale the 5V down to 3.3V even if the pins can take 5V your readings wont be acurate. I would also say to you that you should put the input through a voltage follower before you go into the voltage devider. If the reading is critical you dont want a voltage spike frying the ADC channel. Its good practice to use voltage followers for all external sources. If your looking to make sure that the presure does not go above a known value you can also use a voltage comparitor with the output going to one of the digital pins. The comparitor is an opamp so it acts like a voltage follower to protect the processor.

#8 drischar

drischar

    Member

  • Members
  • PipPip
  • 13 posts

Posted 24 March 2012 - 09:14 PM

Alright. I'm pretty set on making this work on the Netduino, so I've been looking into using external ADCs for the pressure sensors and communicating with SPI. For the temperature sensors (which would have worked on 3.3v), I may switch to 1wire DS18B20 and get rid of using analog sensors for temperature completely which makes it s little easier since I don't have to worry about switching the analog pin and sleeping to let it settle. In looking at external ADC chips (say, MCP3002), I'm a little confused on how I can make the analog comparison get done at a 5V reference whil the SPI communication takes place at 3.3V. That is, unless I can just run it on the 5V and let is go. If the digital pins (10-13 for SPI) allow 5V in, then this could work, as long as 3.3V out will be good enough for the ADC. It still feels a little kludgy though. A really elegant solution would be a ADC that has two voltage inputs one for the data communication (3.3v) and one for the Vref (5V). Does such a thing exist or will the MCP3002 work out just fine?

#9 drischar

drischar

    Member

  • Members
  • PipPip
  • 13 posts

Posted 24 March 2012 - 09:19 PM

Alright. I'm pretty set on making this work on the Netduino, so I've been looking into using external ADCs for the pressure sensors and communicating with SPI. For the temperature sensors (which would have worked on 3.3v), I may switch to 1wire DS18B20 and get rid of using analog sensors for temperature completely which makes it s little easier since I don't have to worry about switching the analog pin and sleeping to let it settle.

In looking at external ADC chips (say, MCP3002), I'm a little confused on how I can make the analog comparison get done at a 5V reference whil the SPI communication takes place at 3.3V. That is, unless I can just run it on the 5V and let is go. If the digital pins (10-13 for SPI) allow 5V in, then this could work, as long as 3.3V out will be good enough for the ADC. It still feels a little kludgy though. A really elegant solution would be a ADC that has two voltage inputs one for the data communication (3.3v) and one for the Vref (5V). Does such a thing exist or will the MCP3002 work out just fine?

To be a little more clear, I relaize I can use a transistor or something to make the 5V communication 3.3v instead, but I've never done something like that with data transmission and I have no idea whether it would work or be worthwhile.

#10 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 25 March 2012 - 04:13 AM

Alright. I'm pretty set on making this work on the Netduino, so I've been looking into using external ADCs for the pressure sensors and communicating with SPI. For the temperature sensors (which would have worked on 3.3v), I may switch to 1wire DS18B20 and get rid of using analog sensors for temperature completely which makes it s little easier since I don't have to worry about switching the analog pin and sleeping to let it settle.

In looking at external ADC chips (say, MCP3002), I'm a little confused on how I can make the analog comparison get done at a 5V reference whil the SPI communication takes place at 3.3V. That is, unless I can just run it on the 5V and let is go. If the digital pins (10-13 for SPI) allow 5V in, then this could work, as long as 3.3V out will be good enough for the ADC. It still feels a little kludgy though. A really elegant solution would be a ADC that has two voltage inputs one for the data communication (3.3v) and one for the Vref (5V). Does such a thing exist or will the MCP3002 work out just fine?


There's no need of extra hardware to connect the Netduino SPI to the ADC. The ADC chip is able to recognize an high level when the voltage is at least 3.5V: the Netduino gives it at 3.3V, so it's pretty close to the limit...but it should work. On the other side, any discrete input of the Netduino is +5V-tolerant, which means that you can apply a voltage above the nominal +3.3V.

Anyway, before starting to write code and glue various chips, I'd dig a bit deeper around your sensors. It's much like purchasing a box without actually knowing what's inside.
From what I see, the only doubt is about the pressure sensor. Could you get some additional info? Is it a low pressure (e.g. atmospheric), or high pressure (e.g. weight)? Is it possible for you to simulate a "worst case" pressure, and measure the output voltage with a multimeter?
I guess that you can glue any of your devices to the Netduino with a very small effort.
Cheers
Biggest fault of Netduino? It runs by electricity.

#11 drischar

drischar

    Member

  • Members
  • PipPip
  • 13 posts

Posted 27 March 2012 - 03:30 AM

There's no need of extra hardware to connect the Netduino SPI to the ADC. The ADC chip is able to recognize an high level when the voltage is at least 3.5V: the Netduino gives it at 3.3V, so it's pretty close to the limit...but it should work. On the other side, any discrete input of the Netduino is +5V-tolerant, which means that you can apply a voltage above the nominal +3.3V.

Anyway, before starting to write code and glue various chips, I'd dig a bit deeper around your sensors. It's much like purchasing a box without actually knowing what's inside.
From what I see, the only doubt is about the pressure sensor. Could you get some additional info? Is it a low pressure (e.g. atmospheric), or high pressure (e.g. weight)? Is it possible for you to simulate a "worst case" pressure, and measure the output voltage with a multimeter?
I guess that you can glue any of your devices to the Netduino with a very small effort.
Cheers

The pressure sensor that I am using is a Freescale MPX4250GP. Freescale has other sensors, but none that quite meet my requiremnts for pressure range. The idea is that the sensor reads CO2 pressure on a keg of beer which can range from 0 to 30psi (this sensor supports 0 to 36psi). Normally, I would have just about any beer at around 10-15psi which puts the output of the sensor within the 3.3V range (should be... I need to check with a multimeter but my CO2 tank is empty), but in the end it would be best to support the full range, which will require an external ADC. I'll just let the ADC communicate with the Netduino at 5V.

I'm still looking at the MCP3002 (it's the only standalone ADC I can find at Sparkfun). I've never done SPI before, but I'm always up for something new.

#12 drischar

drischar

    Member

  • Members
  • PipPip
  • 13 posts

Posted 28 March 2012 - 01:27 AM

The pressure sensor that I am using is a Freescale MPX4250GP. Freescale has other sensors, but none that quite meet my requiremnts for pressure range. The idea is that the sensor reads CO2 pressure on a keg of beer which can range from 0 to 30psi (this sensor supports 0 to 36psi). Normally, I would have just about any beer at around 10-15psi which puts the output of the sensor within the 3.3V range (should be... I need to check with a multimeter but my CO2 tank is empty), but in the end it would be best to support the full range, which will require an external ADC. I'll just let the ADC communicate with the Netduino at 5V.

I'm still looking at the MCP3002 (it's the only standalone ADC I can find at Sparkfun). I've never done SPI before, but I'm always up for something new.

Alright, I finally picked up the hardware to convert the tubing on my tank down to the 1/8" inside diameter tubing to connect to the pressure sensor. My tank wasn't quite empty (no liquid, but stil enough gas to run a test). I hooked up the sensor, and then eyeballed the values from the guage and I'm pretty accurate according to what the datasheet says I should be getting.

The bottom line is, I don't hit the 3.3V limit until I reach nearly 24psi. At a temperature of 37*F that allows me to put 3.75 volumes of CO2 into a beer and still be able to handle the value on the Netduino ADC. That covers just about any style of beer I will put in there. If I were to put homemade soda, I'd want to raise it to 4volumes, which puts me at 30psi but that would be such a rare occasion I probably dont need to design for it (I can remove the sensor when that happens).

So thanks for all the help. It looks like I'll just be connecting the sensor directly to the arduino, and never raising the guage above 24 while it is connected. To be honest, I'd be afraid of >24psi on that thing anyhow.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.