adryanrifa
Published © MIT

Prototype Controlled Home Automation Using Arduino

This project is a prototype of a smart home.

BeginnerProtip1,389
Prototype Controlled Home Automation Using Arduino

Things used in this project

Hardware components

Resistor 10k ohm
Resistor 10k ohm
×2
Arduino Nano R3
Arduino Nano R3
×1
Resistor 330 ohm
Resistor 330 ohm
×4
LED (generic)
LED (generic)
×4
LDR, 5 Mohm
LDR, 5 Mohm
×2
Ceramic Capacitive Rain Sensor
Telecontrolli Ceramic Capacitive Rain Sensor
×3
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
DC Motor, 12 V
DC Motor, 12 V
×1
Linear Regulator (7805)
Linear Regulator (7805)
×1
Custom PCB
Custom PCB
×1

Software apps and online services

MIT App Inventor
MIT App Inventor

Hand tools and fabrication machines

Drill / Driver, Cordless
Drill / Driver, Cordless
Solder Wire, Lead Free
Solder Wire, Lead Free
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Scissor, Electrician
Scissor, Electrician
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

alhamdulilllah_dadi_mYqqOLyPV5.png

Code

dadi.ino

Arduino
#include <Servo.h>
Servo myservo;
int hujan=8;
int bawah=6;
int atas=7;
int motor=10;
int led2=2;
int led3=3;
int led4=4;
int led5=5;
int ldrjemur=A0;
int ldrlampu=A1;
int nilai, jemur;
int button1=11;
int button2=12;


void setup() {
  Serial.begin(9600);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(motor, OUTPUT);
  pinMode(hujan, INPUT_PULLUP);
  pinMode(atas, INPUT_PULLUP);
  pinMode(bawah, INPUT_PULLUP);
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  myservo.attach(9);
}

void manual(){
  if(Serial.available()>0)
  {
    char data = Serial.read();
    if (data == 'a')
    {digitalWrite(led2,HIGH);}
    else if(data == 'b')
    {digitalWrite(led2,LOW);}
    else if(data == 'c')
    {digitalWrite(led3,HIGH);}
    else if(data == 'd')
    {digitalWrite(led3,LOW);}
    else if(data == 'e')
    {digitalWrite(led4,HIGH);}
    else if(data == 'f')
    {digitalWrite(led4,LOW);}
    else if(data == 'g')
    {digitalWrite(led5,HIGH);}
    else if(data == 'h')
    {digitalWrite(led5,LOW);}
    else if(data == 'i')
    {digitalWrite(motor, HIGH);}
    else if(data == 'j')
    {digitalWrite(motor,LOW);}
    else if(data == 'k')
    {myservo.write(55); }
    else if(data == 'l')
    {myservo.write(150); }
  }

}



void lampu(){
  nilai=analogRead(ldrlampu);
  
  if (nilai<500){
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    Serial.print("============LAMPU===========\n");
    Serial.print("Nilai sensor : ");
    Serial.print(nilai);
    Serial.print("\t");
    Serial.print("LAMPU OFF");
    Serial.print("\n");
    Serial.print("============================");
    Serial.print("\n \n");
    delay(300);
  }
  else{
     digitalWrite(led2, HIGH);
     digitalWrite(led3, HIGH);
     digitalWrite(led4, HIGH);
     digitalWrite(led5, HIGH);
     Serial.print("============LAMPU===========\n");
     Serial.print("Nilai sensor : ");
     Serial.print(nilai);
     Serial.print("\t");
     Serial.print("LAMPU ON");
     Serial.print("\n");
     Serial.print("===========================");
     Serial.print("\n \n");
     delay(300);
  }
}

void jemuran(){
  jemur=analogRead(ldrjemur);
  
  if (jemur>500){
    if (digitalRead(hujan)==LOW){
      Serial.print("============JEMURAN===========\n");
      Serial.print("Nilai sensor : ");
      Serial.print(jemur);
      Serial.print("\t");
      Serial.print("Hujan");
      Serial.print("\n");
      Serial.print("=============================");
      Serial.print("\n \n");
      delay(300);
      myservo.write(150); 
      delay(15);  
    }
  }

  else if (jemur<500){
    if (digitalRead(hujan)==HIGH){
      Serial.print("============JEMURAN===========\n");
      Serial.print("Nilai sensor : ");
      Serial.print(jemur);
      Serial.print("\t");
      Serial.println("Tdk Hujan");
      Serial.print("\n");
      Serial.print("=============================");
      Serial.print("\n \n");
      delay(300);
      myservo.write(55); 
      delay(15);  
    }
  }
  
}

void tandon(){
  if(digitalRead(bawah)==LOW){
    if (digitalRead(atas)==LOW){
     digitalWrite(motor, LOW);
    }
  }

  else if(digitalRead(bawah)==HIGH){
    if (digitalRead(atas)==HIGH){
      digitalWrite(motor, HIGH);
    }
    
  }
}
void otomatis(){
  lampu();
  jemuran();
  tandon();
}
void tombol(){
 
  if (digitalRead(button1)==LOW){
  while(1){
    lampu();
    jemuran();
    tandon();
    if (digitalRead(button2)==LOW){
      break;
    }
  }
  }

 if (digitalRead(button2)==LOW){
    while(1){
      manual();
      if (digitalRead(button1)==LOW){
      break;
    }
    }
 } 
}

void loop() {
  tombol();
}

Credits

adryanrifa
0 projects • 1 follower

Comments