  The bacterium {\em Bacilus subtilis} frequently forms biofilms at the
interface between the culture medium and the air. We develop a mathematical
model that couples a description of bacteria as individual discrete objects to
the standard advection-diffusion equations for the environment. The model takes
into account two different bacterial phenotypes. In the motile state, bacteria
swim and perform a run-and-tumble motion that is biased toward regions of high
oxygen concentration (aerotaxis). In the matrix-producer state they excrete
extracellular polymers, which allows them to connect to other bacteria and to
form a biofilm. Bacteria are also advected by the fluid, and can trigger
bioconvection. Numerical simulations of the model reproduce all the stages of
biofilm formation observed in laboratory experiments. Finally, we study the
influence of various model parameters on the dynamics and morphology of
biofilms.
