Closed Loop unity feedback control for motor on Arduino

Hi, I'm trying to figure out how to make the logic in the attachment a closed loop unity feedback system.

This lab controls the speed of a dc motor using speed feedback from a tachometer. We will observe this feedback effect when controlling the speed of a dc motor.

In a feedback system the actual speed (feedback)) is compared with the commanded speed and the difference is used as input to the motor amplifier thus trying to maintain the commanded speed.

The pot on the circuit board sets the commanded speed and it is connected to the ADC input of the Arduino (A0).
The photointerruptor is used to create a tachometer.
The PWM output from the Arduino adjusts the motor voltage.

Right now, it is setup as a open loop feedback system and I want to make it a closed loop feedback system and that is where I am getting stuck

lab 5 diagram.PNG


ent418_lab_8.ino (1.31 KB)

lab 5 diagram.PNG


More members will see your code if posted properly. Read the how to use this forum-please read sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

What does the code actually do? How is that different from what you want the code to do?

A schematic of the system would probably help.

Isn't "open-loop feedback" a contradiction in terms? If there's feedback, then there's a closed loop.