Why do trains blow their horns? What is the point?

Ok, I know they aren't "horns", but whatever they are called...
I live near a train track and every time they pass by my house, they blow their horn...sometimes even at 2 in the morning! Why is this? Do they HAVE to or do they just do it because they're bored?
37 answers 37