How light is made from the ordered motion of electrons in atoms and molecules

Atoms like to emit and absorb photons of particular frequencies. Which frequencies are favored depends on the kind of atom.

An atom consists of a heavy nucleus surrounded by light electrons.

A hydrogen atom has one electron. A helium atom has a heavier nucleus and two electrons. A lithium atom has a still heavier nucleus and three electrons. ... An oxygen atom has eight electrons. ...

A molecule consists of two or more atoms joined together.

Roughly speaking, one can think of the electrons as being in orbits in an atom or molecule. But only certain orbits are allowed. For this reason, the atom can have only certain energies. (Energies of atoms are usually measured in electron volts, abbreviated eV.) The allowed energies can be illustrated with a diagram:
The example shown is for hydrogen, but each kind of atom or molecule has its own energy level structure.

This picture shows the four lowest energy levels. There are more.

Energies above the blue line (~ 13.6 eV) are possible too. That corresponds to removing the electron from the hydrogen atom (ionizing the atom, making it an ion). The energies for an electron that isn't attached to the atom can be anything. Thus any energy above the ionization energy is allowed. For the moment we neglect this to keep the discussion simple.

An atom in one of its "excited" levels can get to a lower level by emitting a photon.

The energy is carried away by the photon. Thus the energy of the photon is the difference

energy of emitted photon = (atom energy before) - (atom energy after)

In this case, the energy of 1.88 eV corresponds to a wavelength of 653 nm. (This particular kind of light is red and is called H-alpha light.) One can get a different view of the Sun by photographing it in H-alpha light.

An atom in its ground state or in one of its excited states can absorb a passing photon of the right energy and be raised to a higher energy state:

Note that the passing photon has to be just the right color or it can't be absorbed.

energy of absorbed photon = (atom energy after) - (atom energy before)

We can use a simpler picture with arrows to illustrate these processes:

If you look at a dense gas, the photons you see have bounced around so much that you see radiation at a continuous range of wavelengths, often close to a blackbody spectrum.

But if you look at a thin, transparent gas, then you can see photons that come to you directly from an emitting atom.

Davison E. Soper, Institute of Theoretical Science, University of Oregon, Eugene OR 97403 USA