What's an atheist scientist like me doing writing good things about religion? I didn't start out this way. As a teenager, I had contempt for religion. I was raised Jewish, but when I read the Bible, I was shocked. It hardly seemed to me like a good guide for ethical behavior in modern times, what with all the smiting and stoning and genocide, some of it ordered by God. In college, I read other holy books, and they didn't make me any more positive toward religion.

In my 20s, I obtained a Ph.D. in social psychology and began to study morality. I ignored religion in my studies. We don't need religion to be ethical, I thought. And yet, in almost every human society, religion has been intimately tied to ethics. Was that just a coincidence?

Watch Jonathan Haidt's TED Talk

In my 30s, I began to study the emotion of "moral elevation." That's the warm, fuzzy feeling you get when you see acts of moral beauty. When you see someone do something kind, loyal, or heroic, you feel uplifted. You can feel yourself becoming a better person -- at least for a few minutes.

Everyone who has watched an episode of Oprah knows the feeling, but there was absolutely no scientific research on this emotion. Studying moral elevation led me to study feelings of awe more generally, and before I knew it, I was trying to understand a whole class of positive emotions in which people feel as though they have somehow escaped from or "transcended" their normal, everyday, often petty self.

I was beginning to see connections between experiences as varied as falling in love, watching a sunset from a hilltop, singing in a church choir, and reading about a virtuous person. In all cases there's a change to the self -- a kind of opening to our higher, nobler possibilities.

As I tried to make sense of the psychology of these "self-transcendent emotions," I began to realize that religions are often quite skilled at producing such feelings. Some use meditation, some use repetitive bowing or circling, some have people sing uplifting songs in unison.

Some religions build awe-inspiring buildings; most tell morally elevating stories. Some traditional shamanic rites even use natural drugs. But every known religion has some sort of rite or procedure for taking people out of their ordinary lives and opening them up to something larger than themselves.

It was almost as if there was an "off" switch for the self, buried deep in our minds, and the world's religions were a thousand different ways of pressing the switch.

TED.com: Robert Wright on optimism

Read more and watch more on CNN