Hi, i am an arduino beginner and have no coding experience. I am making a seismograph for a school project by putting a moveable magnet in a coil that will give voltage when te magnet vibrates. I am using the arduino uno r3. To live plot the voltage i am using the following code:
not sure you need the derivative, but the derivative is simple the change between the last 2 values. so keep track of the last value (e.g. vLst) and report the difference, v - vLst)
gcjr:
not sure you need the derivative, but the derivative is simple the change between the last 2 values. so keep track of the last value (e.g. vLst) and report the difference, v - vLst)
Thank you for your answer! I need the derivative to get the "induction voltage" (not sure if i translated that right). How do i keep track of the previous voltage value?
gcjr:
not sure you need the derivative, but the derivative is simple the change between the last 2 values. so keep track of the last value (e.g. vLst) and report the difference, v - vLst)
The derivative is the rate of change of one variable with respect to another. Presumably, OP wants rate of change of voltage with respect to time. That can be approximated as delta(v) / delta(t).
So, you'd take the difference between two voltage readings and divide it by the time difference between when those readings were taken. The millis or micro functions can be used to provide the timestamps.
Watch out for the derivative with sampled data. It is not at all the same as the mathematical function which approaches a value to a limit. The math derivative applies to an infinitely small region of the x number line, and only for well defined functions. That means, for example, the difference between the last and present value might consist more of input noise, than the actual derivative.
There is also a problem with resolution, as the difference between last and current values, is usually much smaller than the maximum or nominal input value range. So the quantization that happens in your A/D conversion, is greatly amplified, thus producing very "chunky" output.
The way you "keep track" of something in C++ is to assign the value to a variable.
vLst needs to be persistent between calls to loop() so that its' value is available the next time loop() executes.. either declared as a global outside of loop() or as "static float" inside loop()
gcjr:
vLst needs to be persistent between calls to loop() so that its' value is available the next time loop() executes.. either declared as a global outside of loop() or as "static float" inside loop()
Hi, thank you in advance for bearing with a beginner to this. I changed "float vLst = v2" to "static float vLst = v2" This gave me a voltage output but not the derivative. My coding knowledge is not very big so apologies for these constant questions.
aarg:
How do you know it's not the derivative? What are you expecting? What did you get?
I currently have no coil to test with so i am using two batteries paralell to test. When the voltage is constant like on a battery the derivative should be 0. The plot displayed a constant voltage of 1.36v. I do not know where to find my v /v 2/ v3 / vLst results
TheMemberFormerlyKnownAsAWOL:
Why do you post 11kB of picture, when you could post a few hundred bytes of text?
I blame the dumb serial monitor. It's hard to do a cut and paste while it's receiving. I often write in a "stop" if I know I'll want to capture the displayed data.