Arduino PID Control System (Ball and Beam)

  Рет қаралды 246,067

IV Projects

IV Projects

Күн бұрын

This is a ball-and-beam control system I designed and 3D printed to learn about PID control.
I've posted the CAD and code for this project on my Github page here:
github.com/IVP...
The control electronics consist of an Arduino Uno, a CNC shield, and a TMC2209 stepper motor driver. The TMC2209 motor driver allows the stepper motor to operate very quietly by interpolating step signals into 1/256 microstepping.
The distance sensor I used is an HC-SR04 ultrasonic distance sensor. This sensor typically provides rather noisy data, so I used a moving average to act as a low-pass filter and attenuate the high frequencies. I also added some simple outlier rejection to remove the occasional erroneous measurement.
I used a 12-bit AS5600 absolute magnetic encoder on the stepper motor to track the position of the motor. These sensors operate on the Hall effect and use I2C protocol to communicate with microcontrollers. I designed and printed a housing that attaches to the back of a NEMA-17 stepper motor and holds the encoder board in the correct location relative to the magnet. The encoder magnet is diametrically magnetized and is attached to the back of the motor shaft.
I originally planned to use a ping pong ball as the rolling element of the system, but the distance sensor was not able to reliably provide clean data. I think the reflected sound from the sphere was too small in this case. That's why I made the cart with a large acoustically reflective surface.
To set the PID target position, I mapped the output of a 10k potentiometer to the position along the beam.

