Fun With Infrared Motion Sensor

Very few of the projects I’ve done actually had any real life purpose. The rest were just Can I do it? projects. Here’s one more to that little list. So last year, the fan switch in my room changed its position, from the spot where it was in a one arm distance behind my desktop computer table, to a spot where I had to walk three steps, climb my bed and walk another three steps to reach. Too much effort for something that is required to be done tens of times in a day. Naturally, I didn’t bother to turn it off whenever I left the room, and at times, the fan used to stay running long after I had left, until mom or dad noticed it and turned it off again, just before giving me a nice stare. Something had to be done.

I had this PIR module that I had bought a couple of years ago with a friend. PIR [for Passive Infrared] sensor triggers when a hot body comes in its range, like a human being. I had to make use of it somehow to control the fan in the room. I had to Google just about everything about this project, and slowly I discovered that you cannot just put the AC mains and DC circuits on the same breadboard, and expect them to be nice to each other. As a result, relay was discovered. [The one I have used is a more compact, cheaper version].

So a relay to act as a switch to turn the fan on and off, a PIR sensor to detect me entering the room and something in between to interface the two. Arduino should do it. So next is to code the arduino such that on receiving a Truefrom the PIR, the arduino would close the switch, activating the relay to close the switch of the fan, and stay like that for a couple of minutes. I didn’t want it to go on-off every 3 seconds, hence the timeout.

Next was mounting all of it together. A breadboard would’ve been unsafe, as per the Internet, hence I bought a perfboard for the purpose. I soldered everything to its place, and the final result was something like the following. Oh but first, some code.

The code which was shamelessly ripped off Arduino.cc

Here is how it looked [Heavy images. Patience!]



My desk that beautiful day!

Now Aditya would’ve told you that this project is what electronics people do when they’re like 5. Nevertheless, I was too proud of this. Not just because I could do it, but because I needed it.

So did it work? No. The range of the PIR sensor was a bit too small for the entire room, and I had to literally dance in front of it to trigger it. Solution? Multiple PIRs to cover the entire room. Also, I realized how easily I could just add the tubelight to the same circuit. Just add another relay and connect it to the LDR sensor and set it to trigger when the daylight fell below a certain threshold.

Suddenly, automating stuff in the room seemed a bit too simple, and it really is, even for an electronics novice like myself. The Internet gives you that power. As always, thank you for reading, and pardon any silly technical mistakes that I must’ve made in the post (even better, correct me ;).