Maker Pro
Maker Pro

OP amp guidance for newbie

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
hi all.

im a newbie so excuse any ignorant questions in advance.
Im 39 and doing a part time college degree and decided to do something with arduino uno for a project. I have little practical experience with electronics but have read a lot over the years. unfortunately my memory isn't the best so even when I understand something, I have forgotten it a couple of days later.

im looking for some guidance on what sort of op amp I should use to amplify the voltage output of a sphygmomanometer pressure sensor (MPS200N0040D-D). its a small traffic light system im doing with red lights being activated by the pressure sensors. from my research I have concluded that the sensor outputs a 0-25mv signal.im looking for about 5v for the input to the arduino. im not concerned with the value of the signal, I just want it to turn on a red light if any pressure is recorded. any advice greatly appreciated.

Thanks all
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
Welcome to EP.

For converting an analog signal 0 ... 25 mV into a digital signal (0 V / 5 V or 0 V / 3.3 V depending on the type of arduino) you need a comparator, not an amplifier. Any comparator with single supply operation and rail-to-rail inputs and outputs will work. See for example the LMV7291. Set the reference voltage such that at a presuure greater than you defined limit the output of the comparator becomes active. Add some hysteresis as described on pages 11 ff. of the datasheet to reduce sensitivity to noise.

Alternatively you can feed the 0 ... 25 mV signal directly into an ADC input of the Arduino and use the digitized signal in software to make the on/off decision. This makes use of an external opamp or comparator unnecessary.
 

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
Welcome to EP.

For converting an analog signal 0 ... 25 mV into a digital signal (0 V / 5 V or 0 V / 3.3 V depending on the type of arduino) you need a comparator, not an amplifier. Any comparator with single supply operation and rail-to-rail inputs and outputs will work. See for example the LMV7291. Set the reference voltage such that at a presuure greater than you defined limit the output of the comparator becomes active. Add some hysteresis as described on pages 11 ff. of the datasheet to reduce sensitivity to noise.

Alternatively you can feed the 0 ... 25 mV signal directly into an ADC input of the Arduino and use the digitized signal in software to make the on/off decision. This makes use of an external opamp or comparator unnecessary.
Thanks harald. Obviously I would like to make it as easy as possible for myself but at the same time I wouldn't mind putting extra bits in for wiring/coding experience. I had read somewhere that 25mv might be too low to register as an input but obviously not. I may have to leave the playing around with arduino for a future hobby as I'm working full-time , in college part time, have a 4 year old and two more on the way ( both from my wife ) I'll just concentrate on the project for the minute so if be grateful for any assistance in the future! Thanks again
 

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
Hi again harald/other electronic experts. I've been messing around with my arduino for a couple of evenings and searching the net for info but I am struggling with the coding (And maybe the wiring) can you tell me what code I write to the arduino uno to tell it to only turn the output pin high,when I get a voltage in on analog input pin. I have declared pin 8 an output but it is lighting my led constantly. Basically I am using a spyghomanometer as a pressure sensor, which when activated sends a low voltage to pin A1, which in turn sends 5 volts out of pin 8 to an led via a resistor! I may have the wiring of the spyghmanometer incorrect but any help on coding would be welcome at the moment!
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
I'm sorry, I'm not versed in Arduino coding in special.
What you need to do:
- wire the sensor to an AC input pin
- initialize ADC for reading from that pin
- within a loop
- read analog pin
- check value whether it is above or below the threshold and turn the Light on/off correspondingly

This sample code for reading the analog value should get you started.
 

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
Hi harald.
I have tried to figure out the coding of the analog input but am getting nowhere at the moment. As the link you sent me says, when I have nothing connected to the analog input I am getting input values of a few hundred which equates to about 1volt (I presume as 0 to 1023 = 0 to 5volts). The problem is my sensor will only be input between 0 and 25mv so how do I differentiate between my sensor and noise/interference? I think I may need a pullup/pulldown resistor but I'm not sure how to configure!
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
The input has a high impedance. When you connect your voltage source to it, most of that noise will disappear.

If you know the impedance of your voltage source you could initially replace it with a resistor of that value.

A simple op amp circuit with a gain of 100 will give you a 0 to 2.5V signal which you might decide is valid if it exceeds a count of 512 ( 2.5V) or maybe some lower value (some experimentation may be required).

You would want an op-amp which allows inputs and outputs to go to the supply rail.

The use of a comparator (as suggested above) is also a viable option, but some of your experimentation will be in hardware, and you've told us that not your strong suit.

