Happy new year ,
I need a little help here . I need ,I guess IF ELSE loop to find a minimum "analogread" input .
I am reading a slow fluctuating voltage. When the voltage reach a minimum voltage value, a LED is set "on" , when this voltage again increase in value LED is "off" . When the voltage again reach a new minimum value the LED is "on" again .
The problem is that the minimum voltage value is not Zero volts or the same low value for each minimum . It can be 3volt and next minimum 1volt , next again maybe 2 volt.
It is just the TESTing loop I am not sure how to do , I think I know how to set the LED on/off . Eventually I need to power a DC motor that turns a capacitor until a minimum feedback voltage is reached .
When you refer to a 'minimum' voltage, do you mean that you have a fixed threshold and you want the LED to light while the signal is below the threshold? Or by 'minimum' do you mean you want to find (and remember) the lowest value ever seen and only light the LED when you get a new value which is lower than any seen previously?
I want to detect the bottom of the curve , this is what I call minimum .
I have a motor that adjust a capacitor, and a detector circuit will send a feedback voltage that I will read via analogread. The motor will adjust the capacitor for minimum feedback voltage and then stop. However dependably on how well this capacitor adjust , the minimum feedback voltage can be any voltage between 0 and 4.9 volts . Any minimum in the feedback voltage is regarded as a success and must stop the motor from turning the capacitor any further .
I am interested in the Test "decision" for minimum , not the motor control , that is why I use a LED for illustration of the problem.
So it is not a local max. but a local min. I want to test for. I think if I reverse your suggestion it will work for min. , let me try-
I check your link, and it seem that you want to measure a negative voltage, and going straight to an analog pin is a "bad idea" - I call - kiss good bye the ardiuno chip ...
So you need an external circuit to convert to a proper 0 to 5 V signal. Maybe a inverse peak detector might work....
pathfinder:
However dependably on how well this capacitor adjust , the minimum feedback voltage can be any voltage between 0 and 4.9 volts . Any minimum in the feedback voltage is regarded as a success and must stop the motor from turning the capacitor any further .
I was having trouble visualizing the motor which turned the capacitor, until I remembered tuning capacitors like we used to have on the old radios.
Your problem is you won't know the minimum will you, until you have passed it?
Assuming for the moment that you don't actually try to put -9V into the Arduino, as Techone is worried about, you want to stop at x = 1, y = -9, right? But you don't know that x = 1 is the right spot until you overshoot a bit (eg. y might be -8.9).
So I would turn the motor slowly, noting that the analog reading goes down and down. Then when it starts to go up again you have overshot, so you might go back slightly (or just stop) and there you are!
if it is greater than last time then last time was your minimum - finish
3a) if it is not then make the current reading the last one and go to 1)
Got it! I think
I apologize for the confusing by using a picture of the web . The values in the picture has nothing to do with the values I feed back to the ATMEGA . These will be in the range 0-5 volts.
Even this is correct, system with this algorithm has a very "short-term" memory, only one last readings. To make it less susceptible to noise, you have to implement a "running" or "cycle" buffer, and :
take a reading -> store it in "buffer" array in place of "oldest" value;
run "find minimum" procedure with all readings in the array
Size of the array would define integration time constant.
Noise is an issue in RF environments ,I will take this into consideration when I figure how to do it .
Noise is everywhere. Just think how the system will start up, and how long your minimum value has to be in effect? Minimum should have "expiration" period, if not, system will "stick" to the some accidental value forever , or stick to zero on start up.
There is a link to arduino sketch: http://musicalnoterecognition.blogspot.com/
Probably, it's not exactly what you need, and more details on your project would be useful, but code does search for minimum and maximum in array, and new data sampled in a ring buffer.
Super- I dnloaded the sketch , I think I need a bit of time to understand.
Well it is not so much a project (yet) but rather to find a useful test algorithm , for finding a min (and or) max input voltage.
I believe there must be many projects where such a test is made. Like a Solar tracker , adjusting a solar panel for max voltage feedback from a photo sensor. In my case I have an magnetic loop antenna that tunes for resonants by a (BBQ) gear DC motor driving variable capacitor . To determine resonants I have a detector (SWR bridge) that gives a Feedback voltage . This feedback voltage is minimum at resonants and increases at both side of resonants . Dependant on case of size of RF power and frequency I feed to the antenna this minimum voltage that will indicate resonants varies.
Is there a reason not to use varicap? Varicap - Wikipedia
Ether way, you change tunning (driving a motor or change a voltage on varicap) for one "step", take a measurements and store it into array. Size of array should be equals to N step / 1 station.
For example, you can drive a motor by 100 Hz steps, so for tunning on MW station which is about 5 kHz wide band, you need at least 50 steps. The more , the better, but there is trade speed / precision. Test an array for minimum after each new readings, and if minimum 49 steps "old" you turning wheels back to this point. Want other station? Jump forward on 25 steps and start again.
Ja OK , varicap does not come in quality and voltage ratings so they can be use in such an antenna . An alternative to the good old "egg-divider"capacitor will be to use fixed Hi Q, Hi voltage ceramic capacitors. Switched on/off by relays.
In your AM radio tuning, I read it as you are using a Step-motor? I am using a DC of the commutator type. So I don't know where (position)the motor is , just I can switch power to the motor ON and OFF . I don't even want to change the direction (swoop + and -) since the motor will simply turn round and round until my detector shows the minimum feedback voltage.
I don't understand, you have to change direction, as sooner or later it would reach a upper limit. Or your cap could be rotated continuously? Anyway, you also need to know how much tunning was changed. Mechanically - encoder on motor / cap shaft, electronically - freq. meter of heterodyne.
The motor only rotates in one direction . Anyhow it is a very simple system and it has been don successful before with analog window discriminator. ( this is not looking for min. but compare within 2 defined values)
You definitely got something there about the noise, and I will look into this .