Red means "stop," green means "go," and yellow means "hurry up and make that damn light." Why those colors, though? Why not blue, purple, and brown? I have to admit that aside from a hunch that it had to do with wavelengths, I had no idea myself, so I decided to look into it.
The answer, as it turns out, is a little convoluted, but makes sense. The earliest traffic signals were designed for trains, not cars. They were red and green, gas-powered, and more than a little dangerous in the event of a leak.
• Red is an inherited symbol from railroads
Red symbolizes danger in many cultures, which makes sense, considering it has the longest wavelength of any color on the visible spectrum, meaning you can see it from a greater distance than other colors. Red has meant stop since long before cars existed, with train signals' use of red dating back to the days when mechanical arms lifted and lowered to indicate whether the rail ahead was clear. So that one's simple.
• Green meant "caution" at first
Green's role in lights has actually changed dramatically over time. Its wavelength is next to (and shorter than) yellow's on the visible spectrum, meaning it's still easier to see than any color other than red and yellow. Back in the early days of railway lights, green originally meant "caution," while the "all-clear" light was, well, clear or white. Trains, of course, take an interminably long time to stop, and legend has it that several disastrous collisions happened after an engineer mistook stars in the night horizon for an all-clear. Thus, green became "go," and for a long time, railways used only green and red to signal trains.
• Yellow means "caution" because it's almost as easy to see as red
From the earliest days of motoring up until the mid-1900s, not all stop signs were red --many were yellow, along with yield signs, because at night it was all but impossible to see a red stop sign in a poorly lit area. The yellow stop-sign craze began in Detroit in 1915, a city that five years later installed its first electric traffic signal, which happened to include the very first amber traffic light, at the corner of Michigan and Woodward Aves.
But what of those weird yellow stop signs, you ask? As materials and technologies evolved, the ability to produce highly reflective signs meant that red could resume its natural spot in the sign hierarchy, leaving the still-highly-visible yellow (it's second only to red in terms of visible wavelength) to the domain of "caution." That's why school zones and buses, crosswalks, and other important warnings are yellow today.