The methodology of dual weighted residuals is applied to an optimal control problem for ordinary differential equations. The differential equations are discretized by finite element methods. An a posteriori error estimate is derived and an adaptive algorithm is formulated. The algorithm is implemented in Matlab and tested on a simple model problem from vehicle dynamics