Abstract In molecular dynamics simulations the temperature or pressure can be controlled by applying a weak first-order coupling to a bath of constant temperature or pressure. This weak coupling technique to control system properties using a first-order relaxation equation is analyzed from a statistical mechanics point of view. It is shown, how the weak coupling scheme can be generalized and applied to a bath of contstant chemical potential. The presented method, to which in the following will be referred to as chemical potential weak coupling, is applied and tested on a Lennard-Jones fluid. The thermodynamic quantities known from the literature are accuratly reproduced. The temperature and chemical potential weak coupling methods aim to sample the canonical and grand canonical ensembles respectively. By analyzing the fluctuations in energy and number of particles, the tight relation between the ensembles and the distributions obtained from the weak coupling simulations is demonstrated. The influence of t...