# Real World Calculus: From an Equation to a MicroController

So why bother with calculus? Well, there’s all sorts of really good reasons for knowing about calculus and using calculus. And one of
the best things about calculus is derivatives, and here’s a good example of
how to use a derivative in an everyday engineering application. We’ll take a look
at a dial right here. So a dial turns like that and it turns around its center. And
we can describe the motion of turning from one number to another as something called a “sigmoid.” A sigmoid, if we graph it, looks something like this. This is a graph of time versus angle (angle being
“theta”, in this case) If I take the motion of a
typical dial moving from one angle to another it would look something like
this. It’s what we call a sigmoid. Now, a sigmoid starts at an angle —
so this is a start right here — and it will end at an angle right there. So, start and end. And the thing is about a sigmoid that’s kind of interesting is its slowest
at the end and slowest the beginning. But right in the middle — right here — it’s really fast. So we’ve spoken about the concept of the movement of the dial as a sigmoid. Now, let’s actually write that sigmoid
function out in a program called Maple. And so what you can see is the actual
equation right here. And I will create a plot of it like this so you can see that the
plot in Maple looks similar to the hand-drawn plot and I had before. We can go even
one better than that. So if I right-click on that equation I can say “differentiate with respect to time” (or “with respect to ‘t'”). And so I’ve got the time derivative of that sigmoid function. I can also plot that. I right click on the
equation and I do a plot like this… So I’m going to colour this plot green… and I’m going to make that line a little
bit wider… like that … and do the same thing that sigmoid right here. I’m going to make that line
wider… like that. Now, what I’m going to do is superimpose one on top of
the other, so you can see both the sigmoid and it’s time derivative. So the
sigmoid is a dark red and the time derivative is in green.
And what you can see is the maximum speed or the maximum derivative is always found at the center
of that sigmoid. So now that we have this concept down let’s take a look at
what happens if we actually implement this in real electronics hardware. So now
we’re ready to implement real calculus on real hardware. What we have here is
a microprocessor, we have a dial (or “potentiometer”) right here and then some
LEDs right beside the dial. And what will happen is that there’s code inside this
microprocessor that will read the angle — for which I’m turning this dial right here —
and the faster I turn the dial or the greater the derivative of the motion of
the dial, the more LEDs will turn on. So if I go REALLY slow… one LED turned on. A
little bit faster I get two LEDs that turned on. If I go really fast, three LEDs. Reset it.
Really fast, I get four! And so the way this works, basically, is I’ve
got code written up that configures four LEDs. I have some code, as well, that measures time. And I’ve got specific code to
read the value of that dial. And then I’ve got some code in here that calculates the
difference in time from one measurement to another measurement. And I’ve got code
here that calculates the difference in angle effectively from one measurement
to another measurement. And I take those two differences — the change in time and the
change in angle — and I can create a derivative from it. From there I just
have some code that turns on a bunch of LEDs. And it’s _that_ simple. So basically whatI do is I reset it right here. I turn the dial really slowly, like that, and one or two
LEDs turns on… or really fast and four LEDs turn on. This is the actual implementation
of actual calculus, an actual derivative, on actual hardware.

### One thought on “Real World Calculus: From an Equation to a MicroController”

• April 16, 2018 at 2:00 am