Do you just have a 5V rail for the Arduino, or are you powering it from a higher voltage (presumably via a regulator)?
 

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
Hi Steve. Thanks for the help. Im not up to speed yet to understand all your questions but I think it' best if I just say exactly what I'm doing.
I am powering the arduino uno from a laptop and am simply trying to use a pressure sensor to turn on an led. (At the beginning anyway).The pressure sensor (spyghomanometer) is a wheatstone bridge and I have wired as follows!

I have a 5v output going to + input of the bridge
The - input is connected to ground.
Two negative outputs are connected to same ground.
+ output is connected to A0 on analog in.

What has me confused is that I also have my + output grounded via a 10k resistor but I am still reading 412 on the input monitor! I have got it to work by writing code that the led Will only light if input is 413 or over. When I blow on the sensor via a straw I can light the led!

If I'm not mistaking 412 equates to about 2volts so why am I reading that when the output is grounded via the resistor and also the sensor is only supposed to output 0 to 25mv when activated! Im reading 2volts(412) without it being activated. Maybe it' the way I have wired the bridge but it sounded straight forward. Apologies if I'm not making sense...i am in my limited head!
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Hi Brian, the output of a wheatstone bridge is a differential signal.

You should be looking at the difference between the two outputs, probably by connecting them independently to tell different analog input pins.

You should not as any additional resistance to ground.

I assume the bridge outputs are part of the device? Do you have a link to the datasheet?
 

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
Thanks again.This is all I could find!
 

Attachments

  • Screenshot_20180212-075706.png
    Screenshot_20180212-075706.png
    531.2 KB · Views: 87
  • Screenshot_20180128-223910.png
    Screenshot_20180128-223910.png
    257.1 KB · Views: 70

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
The bridge output is part of the device. Basically if any pressure is received on the sensor, I want the led to light. I also need to put another pressure sensor in that stops the led from lighting if it is activated within 1 second of the first one.
 

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
Thanks again.This is all I could find!
Hi Brian, the output of a wheatstone bridge is a differential signal.

You should be looking at the difference between the two outputs, probably by connecting them independently to tell different analog input pins.

You should not as any additional resistance to ground.

I assume the bridge outputs are part of the device? Do you have a link to the datasheet?
Hi again.
I rewired my bridge to send my two Vouts to two analog inputs and tried to write code so that an led would light depending on the difference in both values. The problem I have now is I can' get the led to change state when I use a straw to blow the sensor. According to the serial monitor (if I have coded correctly) I'm getting a value of 510 on both inputs and when I blow straw these change slightly to around 508 and 512. However my led stays in the same state! I' not sure if my coding is incorrect or if the arduino has to see a bigger difference than that between the values before it decides they'e not equal. I have attached a snip of the code and monitored values which includes a variation in values when I blew on straw but with no change to led!!???
 

Attachments

  • arduino.PNG
    arduino.PNG
    53 KB · Views: 58

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
You probably want something like

Code:
Int diff;
.
.
.
diff = analogread(A1) - analogread(A0);
digitalwrite(ledpin, diff > 2);

The main difference is that you use analogread(A1 - A0) which means something entirely different to analogread(A1) - analogread(A0).

The fact you read the values to display, then pause before reading them again means that the values you display are different to those you act on. It would be better to store the values read and displayed, and then use them to act on.
 

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
You probably want something like

Code:
Int diff;
.
.
.
diff = analogread(A1) - analogread(A0);
digitalwrite(ledpin, diff > 2);

The main difference is that you use analogread(A1 - A0) which means something entirely different to analogread(A1) - analogread(A0).

The fact you read the values to display, then pause before reading them again means that the values you display are different to those you act on. It would be better to store the values read and displayed, and then use them to act on.
Thanks Stephen . Im just trying that now. Just to confirm, did you mean I should or shouldnt write analogread(A1-A0)??
I'm not entirely sure what you mean regarding storing/reading/acting on values etc! Any recommendations for a good book on basic coding.?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Analogread is a function that returns a value. Imagine for a moment that the function is simply the square of the number passed to it. And let's call the function "square" so we don't confuse it with the actual analogread function.

Square(2) returns 4
Square(1) returns 1

Square(2-1) returns 1
Square(2) - square(1) returns 3

So they're different. But which one do you want?

The analogread function takes a single parameter, the pin from which you want to read a voltage.

Do you want to read a single voltage, from a pin that is determined by the difference between two pin numbers (analogread (A2 - A1)), or do we want to read the voltage on two pins and look at the difference between them (analogread (A2) - analogread (A1))? It should be obvious you want the latter.

