God morning! As a member of the Swedish non-profit model railway association "TågCentralen" I am now taking my first step into the Arduino world, trying to make grossing gates close/open. Have just been programming PHP/HTML before.
I have read and used this excellent Several things... guide and getting the main concepts of moving a servo from one position if a signal is given (and not bouncing).
My project I am using millis to set the speed (millis between each step) and degree per step. I use som if-queries to control if the gate shall be open or closed or is moving. However I do not get the smoothness I am looking for, and the reason I did post my issue here is because maybe it is not related to programming but to hardware and other, so this is my setup:
- Arduino Nano, bought in oktober 2018.
- USB-power supply from computer (while developing)
- External power supply Mean Well LRS-50-5, grounds connected with above components.
- 1 x Servo SG90.
- Some small leds and resistors
This is the smoothness I would like: https://youtu.be/yHkUpmoC-9s?t=30
This is how it looks when I run the "Several things..." code. Link to movie on Dropbox
This is how it looks with my modified code. The modification is some if-queries and more. The timings are unchanged. No "delay()". Link to Dropbox-movie (modified code)
So my idea was that the if-queries are slowing it down? Maybe it is a obvius problem for an experienced programmer?
(If needed of course I provide the code here and change it to another forum section.)
Thanks in advance for any ideas and thoughts! :)