Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 9 months ago.
How to measure voltage between two pins on mbed?
Hello everyone!
I am a starter of mbed and I have got mbed LPC1768 and a mbed application board.
I want to know whether there is any way to measure voltage between a pin and the GND pin (like p17 and GND) and show the vltage value by using the LCD display on mbed application board.
I have tried to use mbed and a voltage meter to detect a same vltage, but I got different values.
I have also got a Xbee model, so want to know how can I use two Xbee to let them communicat point to point?
Many thanks for everyone who may help me!
2 Answers
10 years, 9 months ago.
To add to Wim's answer...
For voltages over 3.3V a simple resistor network is all you need. e.g.
Vin - 1k Resistor - CPU AnalogIn pin - 1k Resistor - GND
Will reduce the voltage by half allowing you to measure from 0V to 6.6V. Just remember to double the output you get from the ADC before displaying it.
Or in a more generic form if you have: Vin - R1 - AnalogIn - R2 - GND The voltage at the analog input will be Vin*R2/(R1+R2)
It's possible to do something similar for voltages under 0V by connecting the resistors to 3.3V rather than ground. However the analog input will be referenced to ground which means any noise on the 3.3V power supply (and there will be some) will show up in your measurement. Not recommended but you can do it as a hack if you need to.
Also using resistors like this makes two assumptions: That your voltage source is completely independent of the current it is supplying and that the analog inputs don't pull any current. For crude measurements these two are reasonable assumptions, higher values of resistors minimize the first effect, lower values minimize the second so it's best to pick somewhere in the middle. If you want a more accurate measurement then you'd need to look at a more complex circuit like an op-amp to buffer and scale the signal.
One further detail, if you have no idea what the input voltage will be then connect two diodes to the Analog input,
3.3V supply -|<=- Analog In -|<=- GND. (sorry about the poor ascii artwork)
Normally the diodes will do nothing but if the voltage on the analog input goes over 3.9V or under -0.6V then the diodes kick in and stop the pin from going any further out of specification protecting the CPU from damage. If you aren't using a resistor network to scale the voltage then put a 100 ohm to 1k resistor in series with the input to limit the current that flows if you do go outside the range.
10 years, 9 months ago.
You can measure analog voltages by using one of the AnalogIn pins. Use these pins when measuring analog voltages. Note however that AnalogIn can only tolerate values between 0V and 3V3. Higher or lower voltages must be modified or limited first. You could also connect an AnalogIn pin with any other mbed pin using a wire in case that is needed for some reason.