We present an optimal control problem for traffic regulation via variable speed limit. Using the well---established Lighthill---Whitham---Richards model with Newell--- Daganzo flux, we aim at minimizing the quadratic error to a desired outflow for a given inflow on a single road in free flow condition. After providing existence results for the optimal control problem, we compute analytically and numerically the gradient and solve the optimal control problem. Moreover, we design an instantaneous policy, depending only on the density at the exit point, and compare numerically with other policies. (Joint work with Benedetto Piccoli and Francesco Rossi)