---
# System prepended metadata

title: Temp controlled door lock
tags: [Arduino]

---

###### tags: `Arduino`
# Temp controlled door lock
In this project, my goal is to use a infrared temperture sensor to detect human's body temperture and decide whether to let him/her in. At the mean time, the OLED screen will show the temperture and the red/green led will lightup to show the status.

## Appearence
![](https://i.imgur.com/8gIdb7h.jpg =500x)

![](https://i.imgur.com/vypnPmA.jpg =500x)

## Wiring
![](https://i.imgur.com/Va7IHWt.jpg)

## Program flow
![](https://i.imgur.com/acEMmyW.png =750x)

## Code
```cpp=
#include <Wire.h>
#include <Adafruit_SH1106.h>
#include <Adafruit_MLX90614.h>
#include <Servo.h>

Servo ss;

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

#define OLED_RESET -1
Adafruit_SH1106 display(OLED_RESET);

const int r = 7, g = 8;

void setup(){
    pinMode(7,OUTPUT);
    pinMode(8,OUTPUT);
    Serial.begin(9600);

    display.begin(SH1106_SWITCHCAPVCC, 0x3C);
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(2);
    display.setCursor(0,0);
  
    mlx.begin();

    ss.attach(9);
    ss.write(85);
}

void loop() {
    float temp = mlx.readObjectTempC();
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("Temp:");
    display.setCursor(0,25);
    display.print(temp);
    display.display();
    
    if(temp<35){
        ss.write(85);
        digitalWrite(r,0);
        digitalWrite(g,0);
    }else if(temp>=35.5&&temp<=37.5){
        display.setCursor(0,50);
        display.print("Pass");
        display.display();
        digitalWrite(g,1);
        ss.write(180);
        delay(3000);
        ss.write(85);
        digitalWrite(g,0);
        delay(500);
    }else{
        digitalWrite(r,1);
        display.setCursor(0,50);
        display.print("Block");
        display.display();
        delay(500);
        digitalWrite(r,0);
    }
    delay(100);
}
```