• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Need circuit help? Post them in the comments! I've answered over 50,000!

Blog | Categories | About | Contact | Calculators-online
You are here: Home / Remote Control Circuits / Ultrasonic Smart Automatic ON/OFF Switch Circuit

Ultrasonic Smart Automatic ON/OFF Switch Circuit

Last Updated on January 8, 2024 by Swagatam 13 Comments

In this article we are going to build a smart automatic ON/OFF switch using Arduino, which can turn on or off gadgets automatically by sensing the presence of human nearby through the concept of ultrasonic.

We are going to use ultrasonic module and Arduino to sense the presence of human which activates the gadgets such as table lamp or table fan.

We sometimes forget to turn off the lights or fan while leaving home, at the middle of a trip; we’ll realize that we forgot to turn off “something”. This is enough to ruin our joyful trip. But some don’t even realize it; the energy gets wasted until we return to home.

In this project we are concentrating on gadgets which we use frequently such as table lamps/ table fan and other gadgets, where we sit and move frequently. Leaving these gadgets on for long period may lead to potential energy and money loss.

The Design:

The heart and brain of this smart automatic ON/OFF switch using Arduino is an ultrasonic module, and arduino respectively. The ultrasonic module senses the presence of human, but the ultrasonic module can’t differentiate between a human and an obstacle such as chair in front of the table. Therefore in order to enable this feature we are going to set a threshold distance between the sensor and human.

The distance between the sensor and an object will reduce when new obstacle comes in between them such a human. If Arduino detects the distance between two object the set level goes below the threshold value and this triggers the relay.

When the person moves out of the threshold range it turns off the relay.

smart2Bon off

The above diagram illustrates the triggering of the relay in the presence of human, since Arduino detected the distance below the threshold value.

smart2Bon off1

The above diagram illustrates that relay is held switched off in the absence of human, since the arduino continues to detect the distance above threshold value.

The program is written in such a way that it measures the distance between the sensor and obstacle in real time.

The users need to input the threshold value in centimeter before uploading to arduino.

How it Works

Ultrasonic Smart Automatic ON/OFF Switch Circuit

The ultrasonic sensor can be directly inserted on analog pins from A0 to A3, sensors facing outward, this may reduce wire congestion while prototyping the circuit.

 

NOTE: #PIN 7 is the output to relay

//--------------------Program developed by R.Girish-------------------//
const int trigger = A1;
const int echo = A2;
int vcc = A0;
int gnd = A3;
int OP = 7;
long Time;
float distanceCM;
float distance = 15;  // set threshold distance in cm
float resultCM;
void setup()
{
pinMode(OP,OUTPUT);
pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
pinMode(vcc,OUTPUT);
pinMode(gnd,OUTPUT);
}
void loop()
{
digitalWrite(vcc,HIGH);
digitalWrite(gnd,LOW);
digitalWrite(trigger,LOW);
delay(1);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
Time=pulseIn(echo,HIGH);
distanceCM=Time*0.034;
resultCM=distanceCM/2;
if(resultCM<=distance)
{
digitalWrite(OP,HIGH);
delay(4000);
}
if(resultCM>=distance)
{
digitalWrite(OP,LOW);
}
delay(10);
}
//-----------------Program developed by R.Girish-------------------//

NOTE:

In the program replace the value 15 with your distance between the sensor and table’s edge + 7 to 10cm.

float distance = 15; // set threshold distance in cm

For example: if the distance between sensor and table is 100cm, add 7 to 10 cm more and place the value. The values are in centimeter. It may take up to 4 seconds to turn off the relay after the person moved away from the sensor’s range.

You'll also like:

  • 1.  Remote Controlled Submersible Pump Circuit
  • 2.  Firecracker Igniter circuit [Remote Controlled with Timer]
  • 3.  Whistle Activated Switch Circuit
  • 4.  Bluetooth Car Ignition Lock Circuit – Keyless Car Protection
  • 5.  Vibrating Cell Phone Remote Control Circuit
  • 6.  Simple Remote Controlled Curtain Open/Close Circuit Diagram

About Swagatam

I am an electronics engineer with over 15 years of hands-on experience. I am passionate about inventing, designing electronic circuits and PCBs, and helping hobbyists bring their projects to life. That is why I founded homemade-circuits.com, a website where I share innovative circuit ideas and tutorials. Have a circuit related question? Leave a comment.... I guarantee a reply!

Previous Post: « 6 watt Audio Amplifier Circuit Using TDA1011
Next Post: RC Helicopter Remote Control Circuit »

Reader Interactions

