0% found this document useful (0 votes)
78 views3 pages

Project 2

This document contains code to control multiple systems using Arduino including: 1) A light controller that adjusts an LED based on light levels and distance readings from an IR sensor. 2) A temperature controller that monitors temperature with a sensor and controls fan speed. 3) A gas leakage indicator that triggers a buzzer if high gas levels are detected. 4) An electronic door lock controlled by a keypad where entering a password unlocks the servo motor position.

Uploaded by

Vallabh Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views3 pages

Project 2

This document contains code to control multiple systems using Arduino including: 1) A light controller that adjusts an LED based on light levels and distance readings from an IR sensor. 2) A temperature controller that monitors temperature with a sensor and controls fan speed. 3) A gas leakage indicator that triggers a buzzer if high gas levels are detected. 4) An electronic door lock controlled by a keypad where entering a password unlocks the servo motor position.

Uploaded by

Vallabh Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <Servo.

h>
#include <Keypad.h>
int sensePin = 0;
int ledPin = 11;
//Control DC Motor with temperature sensor
int tempPin = 2;
int fanSpeed = 10;
int GasSensorPin = 3;
int buzzer = 12;
int irPin = 1;
int currentDist = 0;
int lastDist = 0;
Servo ServoMotor;
char* password = "888"; // change the password here, just pick any 3 numbers
int position = 0;
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = { 7, 6, 5, 4 };
byte colPins[COLS] = { 3, 2, 1 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buzzer, OUTPUT);
ServoMotor.attach(9);
LockedPosition(true);
Serial.begin(9600);
}
void loop() {
// light controller
currentDist = analogRead(irPin);
//Serial.println(currentDist);
int lightVal = analogRead(sensePin);
//Serial.println(lightVal);
if ((currentDist > lastDist + thresh || currentDist < lastDist - thresh) && li
ghtVal < 90)
{
val = constrain(val, 80, 350);
int ledLevel = map(val, 80, 350, 255, 0);
analogWrite(ledPin, ledLevel);
delay(1500);
}
else
{
analogWrite(ledPin, 0);
}
lastDist = currentDist;
// Temperature Controller
float temp = analogRead(tempPin);
temp = (temp *5.0*100.0)/1024.0; // calculate temperature in degree Celsius
temp = constrain(temp, 25, 70);
int tempLevel = map(temp, 25, 70, 0, 255);
analogWrite(fanSpeed, tempLevel);
//Gas Leakage Indicator
int gasValue = analogRead(GasSensorPin);
//Serial.println(gasValue);
if (gasValue > 500)
{
digitalWrite(buzzer,HIGH);
}
else
{
digitalWrite(buzzer,LOW);
}
//Electronic door lock
char key = keypad.getKey();
//Serial.println(key);
if (key == '*' || key == '#')
{
position = 0;
LockedPosition(true);
}
if (key == password[position])
{
position ++;
}
if (position == 3)
{
LockedPosition(false);
}
delay(100);
}
void LockedPosition(int locked)
{
if (locked)
{
ServoMotor.write(11);
}
else
{
ServoMotor.write(90);
}
}

You might also like