Make a Contactless (touchless) Switch

6,580

32

8

Introduction: Make a Contactless (touchless) Switch

About: Hey, my name is Nhan and I'm a student of high school Heilig Hartinstituut Heverlee in Leuven. I'm studying Science-STEM (Science-Technology-Engineering-Mathematics).

Hello everybody. In this Instructable I'll show you how to make easily a contactless switch with a distance sensor. It might be very useful for your house or other machines.

Because I'm a student and I'm making a project about 'Passive house' and I want to have a special switch.

Step 1: What You Need

What you need to make

this switch, are:

-wires

-a breadboard

-a distance sensor. I prefer the HC-SR04 or a HC-SR05.

-an Arduino board

-an LED to test the program

Step 2: Wiring

The distance sensor has 4 pins:

-VCC

-TRIG

-ECHO

-GND

Connect:

-VCC to 5V pin on your arduino board

-TRIG to a digital pin (in my case pin 3)

-ECHO to another digital pin (in my case pin 4)

-GND to GND

Connect the LED to a digital pin, it has to be different from the other pins.

Step 3: Program

For some of you who don't understand the code, there are two parts (in 'void loop') in my code:

-The first part is about the distance sensor. To measure the distance, the sensor sends and receives echo (kind of sound). I've used the length of an A4 sheet (29.7 cm - 11.69") to calibrate it. In this calculation "distance = (duration / 2) / 29.7", I've divided the duration in 2 because the time that the echo needs to go from this side of the sheet to another side of the same sheet, is the same as the echo goes from another side to the sensor (it is placed at this side of the sheet).

-The second part is the main part of this code. This is the structure of my code:

While(...){

...;

While(...){

...;

While(...){

...;

While(...){

...;

}

}

}

}

If your hand (or an object) is between 2 and 10 cm (0.79"-3.94", you can change this range in the program), the program will enter the first "While" and the LED (or something else) will turn on. And when you move your hand further than 10 cm (the 2nd "While"), the LED still have to turn on (like a normal switch). If your hand is between 2 and 10 cm for the 2nd time (3rd "While"), the LED has to turn off. And when you move it away from the sensor (>10 cm, 4th "While"), the LED still have to turn off until you move your hand closer than 10 cm again.

Step 4: Result...

Sorry for my English. I'm not a native speaker. If you have any improvement, they are welcome!

If you are interested in this project, please click on the button 'Vote' in the upper right and vote it!

Sensors Contest 2017

Participated in the
Sensors Contest 2017

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

Be the First to Share

    Recommendations

    • For the Home Contest

      For the Home Contest
    • Make It Bridge

      Make It Bridge
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge

    8 Comments

    0
    dnfh1949
    dnfh1949

    5 years ago

    Sounds really interesting and I will try it . If you are interested (ignore this if not!) I think there are only two very small "errors" in your English:

    "1. A distance sensor have 4 pins: " '1. The distance sensor has 4 pins.'

    "You can just take the mine to use it." Not quite sure what you mean, but I think it is

    'Use my code is you wish.'

    0
    NguyenN90
    NguyenN90

    Reply 5 years ago

    Thanks!

    0
    rafununu
    rafununu

    6 years ago

    Did you test your code with an object approaching ?

    You'll agree the code is redundant, but if it works...

    0
    NguyenN90
    NguyenN90

    Reply 6 years ago

    Yes, I've tested my code with an object approaching and normally it should work. In my case, I've tested many times and it worked! So, why not?

    0
    rafununu
    rafununu

    6 years ago

    Actually, I'm working on a similar project to dim my kitchen lights but there are too much reading errors even with delays. I'll try with "while" instead of "if then else", that looks better, I'll let you know.

    0
    NguyenN90
    NguyenN90

    Reply 6 years ago

    I'm also using the 'while' function instead of 'if else' and it works very well !

    0
    DIY Hacks and How Tos

    Cool. No contacts means that there are no parts to wear out.

    0
    NguyenN90
    NguyenN90

    Reply 6 years ago

    What I mean about my project is that I want to make a switch to turn on ... (ex an LED) without touching the switch, just like a normal switch.