The next thing to realise is that each time you call analogread the voltage on the appropriate pin is measured again. Each time you do this, the value retuned could change sure to either the voltage on the pin changing our due to noise in the system which results in some uncertainty in the value you get for a particular voltage.

What you need to do if you want to display the result of the analogread and then to do something with it is to store that somewhere.

Arduino code is just C++, so learning the basics of this language would help you. Not that a microcontroller is a different environment than used in most C++ tutorials in that a microcontroller doesn't have a keyboard or a screen for input and output.

You might be well advised to find a web site or YouTube video that goes through the basics of programming the Arduino.
 

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
Analogread is a function that returns a value. Imagine for a moment that the function is simply the square of the number passed to it. And let's call the function "square" so we don't confuse it with the actual analogread function.

Square(2) returns 4
Square(1) returns 1

Square(2-1) returns 1
Square(2) - square(1) returns 3

So they're different. But which one do you want?

The analogread function takes a single parameter, the pin from which you want to read a voltage.

Do you want to read a single voltage, from a pin that is determined by the difference between two pin numbers (analogread (A2 - A1)), or do we want to read the voltage on two pins and look at the difference between them (analogread (A2) - analogread (A1))? It should be obvious you want the latter.

The next thing to realise is that each time you call analogread the voltage on the appropriate pin is measured again. Each time you do this, the value retuned could change sure to either the voltage on the pin changing our due to noise in the system which results in some uncertainty in the value you get for a particular voltage.

What you need to do if you want to display the result of the analogread and then to do something with it is to store that somewhere.

Arduino code is just C++, so learning the basics of this language would help you. Not that a microcontroller is a different environment than used in most C++ tutorials in that a microcontroller doesn't have a keyboard or a screen for input and output.

You might be well advised to find a web site or YouTube video that goes through the basics of programming the Arduino.
Thanks Steve. Im just waking up so I'll read this again later when my brain starts to function! I got it to work last night so when I blow in the sensor I get the led to come on..however I put a delay of 8 seconds in to keep my led on for that time period and now I have an 8 second delay in every loop!! Ie. If I blow on the sensor again, I may have to blow on it for 8 seconds before led comes on. I want it to come on anytime the sensor is activated(and stay on for 8 seconds).. if u get me!
 

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
Analogread is a function that returns a value. Imagine for a moment that the function is simply the square of the number passed to it. And let's call the function "square" so we don't confuse it with the actual analogread function.

Square(2) returns 4
Square(1) returns 1

Square(2-1) returns 1
Square(2) - square(1) returns 3

So they're different. But which one do you want?

The analogread function takes a single parameter, the pin from which you want to read a voltage.

Do you want to read a single voltage, from a pin that is determined by the difference between two pin numbers (analogread (A2 - A1)), or do we want to read the voltage on two pins and look at the difference between them (analogread (A2) - analogread (A1))? It should be obvious you want the latter.

The next thing to realise is that each time you call analogread the voltage on the appropriate pin is measured again. Each time you do this, the value retuned could change sure to either the voltage on the pin changing our due to noise in the system which results in some uncertainty in the value you get for a particular voltage.

What you need to do if you want to display the result of the analogread and then to do something with it is to store that somewhere.

Arduino code is just C++, so learning the basics of this language would help you. Not that a microcontroller is a different environment than used in most C++ tutorials in that a microcontroller doesn't have a keyboard or a screen for input and output.

You might be well advised to find a web site or YouTube video that goes through the basics of programming the Arduino.
 

brian connolly

Jan 31, 2018
19
Joined
Jan 31, 2018
Messages
19
thanks steve.
that was a great help. I now have that part of it working and I am comparing the difference in analog inputs from a wheatstone bridge pressure sensor. I have my code to light an led when the difference is above 1 so that when I blow on the sensor with a straw, the difference goes up to 2/3 and the ledPin goes high. my problem now is putting a timer into it and im reading a lot of conflicting info and about numerous ways of inserting timers. basically I want the led to stay high for 8secs and then go low, but if the sensor is activated again immediately after going low, I want the led to go high again.(or if activated while high,stay on for a further 8secs) unfortunately if I just put in a delay, my whole loop will delay and this wont work!

im currently trying to use millis/currentmillis/previousmillis etc but I can only get it to work once. I need to figure out how to reset a timer or something like that!! I will post a pic of my current code which I Know wont work, so if you can advise on a simple code to do this that would be great.
 
Top