Comments

  1. Dan says

    June 7, 2020 at 7:50 am

    Thanks for your good works, I am a keen follower. Please can you help me with an arduino cylcle ON/OFF timer code? The timer should be on for 10 minutes and then off for 8 hours then on for 10 minutes, off for 8 hours repeating like that. An LED display may be ok but not necessary
    Thank you.

    Reply
    • Swagatam says

      June 7, 2020 at 2:20 pm

      Thank you, appreciate your thoughts, you can trey the following design and check if it solves your requirement:

      https://www.homemade-circuits.com/arduino-2-step-programmable-timer-circuit/

      Reply
  2. arun says

    May 9, 2020 at 10:06 pm

    where i can buy this

    Reply
  3. Leo Santiago says

    March 24, 2020 at 3:41 pm

    Hi Mr. Swag,
    I am a beginner in Arduino and I level up from LEDs to Sensors. I built and tested your project it’s proven working and useful for my home. I tried different distances and delay time but it works accordingly.
    I want to do more on what you started and if you can help to incorporate the serial print so that the distance value and assigned trigger distance to be visible from the Arduino Serial Monitor?

    I am from the Philippines.

    Thanks a lot.

    Reply
    • Swagatam says

      March 25, 2020 at 9:29 am

      Hi Mr. Leo, I am sorry my Arduino knowledge is not good so will be difficult for me to help you in this regard.

      Reply
  4. Leo Santiago says

    February 21, 2020 at 8:53 pm

    THANK YOU! you provide solution to my Ultrasonic on/off requirement!

    Reply
    • Swagatam says

      February 22, 2020 at 6:20 am

      You are welcome! Glad it helped you!

      Reply
  5. linsonbenny says

    February 11, 2020 at 4:35 pm

    hi,your project was good and useful to us
    we are providing inplant training in cheenai for all engineering department students

    Reply
    • Swagatam says

      February 11, 2020 at 4:46 pm

      Thank you, Glad it helped you!

      Reply
  6. swixxknight says

    January 8, 2018 at 6:29 pm

    can i use more than one sensor, if so how do i modify the code.

    do you know the maximum operating distance

    Reply
    • Swagatam says

      January 8, 2018 at 9:08 pm

      sorry I am not sure about the procedures…

      Reply
  7. GR says

    January 2, 2017 at 12:21 pm

    Hi Yashas,

    There is no error in the program, I double checked.

    If possible try to share link to your screenshot.

    Regards

    Reply
  8. Yashas Dhanmeher says

    January 2, 2017 at 7:53 am

    distanceCM was not declared in this scope error is coming what to do

    Reply

Need Help? Please Leave a Comment! We value your input—Kindly keep it relevant to the above topic! Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Subscribe to New Circuit Ideas

Categories

  • Arduino Projects (87)
  • Audio and Amplifier Projects (132)
  • Automation Projects (17)
  • Automobile Electronics (101)
  • Battery Charger Circuits (82)
  • Datasheets and Components (102)
  • Electronics Theory (143)
  • Free Energy (37)
  • Games and Sports Projects (11)
  • Grid and 3-Phase (19)
  • Health related Projects (25)
  • Home Electrical Circuits (12)
  • Indicator Circuits (14)
  • Inverter Circuits (87)
  • Lamps and Lights (142)
  • Meters and Testers (69)
  • Mini Projects (46)
  • Motor Controller (64)
  • Oscillator Circuits (27)
  • Pets and Pests (15)
  • Power Supply Circuits (108)
  • Remote Control Circuits (50)
  • Security and Alarm (64)
  • Sensors and Detectors (100)
  • Solar Controller Circuits (59)
  • Temperature Controllers (42)
  • Timer and Delay Relay (49)
  • Transmitter Circuits (29)
  • Voltage Control and Protection (37)
  • Water Controller (36)

Calculators

  • Battery Back up Time Calculator
  • Capacitance Reactance Calculator
  • IC 555 Astable Calculator
  • IC 555 Monostable Calculator
  • Inductance Calculator
  • LC Resonance Calculator
  • LM317, LM338, LM396 Calculator
  • Ohm’s Law Calculator
  • Phase Angle Phase Shift Calculator
  • Power Factor (PF) Calculator
  • Reactance Calculator
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator
  • Filter Capacitor Calculator
  • Buck Converter Calculator
  • Boost Converter Calculator
  • Solar Panel, Inverter, Battery Calculator
  • Wire Current Calculator
  • SMPS Transformer Calculator
  • IC SG3525, SG3524 Calculator
  • Inverter LC Filter Calculator

People Also Search

555 Circuits | 741 Circuits | LM324 Circuits | LM338 Circuits | 4017 Circuits | Ultrasonic Projects | SMPS Projects | Christmas Projects | MOSFETs | Radio Circuits | Laser Circuits | PIR Projects |

Recent Comments

  • Swagatam on Best Electronic Circuit Projects
  • TOMMY on Best Electronic Circuit Projects
  • Swagatam on Inverter Circuit with Feedback Control
  • Jerry Adeosun on Inverter Circuit with Feedback Control
  • Swagatam on Contact

Company

  • Privacy Policy
  • Cookie Policy
  • About Me
  • Contact
  • Disclaimer
  • Copyright
  • Videos
  • Sitemap

Social Profiles

  • Twitter
  • YouTube
  • Instagram
  • Pinterest
  • My Facebook-Page
  • Quora
  • Stack Exchange
  • Linkedin
  • © 2025 · Swagatam Innovations