Future inspiration - Automatic room lights

Based on what we have learnt in this chapter and in Chapter 6, Day 4 - Building a Standalone Device previously, the following figure is a simple idea to automate the lights at your home:

Figure 6: Automatic room lights

As depicted in the preceding figure, the Arduino is interfaced with your room light via a Relay module in order to keep the DC circuit separate from the high voltage AC mains. Utilize what we learnt in this chapter for achieving the Relay module interfacing.

The DC part of the circuit has an HC-SR04 ultrasonic sensor and has been powered from an external battery. Use the knowledge you gathered in Chapter 6, Day 4 - Building a Standalone Device for the basic wiring and sketch for using an ultrasonic sensor with the Arduino.

Place the HC-SR04 ultrasonic sensor strategically on one side of the entrance door to a room. Let us say the door is 3 feet (36 inches) in width. The ultrasonic sensor should be placed in such a way, that normally the ultrasonic sensor should only read the width of the door. If nobody enters through the door then the ultrasonic sensor will always return a distance of 3 feet (36 inches) approximately (do not worry about precision at this point). However, as soon as someone enters through the door, the ultrasonic sensor will immediately read a reduced distance (which will be less than 36 inches). You can reuse the sketch from Chapter 6, Day 4 - Building a Standalone Device and introduce an if statement to capture the event when someone enters through the door, as shown in the following code:

// Convert the distance to centimeters 
distance = (duration/2) / 29.1;

// you may need to tweak the number 30 below
// depending upon the width of your door
// and also depending upon what object will be entering the room
if (distance < 30)
{
// trigger the AC-DC Relay device to ON state
// so that the interfaced room light is switched ON
}

The factor 29.1 shown in the preceding code has been calculated based on the speed of sound in air, explained as follows:

343 m/sec = 34300 cm/sec = 0.0343 cm/micro-sec = 1/29.1

So as soon as someone tries to enter through the door, they will cut into the line of measurement of the ultrasonic sensor. This will result in the ultrasonic sensor returning a lower value than the width of the door. That is when the sketch will detect that someone is trying to enter the room and will trigger the Relay to ON position, thus resulting in switching ON the room light.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.125.171