Hi
i am making an active aerodynamics model using potentiometer and servo motor
i am new to using arduino, so can i get the arduino code so that the servo motor gives different rotation for different potentiometer position
for example: the servo motor should rotate 15 degrees for 25% rotation of the potentiometer knob and 30 degrees for 50% rotation of potentiometer. And should stay at 30 degrees until full rotation of potentiometer. While bringing back the potentiometer to initial position the servo motor should increase to 60 degrees (air brakes).
You can find sample code for controlling a servo and for reading a potentiometer by conducting an internet search, or even in the built-in Arduino IDE examples.
You will have to write the code to scale the potentiometer values, and use them to control the servo according to the outlined plan. The map() and constrain() functions might come in handy and are described in the Arduino reference pages on line.
Your description leaves out many details.
Is there another way you could say what you are aiming for, like something graphical?
Missing, for example, is what woukd ever make the servo go back to where it began so the sequence could be repeated.
Here's what I make of what you've said so far:
Increase to 15, and to 30 as we twist up from 0 to 50. Hold at 30 until we've twisted all the way to 100. As we turn the pot the other way, increase to 60.
So many questions. What happens if we never reach 100 on the lot, but start going back? If we do reach 100, how fast is the increase to 69 as we untwist? What happens when the servo reaches 60, which is where your story so far ends.
All questions will be answered. It is better to ask and answer them now during the design, because the code will do something in any case, and unplanned or unanticipated results will almost never be what you wanted.
a7
hello alto777
thank you for the reply!
so i want the servo to have 60 degrees of rotation as we untwist, doesnt matter from where i am untwisting and i want the servo to turn off when i untwist after -75% i.e to have 0 degrees of rotation
hope that clarifies the problem ![]()
A little. Did you see the arrows in my diagram? It shows the path as you twist.
Draw a fine diagram showing the path as you twist.
This is similar to the curve drawn for hysteresis. Look at a hysteresis diagram to see how it encapsulates the changing input parameter relationship to the output.
I'd make a stab given you additional and fine diagram, but I am in transit. And it woukd sadly be another guess.
What happens if the twist doesn't reach 100? You might want to use some target that keave a bit if headroom (95) also, hard to know yet.
a7
umm does this help..?
even if it doesnt reach 100, when i untwist it should give a rotation of 60 degrees and disengage when i untwist below -75
No. I did not know your pot could go to -100, is that what you mean? And the arrows on the path going to the right, where does it go after that?
Did you look at a hysteresis diagram? google/wikipedia are your friends. Basic engineering concept.
Someone published a demo, this is for a heating system. The slide fader is room temperature, see how the path involves turning on and off the heat depending on the set points.
You have a similar problem - there has to be history maintained as you have two servo values for any given pot position, depends on how you got to that setting.
I'll try to make sense of your diagram. I am in transit, so.
a7
by -100 i mean that the pot. is completely untwisted
and in the right, it stops at 100,(my bad) i.e it is completely twisted
and take your time ...and thank you
Normally with a pot you would have a linear relation between analog value and action. I think you are saying that want a different profile when turning CCW vs CW.
Lets call them Mode A and Mode B. So how will the code determine when to switch from Mode A to Mode B? Bear in mind that the analog value will vary due to noise, depending on the quality of the pot.
I would suggest it will be a lot easier if you have a switch to select between Mode A and Mode B.
This is what hysteresis does, it is what it is for.
It automatically switches modes. Play with the demo, or just recall how your gnome heating thermostat works.
@wireybus draw the path the control value takes on as you twist and untwist the pot.
Use hysteresis, or otherwise spell,out exactly what happens if your twisting does not reach 100.
For example, if I twist fro 0 to 30, but then twist back, I assume th servo goes back down. But if I twist alla way past 95, the lath in the way down takes on different values, until…
well, until when?
Again, look at the demo or read about it in the context of magnetism. Parts of the lath have arrows goin both ways, pointe on the path will be where @bobcousins's mode changes will happen, not on a switch but by logic.
Hysteresis does not need to be limited to on/off; my opinion sitting here in the transport cafe is that it can be wrangled into service for your goal.
a7
@wireybus here's what further thinking leads me to.
Whilst moving between 2 and 98 (arbitrary but not just 100 and 0, a range instead), you are on the bottom path with ability to go back and froth all day long.
Should you exceed 98, the system snaps to the upper path, where again you can go bakc and forth all day long, unless you go below 25, where we snap to a third path, and… go back and forth all day long until you go below 2.
I don't expect this to be correct; I do expect you to express your goal in this same graphic style with the same kind of words 'splaining it.
Note the red one way portions.
Say what happens on the way down after we take the first snap but then dial up the input. Is there another point where anything shoukd snap?
a7
Good. Use what you get from that video and draw a diagram like mine. I cannot. Or will not, take your pick.
Or don't. Just go ahead and code that, using the idea that there seem to be modes amongst which your control system must change according to the history, as the demo does with switching from
heating mode until it is warm enough to stop heating
to
cooling off mode until it is so cold to start heating
What neither you nor the video make entirely clear is where there are, or are not, one-way arrows where modes should change.
A diagram would be unambiguous; without one it is not sane to code. Anything.
a7
i think the diagram which you gave does kinda satisfy my criteria
i can check the same if you can come up with a code using your diagram and i shall upload it to my arduino and if it does satisfy then we have our code if not we can try other methods
again thank you so much for your time.
Is there something unclear about my diagram?
Let's try to make the diagram satisfactory, not just "kinda".
If I had the little demo device in the video, I could play with it, and draw a complete and correct diagram. it might take a minute, but it would not be ambiguous. Since an operational example of the device can be graphed, one could start with the graph and wi]rite the code.
If you haven't made a good diagram by the time I get to the lab, I will try to post another diagram showing where all the unanswered questions are.
I say again in case it isn't clear - the diagram works because it has sections where you can travel,both directions, and trigger points that only go one direction from the current path (mode) to another.
My diagram has three modes. Start with asking yourself how many modes all activity on the spoiler can be divided into.
There is accelerating, and there is slowing down after having surpassed 100, again I think if the pot max is 100, that trigger should allow a bit of headroom, same same at the low end.
And there is the odd change when you are untwisting (slowing down), where the spoiler goes down to 30…
In my diagram, if at that point you speed up again, nothing ever makes the mode change from that odd third bidirectional section.
Which seems obvsly wrong.
Did you play with the hysteresis demo and read the code to see how it functions? This will be how you will have to write the control code if you stay in my advice.
Which I certainly admit is not the only way to go, nor can I claim the best. It's just how I would do it, and I'm not that creative, so I think my ideas are informed by the kinds of things I've read and studied.
a7
I think I would try doing it as a state machine. Here is a simplified version, I haven't included all the possible transitions. I split it into 4 acceleration phases, and 2 decel phase, but of course there could be more or less.
In a real situation, I guess the state machine would look at throttle and brake pedals as well as just speed to determine the behaviour.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.



