[[Template core/front/global/updateWarning is throwing an error. This theme may be out of date. Run the support tool in the AdminCP to restore the default theme.]]
To prevent this problem ever occur again, all you have to do is purchase a cheapy memory card and stick it in there. Then if you lose power or battery, the controller will load the program from the memory card. Buy it on ebay! cheap memory card...
Why don't you use simple devices such as Dayton (or others) that already has PID loop and integrate it into your design. Using PLC PID can be very headache.
Use Turck or Keyence color sensor. These sensor can be trained (programmable by dip switches) to detect up to 7 colors of your choice. Outputs will indicate correct color under inspecting. Simple, cheap and robust.