Overview

This project is about creating an automatic fan control system that automatically turns the fan on and off depending on the room temperature. I used an Arduino UNO microcontroller here, you can also use a MINI, but there will be some problems with power regulation, so choose UNO 🙂 The temperature sensor here is an LM35 module that you can use and it will also give you the most accurate readings.

Arduno Specifications:

  • Microcontroller ATMEGA 328P
  • Operating Voltage 5V
  • Input Voltage (recommended) 7-12V
  • Input Voltage (limit) 6-20V
  • Digital I/O Pins 14 (of which 6 provide PWM output)
  • PWM Digital I/O Pins 6 
  • Analog Input Pins 6
  • DC Current per I/O Pin 20 mA
  • DC Current for 3.3V Pin 50 mA
  • Flash Memory 32 KB
  • SRAM  2KB
  • EEPROM 1 KB
  • Clock Speed 16 MHz

 Block diagram:

About I2C communication protocol:

 I2C communication is the short form for inter-integrated circuits. It is a communication protocol developed by Philips Semiconductors for the transfer of data between a central processor and multiple ICs on the same circuit board using just two common wires. Owing to its simplicity, it is widely adopted for communication between microcontrollers and sensor arrays, displays, IoT devices, EEPROMs etc. This is a type of synchronous serial communication protocol. It means that data bits are transferred one by one at regular intervals of time set by a reference clock line.

Features

The following are some of the important features of the I2C communication protocol:

  • Only two common bus lines (wires) are required to control any device/IC on

    the I2C network.

  • No need for prior agreement on data transfer rate like in UART.
  • So the data transfer speed can be adjusted whenever required.
  • I2C networks are easy to scale. New devices can simply be connected to  

   the two common I2C bus lines.

I2C Bus (Interface wires) consists of just two wires and are named Serial Clock Line (SCL) and Serial Data Line (SDA). The data to be transferred is sent through the SDA wire and is synchronized with the clock signal from SCL. All the devices/ICs on the I2C network are connected to the same SCL and SDA lines as shown below:

  A pull up resistor is used for each bus line, to keep them high (at positive voltage)

  by default.

LM-35 Temperature sensor:

LM35 is a temperature sensor that outputs an analog signal which is proportional to the instantaneous temperature. The output voltage can easily be interpreted to obtain a temperature reading in Celsius. The coating also protects it from self-heating. Low cost and greater accuracy make it popular among hobbyists, DIY circuit makers, and students. Many low-end products take advantage of low cost, and greater accuracy and use LM35 in their products.

LM35 Temperature sensor Features

  • Calibrated Directly in Celsius (Centigrade)
  • Linear + 10-mV/°C Scale Factor
  • 0.5°C Ensured Accuracy (at 25°C)
  • Rated for Full −55°C to 150°C Range
  • Suitable for Remote Applications
  • Operates from 4 V to 30 V
  • Less than 60-µA Current Drain
  • Low Self-Heating
  • Non-Linearity Only ±¼°C Typical

Step by step execution process:

  1.  Connect the sensor’s middle pin as a analog input pin A0 to the analog Arduino Uno board and also Vcc and Gnd respectively.
  2. Connect the OLED display’s SDA and SCK pins to the analog inputs pins A4 and A5 respectively to the board.
  3. Select pin A0 as the analog input in the code.
  4. Give the command “PinMode” to select the OLED as led output.
  5. Give other commands for selecting text size, position, colour, etc in the code.
  6. Keep a delay of 1 second for updating the temperature values.
  7. Execute the final code and verify the output.

Final code:

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128   // OLED display width, in pixels
#define SCREEN_HEIGHT 64   // OLED display height, in pixels
#define led 13

int val;
int tempPin = 0;

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup()
{
  Serial.begin(115200);
  pinMode(led, OUTPUT);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) 
  {        // Address 0x3D for  128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }

    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(0, 0);
    display.print("Temp.(C):");
}

void loop()
 {
    val = analogRead(tempPin);
    float mv = ( val/1024.0)*5000;
    float cel = mv/10;
        // convert the analog volt to its temperature equivalent
    Serial.print("TEMPERATURE = ");
    Serial.println(cel); // display temperature value

    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(0, 0);
    display.print("Temp.(C):");
 
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(20,30);
    display.println(cel);
    
    display.drawRect(1,20,127,40,WHITE);
    display.display();
   
   if(cel >60)
    {
     digitalWrite(led, HIGH);  
     display.clearDisplay();
     display.setTextSize(2);
     display.setTextColor(WHITE);
     display.setCursor(0,30);
     display.println("Temp High");        
     display.drawRect(1,20,127,40,WHITE);
     display.display();
}

    else
    digitalWrite(led, LOW);
    delay(1000);

}

By Admin

Leave a Reply

Your email address will not be published.

%d bloggers like this: