Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
AYUSHMAN SAHA
Published © GPL3+

Home Automation with Arduino Uno and SmartEdge Agile

Saves electricity and makes your home a smarter one with the security of Avnet.

IntermediateFull instructions providedOver 1 day4,207
Home Automation with Arduino Uno and SmartEdge Agile

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SmartEdge Agile Brainium
Avnet SmartEdge Agile Brainium
×1
LED (generic)
LED (generic)
×2
DC motor (generic)
×2
Rapid IoT Prototyping Kit
NXP Rapid IoT Prototyping Kit
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Breadboard (generic)
Breadboard (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Male/Male Jumper Wires
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
4-CHANNEL RELAY CONTROLLER FOR I2C
ControlEverything.com 4-CHANNEL RELAY CONTROLLER FOR I2C
×1

Software apps and online services

Avnet brainium
MIT App Inventor 2
MIT App Inventor 2
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Solder Flux, Soldering
Solder Flux, Soldering
Wire Stripper & Cutter, 30-20 AWG / 0.25-0.81mm Capacity Wires
Wire Stripper & Cutter, 30-20 AWG / 0.25-0.81mm Capacity Wires
thermocol

Story

Read more

Schematics

SCHEMATICS

Follow the same connections

Code

CODE

Arduino
/***************** INCLUDING LIBRARIES****************/
#include <SoftwareSerial.h> // SoftwareSerial library
#include <DHT.h>    //DHT library
#include <DHT_U.h>
/******************* DEFINING PINS********************/
#define r1l 7    
#define r2l 8
#define r1f 5
#define r2f 6 
#define ldr A0
#define Trig1 10
#define Echo1 11 
#define dhtPin 9
#define Trig2 12
#define Echo2 13
#define DHTTYPE DHT11
/************************* INTITIATING VARIABLES****************/
int distance2 = 0;
int duration2 = 0;
int distance1= 0;
int ldrv = 0;
int duration1=0;
char bt =0;
int h=0;
int t = 0;
/************************* INTITIATING DHT SENSOR****************/
DHT dht(dhtPin, DHTTYPE);
/******************** Intitiating softwareSerial ************/
SoftwareSerial btSerial(3,2);
// void setup
void setup()
{
  btSerial.begin(9600);
  Serial.begin(9600);
  dht.begin();
  pinMode (r1l,OUTPUT);
  pinMode(r1f,OUTPUT);
  pinMode (r2f,OUTPUT);
  pinMode (r2l,OUTPUT);
  pinMode (Trig1,OUTPUT);
  pinMode (Echo1,INPUT);
  pinMode (Trig2,OUTPUT);
  pinMode (Echo2,INPUT);
  pinMode (dhtPin,INPUT);
  pinMode(ldr,INPUT);
  
}
void loop()
{
  Measure();
  delay(25);
  CheckAction(); 
}


void Measure()
{ 
  // Measuring Temperature and Humidity
    h = dht.readHumidity();
    t = dht.readTemperature();
     if (isnan(h) || isnan(t)) 
     {
     h = 0;
     t = 0;
     return;
     }
     Serial.println("humidity = ");
      Serial.println(h);
  Serial.println("temperature = ");
       Serial.println(t);
  // Measuring Ultrasonic distance
    

 digitalWrite(Trig1, LOW); 
 delayMicroseconds(2); 
 digitalWrite(Trig1, HIGH);
 delayMicroseconds(10); 
 digitalWrite(Trig1, LOW);
 duration1 = pulseIn(Echo1, HIGH);
 distance1 = duration1/58.2;
 Serial.print("ROOM 1 = ");
 Serial.println(distance2);
 
 digitalWrite(Trig2, LOW); 
 delayMicroseconds(2); 
 digitalWrite(Trig2, HIGH);
 delayMicroseconds(10); 
 digitalWrite(Trig2, LOW);
 duration2 = pulseIn(Echo1, HIGH);
 distance2 = duration2/58.2;
 Serial.print("ROOM 2 = ");
 Serial.println(distance2);
 
delay(10);

 ldrv= analogRead(ldr);
 Serial.println("ldr = ");
 Serial.println(ldrv);
delay(10);
 bt = btSerial.read();
 Serial.print("bt =");
 Serial.println(bt);

 delay(50);
 }


 void CheckAction()
 {  
   // checking fans ......
   if(t>22 && h>40)
    {
       // checking room 1 fans ......    
       if (distance1 > 5)
         digitalWrite(r1f,HIGH);
       else  
         digitalWrite(r1f,LOW);
         
       // checking room 2 fans .......
         if (distance2 > 5)
         digitalWrite(r2f,HIGH);
       else  
         digitalWrite(r2f,LOW);
    }

    // checking lights ......
    if(ldrv > 4.5)
      {
          // checking room 1 lights ......    
       if (distance1 > 5)
         digitalWrite(r1l,HIGH);
       else  
         digitalWrite(r1l,LOW);
         
       // checking room 2 lights .......
         if (distance2 > 5)
         digitalWrite(r2l,HIGH);
       else  
         digitalWrite(r2l,LOW); 
      }
        
       //Checking Bluetooth..........
     if (bt == '0')
{
 digitalWrite(r1l,HIGH);
  digitalWrite(r1f,HIGH);  // ROOM 1 APPLIANCES ON
   Serial.print('a');
}
    if (bt == '1')
    {   
      Serial.print('b');
  digitalWrite(r1f,LOW);   // ROOM 1 APLLIANCES OFF
  digitalWrite(r1l,LOW);
    }

    if (bt == '2')
{
 digitalWrite(r2l,HIGH);
  digitalWrite(r2f,HIGH);  // ROOM 2 APPLIANCES ON
   Serial.print('c');
}   


    if (bt == '3')
{ 
  Serial.print('d');
  digitalWrite(r2f,LOW);  // ROOM 2 APPLIANCES OFF 
  digitalWrite(r2l,LOW);
}
 } 

Credits

AYUSHMAN SAHA

AYUSHMAN SAHA

5 projects • 3 followers

Comments