Automatic Lights control with temperature variation.

In this world of automation, there are many devices which need to be automated and it starts with simple household electric equipment such as Lights, fans etc. The electric devices work when provided proper power ie, 220v-240v at 50hz(India) now to make the simple devices work automatically it needs to be given power when required.

Relay Module which is a device which connects the circuit of AC powered devices when the user presses the button or automatically it needs to be switched ON.

Image result for relay module


  1. NO: Normally open- This pin makes the circuit normally opened by default, so when the relay activates it closes the circuit.
  2. NC: Normally Connected- This pin makes the circuit complete by default, so the circuit keeps running until the relay is activated and at this point the relay breaks the circuit.
  3. COM: Common Pin or the ground pin which needs to be connected to the microcontroller.

The temperature Measurement Sensor used is DS18B20, which is a very sensitive sensor but it is an analog sensor so the output of the sensor is purely analog(Varies frequently with time and is unstable). This type of signals needs signal processing a bit and hence an ADC(Analog to Digital Converter) is used to convert the analog signals to digital signals so that the microcontroller can process.

Image result for Ds18b20

The code(.ino file) for this project is provided in Github

#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
#define relay 3
// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup(void)
  // start serial port
  pinMode(relay, OUTPUT);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
void loop(void)
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures

  Serial.print("Temperature is: ");
  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? 
    // You can have more than one IC on the same bus. 
    // 0 refers to the first IC on the wire
  if ((ONE_WIRE_BUS)>=32){
  DigitalWrite(relay, HIGH);
  DigitalWrite(relay, LOW);

Leave a Comment

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