Full Width CSS

Room Heater automatic turn on and off using Ultrasonic sensor, Relay and Arduino

During winter offices and universities and houses, uses heater to get rid from coldness. But due to excessive use of them we can figure out increment in the electric bills. Also, the co workers of the industry, colleges and homes don't turn it off when the go out and we find loss in energy consumption and increment in bills.

So, in this tutorial, we are going to build an automatic heater using ultrasonic sensor, relay module and Arduino UNO that will sense people, if his distance is between 0 cm to 140 cm from the heater then the heater will glow otherwise it remains off.

Let's have look how we did it:

Circuit diagram:
(NOTE: First upload the program to the Arduino then connect wires in order to be safe from short circuit due to previously uploaded codes in the Arduino.)

Components required:
  1. Arduino UNO
  2. Ultrasonic Sensor
  3. 5 volt relay module
  4. A room heater
Arduino Uno:

It is a programmable micro controller that takes input in the voltage form and produces output in the voltage form. You can program the device according to your need.

Ultrasonic sensor:

The working principle of this sensor is to produce ultrasonic wave and when it strikes any medium than then the wave gets reflected back to the sensor and we measure the total time taken by the wave to travel in air from production to return of wave to the sensor and then divide the time by two to measure distance of the object from the sensor.

Time(T) =  t / 2      where, t is total time taken.

Now, in order to calculate the distance, we multiply TIME(T) by speed of sound in air.

DISTANCE = T * 343      where, 343m/s is velocity of sound in air

5 volt relay module:

It is a switching device that closes the circuit when it's input sensing voltage goes high i.e. 5 volts, in other condition the relay is off and the circuit remains open.


Copy and paste the given below code to Arduino IDE and upload it.

float echoPin=2; // attach pin D3 Arduino to pin Echo of HC-SR04

float trigPin=3; //attach pin D4 Arduino to pin Echo of HC-SR04

int heater=4; // attach pin D2 Arduino to relay

long duration; // variable for the duration of sound wave travel

int distance; // variable for the distance measurement

void setup() {

  pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT

  pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT

pinMode(heater, OUTPUT); // sets the heater as OUTPUT

digitalWrite(heater,LOW); //set heater initially low

  Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed


void loop() {

  // Clears the trigPin condition

  digitalWrite(trigPin, LOW);


  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds

  digitalWrite(trigPin, HIGH);


  digitalWrite(trigPin, LOW);

  // Reads the echoPin, returns the sound wave travel time in microseconds

  duration = pulseIn(echoPin, HIGH);

  // Calculating the distance

  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)

  // Displays the distance in cm

 if (distance<140)





In this way you can make your own automated heater using Ultrasonic Sensor and Arduino.


  1. Saves energy consumption
  2. Less worry of electric bills due to heater
  3. Modernization in the automated world

Post a Comment


  1. It is handed across the desk from player to player, counterclockwise, every time a player hand wins.This encourages every player to take an active half in dealing the game. Before playing cards are dealt from the shoe, everyone locations their bet SM카지노 on the facet they suppose will win . The player with the shoe then deals 4 playing cards alternately. Two are designated player playing cards; two are designated banker playing cards.


If you have any doubts, Please let us know.

Also you can visit my newly made freelancing account to make your project done at low price.