i want to read frequency realtime

i used a LM339 but it never work am trying to make an analog sensor output tobe square but still getting negative results...... so nick with the lm358 what do i need to change in the circuit to get a high input when my sensor gives 200mv o maybe 100mv...... its an inductive sensor so when the magnetic field its low the output voltage its 100mv or something near.....

this is a sample on my sensor took from the analog A0 and plotted with kst

Uploaded with ImageShack.us

for this i am holding a magnet with my hand and passing it to the sensor the fastar as i can, but if you see there when is low speed the output get too low voltage, anl also there is a lot of noise coming from the sensor

Right. Well what you want to do is set up the op-amp as a comparator. You need a voltage divider on the - input to the op-amp (eg. pin 2) and your signal into the + (eg. pin 3) input.

Looking at this page:

http://www.raltron.com/cust/tools/voltage_divider.asp

I type in that I have 5V input voltage, and a 10K as R1 (from 5V to pin 2). I want 100 mV comparison voltage for the op-amp so I type 0.1 as the output voltage and hit "calculate". It tells me to use a 204 ohm resistor, so say use a 220 ohm between pin 2 and ground. Now you should be able to measure around 0.1V on pin 2 of the op-amp. That means it will turn on when the input on pin 3 is above 100 mV and turn off if it is less, thus "squaring up" your input.

Something like this:

thank you so much jejje ummm but i cant get an op-amp right now stores are close so i need to wait till monday.
but maybe a could try this with the lm339 if not i will have to wait till then....

thanks again all of you techone, nick gammon and retrolefty..... you guys have help me a lot

one doubt 220R its going to ground?

copachino:
thank you so much jejje ummm but i cant get an op-amp right now stores are close so i need to wait till monday.
but maybe a could try this with the lm339 if not i will have to wait till then....

thanks again all of you techone, nick gammon and retrolefty..... you guys have help me a lot

one doubt 220R its going to ground?

Here is a link to the datasheet for a LM339. There is a typical application section that should show you how to use the chip. Most people that have trouble with this chip forget that it has an open collector output that requires an external resistor wired between the output pin and +5vdc. The programmable internal pin pull-up option for an arduino input pin can satisfy that requirement.

copachino:
one doubt 220R its going to ground?

Yes. Effectively the 10K and the 220 ohm added together give 10.2K between 5V and ground. We are sampling that at 220/10220 along that, being 0.0215 of the total "distance". Multiply that by 5 and we get 0.1076V, which is 107 mV.

So the comparator compares the input to the comparison voltage of 107 mV.

Your LM339 looks like it should do a similar job.

look this is an lm339 but i dont undestand it.... for example why the are using a 3k resistor and where does that voltage goes???

Uploaded with ImageShack.us
also resistor need tobe that high, or they have tobe changes in oder to input 100mv

copachino:
look this is an lm339 but i dont undestand it.... for example why the are using a 3k resistor and where does that voltage goes???

Uploaded with ImageShack.us
also resistor need tobe that high, or they have tobe changes in oder to input 100mv

The 3k resistor is the external pull-up resistor I mentioned in my prior posting. It should wire to either +5vdc or +3.3vdc depending on what voltage your arduino board runs at, +5vdc for a standard Uno type board. The VO point is the signal you wire to your arduino digital input pin of choice. Also note that the drawing you posted doesn't show the power and ground connections used for the chip it'self.

Lefty

Forget about the hysteresis. Forget about the 3K resistor. Lefty said if you configure that pin with a pull-up that will have the same effect.

Just wire up the + and - as I showed above.

yes, i know lm339 need input voltage to pin 4 and 8 i think, anyway its in the datasheet, i will try with the internal pull of but, id rahter use the external one......

only as a doubt, the output of the pull-off resistor goes again to v+ right, that what it call hysteresis??

copachino:
yes, i know lm339 need input voltage to pin 4 and 8 i think, anyway its in the datasheet, i will try with the internal pull of but, id rahter use the external one......

Either should work, and the value is not critical, so anything 3k or higher ohms.
only as a doubt, the output of the pull-off resistor goes again to v+ right

No, because It's possible to run the LM339 chip at a higher voltage then the arduino runs at, and in that case you wouldn't want to wire the output pull-resistor to that higher voltage. It needs to be wired to the arduino +5vdc pin, if your LM339 is not being powered already from +5vdc. By not using the pull-up resistor and just using the arduino pull-up option you don't have to worry about this at all.

That make sense?
, that what it call hysteresis??

Hysteresis feedback is just a method to make the comparator a little less likely to switch high and low sporadically if there is no input signal present, or if it's a very weak input signal. As long as you have a suitable voltage input signal wired to the chip you probably don't need to use that feedback 'feature'.

Lefty

I just tested with an LM339 I happened to have lying around.

That works fine:

i tried it right now and works fine, monday will look test ir with an osciloscope to see it better, but i tried with a 4.7k and 470R resistors i had lying there, and for external pull-off used a 10k resistor......

this work really well with both of my sensor inductive one and also for the optical sensor....

ummm somethig its wrong with this i just try it and see that there its a problem, when output of the sensor becomes zero, i always get 5v cos noises get in input and it generates signals that becomes pulses.....

@retrolefty

Thank for the link about the LM339 datasheet. I did have one, but not that one you link. The circuits will give me some ideas. And the pull-up resistor, <-- I did know about this little info :roll_eyes:

In my experience with the LM339, it work fine for a signal going from 0 V to positive and back. But I try with an AC signal in, Flat line... just be aware of that fact.

Techone:
@retrolefty

Thank for the link about the LM339 datasheet. I did have one, but not that one you link. The circuits will give me some ideas. And the pull-up resistor, <-- I did know about this little info :roll_eyes:

In my experience with the LM339, it work fine for a signal going from 0 V to positive and back. But I try with an AC signal in, Flat line... just be aware of that fact.

An LM339 can work very well with AC input signals. Usually such an application works better if you power the chip with a bipolar voltage supply such as +5vdc and -5vdc rather then a single positive polarity supply and ground. The application section of that linked datasheet shows several examples of using the chip with an AC input signal.

Lefty

@retrolefty

I discover that. Thank for the link by the way.

copachino:
i tried it right now and works fine, monday will look test ir with an osciloscope to see it better, but i tried with a 4.7k and 470R resistors i had lying there ... this work really well with both of my sensor inductive one and also for the optical sensor....

...

ummm somethig its wrong with this i just try it and see that there its a problem,

Does it work really well or not?

According to those resistor values the comparator should be comparing to 455 mV (which sounds a bit high). This certainly should not be triggering on the noise you showed. I'm not convinced you have it wired up according to that circuit, if you are having problems.

the first one doesnt have problems with noises.... but using the one with 1ok and 220R it gives me always 5v cos the noises, probe it changing resistor values

Well you have to get the cut-off voltage right. On the figures you quoted my resistors should have been right, but only you can tweak them so it works exactly right for you.