Those lights are used to show obstacles that may interfere with the aircraft's course, such as antennas, buildings, wind turbines, and they are mandatory. The name of those lights is Aircraft Warning Lights, and here is an article from Wikipedia about them.
Yes, the lighting is helpful for collision avoidance.
The red lights are helpful, but the white strobes can be even better for visibility.
When I am flying very low to the ground I am far more concerned about towers and windmills (or occasionally high tension power lines) than buildings. Fortunately all of my really low flying for work is done during daylight hours, but in heavy overcast or other low-light conditions the lights are very helpful.
Most tall buildings are in congested areas and most flight operations will be required to maintain an altitude of 1000 feet or more above such structures. The presence of towers in excess of 500 feet, and especially in excess of 1000 feet, in uncongested areas posses a much more credible threat to VFR low level flight.
The FAA describes the standards for structure and tower lighting in AC70/7460-1L. Generally, any structure that exceeds 200 ft AGL should be marked and/or lighted.
Note that, though the lighting may be mandatory, it may be NOTAMed out of service. For example:
!SFF 02/009 SFF OBST TOWER LGT (ASR 1060807) 473535.00N1171750.00W (5.5NM S SFF) 3971.1FT (352.4FT AGL) OUT OF SERVICE
Before the lights were installed, this happened...
(second picture via Pinterest)
A better picture of this incident (a 1915 Sopwith Baby at Horsea Island in 1917) appears in the front of the 1925 edition of the "Admiralty Handbook of Wireless Telegraphy" in a slightly snarky advert, captioned "A proof of the quality of Elwell masts".
To answer your question directly, no, they are not used to indicate that you are too close to the ground. Some of them are over 1500 feet high.
They are used so you do not fly into them for obvious reasons or fly too close to them for less obvious reasons:
- Some are powerful transmitters and can interfere with the systems on the aircraft.
- Towers often have support wires which extend a long way from the obstacle with the light and do not have lights themselves.
Too close to the ground is figured out by looking; by the altimeter; by charts and by planning.
The red light just means "keep away!"
Whilst this paper focusses primarily on the ability of high powered EMR sources to cause ignition sparks up to 30kms away (!), it also shows how dangerous they are up to hundreds of metres away.
If anyone remains unconvinced that powerful transmitters need to be avoided by aircraft, please let me know and I'll do some more digging, but for now, I have an "all nighter" I need to pull to deliver a project tomorrow so I may be some time....