During the last block of the second year we had the subject Measure, Regulate & Control. This subject was about capacitance, coils, system equations, motors, Fourier Transforms and that kind of stuff. Nothing I haven’t learned during the projects listed on this website. However, luckily we also discussed PID-Loops; I think they are awesome so I decided to put them to use!
The code used to accomplish this can, as always, be found on GitHub; it was very fun to write, test and verify this program with the used hardware. The diagram of the on GitHub visible code is shown underneath.

First of all, the hardware had to be wired up. To make this a little easier, I created a wiring diagram. As can be seen, I used a LM2596 as Step-Down Converter, a Pro Micro as Microcontroller and a Sharp Distance Sensor, as the name suggests, as distance sensor. The capacitors are used to ensure all devices are able to funciton properly.

Since a video tells more than a thousand words, I recorded the underneath embedded video
Challenges
As any other project, there always are problems that weren’t anticipated beforehand. One of these problems was the location of the Servo…

The location of the servo created a very large lever, thus requiring a pretty large amount of force to move the beam. It can draw up to 2.5A at a still depending on the expressed force; that’s the reason a 12V DC Power Supply is used to deliver the proper amount of power.
However, after a minute of 30 the Servo started stuttering. This is most likely due to the internals wearing out; this happened once already. So next time, I’ll definitely try to look more into the lever-law.

Another problem was the Sharp Distance sensor; the Infrared Signals reflected on the sides of the PVC tube thus resulting in noise. This has been solved with a 50-taps mean filter. However, this results in a slower reaction. It would be better if another sensor could be used.