Пікірлер: 121
@matt55346
@matt55346 Жыл бұрын
A beautifully simple and effective demonstration of PID control, my congratulations from Italy
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thank you!
@47lokeshkumar74
@47lokeshkumar74 Жыл бұрын
@matteo ur email
@robvanscheijndel
@robvanscheijndel Жыл бұрын
I wish that my teacher had something like this to explain the working of PID controls. We have used just a book (which was by the way a great one), seeing the system in real life is much more interesting. Great work, maybe I will build one for myself.
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks! It is a nice way to visualize PID control.
@zuzukouzina-original
@zuzukouzina-original Жыл бұрын
Exactly, our teachers also didn’t show a working example to support the theory. After 25 years I’m thinking of building a working demo with arduino too. I already have all the things needed 😁
@RNGHatesM3
@RNGHatesM3 7 ай бұрын
This is nicely designed, I was thinking of doing something similar. One significant modification I was thinking about was replacing the ultrasonic sensor with something more reliable. What if instead of the wooden rails, you used metal rods instead, with a metal ball. Then measure the resistance across the rails. As long as the rails are electrically isolated (and it would appear they would be in your model), the ball would act as a potentiometer. Greater resistance = greater distance. It'd be interesting to see how that would work. It would also remove your friction issues.
@ivprojects8143
@ivprojects8143 7 ай бұрын
That would be neat! I bet it would be possible, but I wonder if it would be hard to get good data (I wonder if it would be super sensitive to things like the cleanliness of the rails). Cool idea for sure.
@tahirkamboh147
@tahirkamboh147 Жыл бұрын
That's amazing to watch it, but we missed the sweet voice over!
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks! I didn't have much time to put this video together, so I that's why there's no voice over.
@georgekerwood9100
@georgekerwood9100 Жыл бұрын
Nice project, good work. Hope you enjoyed it continue to do more!
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thank you! I'll try to post every now and then.
@scottrasmus5611
@scottrasmus5611 Жыл бұрын
inject a sine wave instead of the pot. Awesome work.
@williamogilvie6909
@williamogilvie6909 Жыл бұрын
I see a lot of these on Utube now. There must be an open source project somewhere because they all look the same. This isn't a difficult PID control project. It is just first order so has little chance of becoming unstable, no matter what you do. A more interesting PID demo I have seen is balancing a vertical pole, with the error signal coming from an angle sensor at the base.
@vineshgda
@vineshgda Жыл бұрын
Amazing work. It will be awesome to have a wave machine on wheels on this
@marializianichols648
@marializianichols648 Жыл бұрын
Congratulations Great project.thank you for sharing so amazing PID controller
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks! Glad you like it.
@HenriqueFerrolho
@HenriqueFerrolho 6 ай бұрын
Hi, @ivprojects8143! Why did you need an encoder for this project? Was the stepper motor skipping steps and so you needed the AS5600 to compensate for that? Thanks in advance!
@ivprojects8143
@ivprojects8143 6 ай бұрын
Hi! I added the encoder to let me graph the angular position and also in case I wanted to switch to closed loop control for the motor (like you mentioned). I ended up just using open loop control though. So you could omit the encoder if desired.
@kurtdobson
@kurtdobson Жыл бұрын
Could be used as a controller for hydrofoil wing. Looks like ultrasound distance is the 'set point' for the PID.
@ivprojects8143
@ivprojects8143 Жыл бұрын
PID control is used for lots of things. The ultrasonic sensor data is the input to the PID loop. The target position is defined by the potentiometer position.
@pabloperez9268
@pabloperez9268 Жыл бұрын
Love to see your trasfer function
@elektroschrott-arduino
@elektroschrott-arduino Жыл бұрын
Sehr schönes Projekt!
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thank you!
@charlessun8321
@charlessun8321 Жыл бұрын
Do you have this project documented somewhere for other people to replicate and learn? Open source? This is a good learning project for PID control.
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks! I have posted all the CAD and code related to the project on my Github.
@yisusdeastora4692
@yisusdeastora4692 Жыл бұрын
Congrats it is a great video, just a question, can i use another magnetic encoder?
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks! Yes, you should be able to. You'll just likely have to make some changes to the code.
@Singh_Malkiat
@Singh_Malkiat Жыл бұрын
I tried to build this project but didn't find a circuit diagram and used library. Specially HC_SR04 creates problems.
@TheRealStructurer
@TheRealStructurer Жыл бұрын
Cool and smooth 👍🏼 Built as a demo or is there a future use for it?
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks! It's just intended as a demo, but there are lots of analogous uses for PID control in real systems.
@papanyanz
@papanyanz Жыл бұрын
Impressive! Can you tell which pid equation is implemented here, since there are quite a few of them for some reason like parallel form, etc. Do Ki and Kd terms have time related physical meaning in your code or are "just numbers" correctly chosen? Would like to see some educational material from you, thank you!
@JimMaz
@JimMaz Жыл бұрын
He's using an Arduino library for the controller itself (PID_v1.h). He then tunes it by scaling the values.
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks! And @JimMaz is correct. I posted the code on my Github if you'd like to take a look.
@MatterLabz
@MatterLabz Жыл бұрын
@@ivprojects8143 I'm thrilled to hear that. I'd love to build this as a platform to learn about tuning PID values. Thanks for sharing!
@Rich171090
@Rich171090 Жыл бұрын
Awesome work. How long would you say you spent tuning this?
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks! It took me quite a while, but I think if you're experienced you could tune a system like this rather quickly.
@Rich171090
@Rich171090 Жыл бұрын
I've thought about doing something like this for a while, the quality of your finish is great. Not janky at all. But I've always wondered how long I would spend tuning it. I've done PID before but with chemical process control
@DerClaudius
@DerClaudius Жыл бұрын
Nice project, PID constants are not tuned optimally though - it oscillates around the target
@ivprojects8143
@ivprojects8143 Жыл бұрын
The friction in the cart makes the system require higher gains to work properly. It would still be possible to reduce the oscillations, but it would probably require a more sophisticated controller.
@gabedarrett1301
@gabedarrett1301 Жыл бұрын
That's pretty cool! Are you an engineering student by chance?
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks! And yes, I am an engineering student. I chose this project because it involves quite a few of the concepts from my classes last semester.
@gabedarrett1301
@gabedarrett1301 Жыл бұрын
@@ivprojects8143 Could you please post the code? That control loop is impressive, especially with the silent stepper motor driver!
@ivprojects8143
@ivprojects8143 Жыл бұрын
@@gabedarrett1301 Sure thing! I just uploaded the code and all the CAD files to my Github.
@gabedarrett1301
@gabedarrett1301 Жыл бұрын
@@ivprojects8143 Much appreciated!
@dmawzx
@dmawzx Жыл бұрын
Здорово! Спасибо!
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thank you!
@gloomyday3
@gloomyday3 2 ай бұрын
Which part of the motor drive should I connect HC-SR04 to? I'm also curious about the details of the changing PID target position of with potentiometer knob
@abdulwhabibrahim9177
@abdulwhabibrahim9177 Жыл бұрын
good job 👍🏽, but may you show me how is the connection of the electrical components with the microcontroller ?
@jorgeezequiellopez6403
@jorgeezequiellopez6403 Жыл бұрын
Excelente! ¿cual es la biblioteca del HC_SR04?
@JimMaz
@JimMaz Жыл бұрын
Very cool. Thanks!
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thank you!
@shiiimo2167
@shiiimo2167 10 ай бұрын
I'm wondering how the 3D models work for the cart, I can't seem to see how the the axels fit inside the cart chasis, thank you!!!
@mehemmedelizade7983
@mehemmedelizade7983 Жыл бұрын
Your project is beautiful. Can you post the wiring diagram of the circuit?
@Disks3
@Disks3 2 ай бұрын
How did you supply voltage to the cnc shield?
@FranciscoMejia-z9t
@FranciscoMejia-z9t Жыл бұрын
excellent project, can you share the electronic schematics?
@skunkprints7952
@skunkprints7952 Жыл бұрын
Well I think you need to get a second one and use the data to create a gyroscope of sorts. 2 axis and you could build a table that balances on a ball if you use the inputs of the “Sensors” you make. Idk just a KZbin idea
@luismanuelsantamarianegron2205
@luismanuelsantamarianegron2205 Жыл бұрын
Hola donde puedo ver las medidas que utilizaste para la construcción del proyecto bola biga
@Irfan-vo6fh
@Irfan-vo6fh Жыл бұрын
Which software can i use for designing this controllers and which KZbin channel can help me for learning this practical approach???
@Ekstrapolator
@Ekstrapolator Жыл бұрын
This ultrasonic distance sensor are pretty slow from what I remember on such short distance IR sensor would be better i think 🤔
@47lokeshkumar74
@47lokeshkumar74 Жыл бұрын
Simple cute brilliant
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks!
@47lokeshkumar74
@47lokeshkumar74 Жыл бұрын
Can i buy these thing ..
@Disks3
@Disks3 2 ай бұрын
Are there separate libraries for hc-sr04 and as5600??
@SpencerHyams
@SpencerHyams Жыл бұрын
Do you have 12v DC power supply to the shield?
@ivprojects8143
@ivprojects8143 Жыл бұрын
I think I used a 19v laptop charger as the power supply, but you can use any voltage that the CNC shield/drivers accept.
@luiz4074
@luiz4074 Жыл бұрын
How do you modeling this? Does you have the datas of experiments?
@Disks3
@Disks3 2 ай бұрын
Can I see the circuit diagram? I really want to try making it.
@alperenk7560
@alperenk7560 6 ай бұрын
Hi could you share the dynamic equations of this system with me?
@NutsandGuts
@NutsandGuts Жыл бұрын
Cool demonstration but isn't it overcompensating?
@NutsandGuts
@NutsandGuts Жыл бұрын
Underdamped in PID terms
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks! Yes, it's currently an underdamped system. I wasn't able to get it to work well with critical damping because of the hysteresis due to the friction between the cart and the track.
@nguyenhainam7594
@nguyenhainam7594 5 ай бұрын
Would you mind if I could refer you to the circuit diagram of this project?
@IdeasInfinityTV
@IdeasInfinityTV 8 ай бұрын
@IV Projects I am building this project but i have stepper motor without encoder can we use l298N driver and still do this project ? ihave 3d print all the parts from your repository .
@adelajasamuel1
@adelajasamuel1 8 ай бұрын
Sorry how did you get the parts from his repo? I can't find my way around it. I want to make some tweaks
@AbhishekKumar-jp9eg
@AbhishekKumar-jp9eg Жыл бұрын
Pid stand for proportional integral derivative
@subramanyamysore
@subramanyamysore Жыл бұрын
Hi, first of all, awesome!!! Can we work together on using your setup to implement auto pilot system in a personal airplane?
@burkejohnson4539
@burkejohnson4539 11 ай бұрын
jesus christ lol
@renanmonteirobarbosa8129
@renanmonteirobarbosa8129 Жыл бұрын
Why PID if LQR is far easier and more effective to implement?
@ivprojects8143
@ivprojects8143 Жыл бұрын
I wanted to learn about PID control because of its prevalence in industry. Now that I have the hardware I can always change the code to try different control methods.
@renanmonteirobarbosa8129
@renanmonteirobarbosa8129 Жыл бұрын
@@ivprojects8143 Did you create the state space ? you gonna see the same solver pipeline for PID can be used for LQR. Your project is relly cool.
@WRLD-FPV
@WRLD-FPV Жыл бұрын
Your a wizard
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks Kyle!
@DanielHernandez-lv6rj
@DanielHernandez-lv6rj Жыл бұрын
what is the length of the wooden bars?
@Phonex633
@Phonex633 22 күн бұрын
In the files doesn't STL files are some missing
@ChemEDan
@ChemEDan Жыл бұрын
This needs to become a borzoi meme
@karanparve1734
@karanparve1734 Жыл бұрын
Great 😍
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks!
@relampago0358
@relampago0358 Жыл бұрын
Hola podrías pasar el esquematico para poder armarlo porfa
@mantaklee3523
@mantaklee3523 4 ай бұрын
The ultrasonic sensor is not smooth, Laser distance sensor is better than this one I think.
@ivprojects8143
@ivprojects8143 3 ай бұрын
Yes I had to a lot of data processing to get it working properly. I didn't have a laser distance sensor on hand that would work for this range of distances.
@devdev-cs3tq
@devdev-cs3tq Жыл бұрын
hi can I have the code source ? with CAD please
@ivprojects8143
@ivprojects8143 Жыл бұрын
The CAD and code are posted on my Github page.
@Disks3
@Disks3 2 ай бұрын
Can I see the schematic?
@МаксимБалахонов-к7ж
@МаксимБалахонов-к7ж Жыл бұрын
На температуру подходит алгоритм ?
@ivprojects8143
@ivprojects8143 Жыл бұрын
Yes, PID control is often used for temperature control.
@wisnual-rasyid984
@wisnual-rasyid984 Жыл бұрын
what is PID ?
@castlebravo1599
@castlebravo1599 Жыл бұрын
PID simply put is a type of controller that uses 3 pieces of information about a value to control a system(aka whatever it is you want to manage). These pieces of information are: P: p stands for "proportional" and it is simply the error, or difference between the value you have and the value you want. I: I stands for "integral" or the sum of the error over time that has accumulated which is aquired through integrating of the error value D: D stands for the differential of the error, or in more plain terms it is the rate of change of the error, so how fast you are moving towards or away from the value you want. once you have these values you multiply them by a constant and add them linearly to get your controller output. you can choose the constants and in doing so you make a controller that should in theory give you no steady state error (so it will reach the value you want exactly if you give it enough time) it should rapidly move towards that desired position you want and then manage the speed when it is getting close to get the final property, namely no overshoot. The system will not jump over the desired value and then have to return. there is(obviously) more to this then i can put in a yt comment but this should give you a general idea. tldr: it is a controller that looks at the error, the rate of change of the error and the sum of the error to determine what commands it needs to give. hope this helps :)
@eddyeisenberg5740
@eddyeisenberg5740 Жыл бұрын
Awesome man! So cool! Glad to see your still at it! Hmu on discord sometime and well get together!
@eddyeisenberg5740
@eddyeisenberg5740 Жыл бұрын
Also: those TMC2209s are certainly a game changer. Definitely worth it on the ender 3. Makes it so quiet.
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks Eddy! Sent you a message.
@ParsMaker
@ParsMaker Жыл бұрын
nice toy
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thanks
@TuyenNguyen-ug3wv
@TuyenNguyen-ug3wv Жыл бұрын
Rất ấn tượng
@ivprojects8143
@ivprojects8143 Жыл бұрын
Thank you!
@wagyourtai1
@wagyourtai1 Жыл бұрын
Just a bit overdampened, critically dampened systems is where its at
@raulcastro6768
@raulcastro6768 8 ай бұрын
Stl ?
@utkudenizaltiok860
@utkudenizaltiok860 Жыл бұрын
Where is code ?
@ivprojects8143
@ivprojects8143 Жыл бұрын
It's on my Github page.
@utkudenizaltiok860
@utkudenizaltiok860 Жыл бұрын
@@ivprojects8143 whete is yout github link
@ivprojects8143
@ivprojects8143 Жыл бұрын
@@utkudenizaltiok860 Check the video description.
@Chinafilm001
@Chinafilm001 3 ай бұрын
schematic pls brother
@philipdrew7518
@philipdrew7518 Жыл бұрын
You realise you spent time on this. Like part of your life building this thing
@ivprojects8143
@ivprojects8143 Жыл бұрын
Yes, I do realize that :)
@philipdrew7518
@philipdrew7518 Жыл бұрын
@@ivprojects8143 My point is for people and yourself to realise the uselessness of your device. I know your a decent person, probably bored. What about a launch rail for a hypersonic aircraft? Could you prepare designs for that and put it on yt?
@CarlosPerez-wf9gv
@CarlosPerez-wf9gv Жыл бұрын
Mmm... I smell Matlab from here
@macaion897
@macaion897 10 ай бұрын
アヒルに見える
@johnrom8787
@johnrom8787 Жыл бұрын
Ардубина
@JesusCarrilification
@JesusCarrilification Жыл бұрын
Please detail your build a little better. Don't know how to build it
@3DSpaceX
@3DSpaceX Жыл бұрын
Есть ли скетч програми ?
@ivprojects8143
@ivprojects8143 Жыл бұрын
Yes, the code is posted on my Github page.
DIY Arduino Ball and Beam : PID control
6:19
Homemade Engineering
Рет қаралды 68 М.
What is a PID Controller? | DigiKey
22:19
DigiKey
Рет қаралды 96 М.
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 6 МЛН
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 36 МЛН
This Should Be Impossible...
23:05
Alec Steele
Рет қаралды 927 М.
3D printed robot arm base with stepper motors
3:45
Stuff Gets Made
Рет қаралды 3 М.
20 Mechanical Principles combined in a Useless Lego Machine
7:21
Brick Experiment Channel
Рет қаралды 44 МЛН
Much bigger simulation, AIs learn Phalanx
29:13
Pezzza's Work
Рет қаралды 2,8 МЛН
Уроки Ардуино. ПИД регулятор
28:57
Заметки Ардуинщика
Рет қаралды 479 М.
Getting Started with Meshtastic - Devices
15:01
The Comms Channel
Рет қаралды 227 М.
Прошивка Bruce для StickC Plus2 !
11:19
Hobby Support
Рет қаралды 13 М.
PID Balance+Ball | full explanation & tuning
13:13
Electronoobs
Рет қаралды 762 М.
PIDs Simplified
13:07
SiieeFPV
Рет қаралды 306 М.
Глюк на моем iPhone 16 Pro Max
0:26
ТЕХНОБЛОГ ГУБАРЕВ СЕРГЕЙ
Рет қаралды 1,4 МЛН
Наклейка SSD 💽
0:24
serg1us
Рет қаралды 565 М.
Как подключить магнитолу?
0:51
KS Customs
Рет қаралды 2,3 МЛН