Project showcase
Arduino House

Arduino House © CC BY

I created a house with a light that gradually turns on a light if it is dark and an alarm connected to the door.

  • 888 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

I created a house with a light that graually turn on a light if it is dark and an alarm connected to the door the squeeze and send email if someone enter the house!

Step 1: Make the circuit

Use my Fritzing file to copy the circuit I realized. You will need:

  • LED
  • buzz
  • bulb

You can add a potenziometer (for buzz volume) and everything you'd like! Upload the casa.ino file into your board!

Step 2: Set the light

On my file is already done!

Link a bulb lamp to a transistor and the transistor with one of your Arduino's pin. Create a circuit with a 2K resistence and a fotoresistence, this is useful to read the voltage in the connection of two resistence.

Done! The lamp turns on in the dark! I did analogRead from fotoresistence and then analogWrite to transistor!

Step 3: Set the alarm

Download Blynk app! (http://www.blynk.cc/)

Create a circuit with a push button, and a contact sensor for the door: when the door is closed digitalRead(button) should be 0! Create an email widget on the app! It's done! My code sends an email when the door's open!

Code

casa.inoArduino
This do everything
/*
Little Home by Filippo
This code is licensed under Creative Commons BY license. If reuse you should link the page where you find this code.

Have a nice making!
*/

/**************************************************************
 *
 BLYNK comments
 
 * 1. Optional, but recommended.
 *    Connect additional USB-serial adapter to see the prints.
 *
 * 2. Edit auth token and upload this sketch.
 *
 * 3. Run the script (script located in "scripts" folder of library root,
 *    e.g. 'blynk-library/scripts') for redirecting traffic to server:
 *
 *      for Windows:
 *                     1. Open cmd.exe
 *                     2. write : (your way to blynk-ser.bat folder) example: "cd C:\blynk-library-0.3.1\blynk-library-0.3.1\scripts"
 *                     3. write : "blynk-ser.bat -c COM4" (where COM4 is port with your Arduino)
 *                     4. And press "Enter" , press "Enter" and press "Enter"
 *
 *      for Linux and OSX:
 *
 *                    ./blynk-ser.sh (may need to run with sudo)
 *
 *    You can specify port, baud rate, and server endpoint like this:
 *      ./blynk-ser.sh -c <serial port> -b <baud rate> -s <server address> -p <server port>
 *
 *    For instance :
 *      ./blynk-ser.sh -c /dev/ttyACM0 -b 9600 -s blynk-cloud.com -p 8442
 *
 *    Run blynk-ser.sh -h for more information
 *
 *    Be sure to select the right serial port (there may be multiple).
 *
 *    Attention!
 *        Arduino IDE may complain with "programmer is not responding".
 *        You need to terminate script before uploading new sketch.
 *
 * 4. Start blynking! :)
 *
 **************************************************************/

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3); // RX, TX
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>
#include <SimpleTimer.h>


SimpleTimer timer;


// You should get Auth Token in the Blynk App.
char auth[] = "a8659c1939b645a88afeca5928a0118a";
 //variables
int rpin=A0, doorsensor=A1, button=A2; //which pin read?
int value;  //read value
int parsed; //value after map
int setmin=790, setmax=960; //Values for fotoresistence (low=light)
unsigned long cmil, pmil=0; //current and previous millis
int trpin=5,tr;
int buzz=4;

class led{
 private:
   int pin;
   bool state;
   unsigned long current;   
   unsigned long previous;
  public:
   led(int a){pin=a;pinMode(pin, OUTPUT);state=0;previous=millis();};
   led(){};
    void set_on(){digitalWrite(pin,HIGH);state=1;};
    void set_off(){digitalWrite(pin,LOW);state=0;};
    void blynk(); 
    void set_pin(int a){pin=a;pinMode(pin,OUTPUT);};
};

class alarm{
  private:
  led alarmled;
  bool state;
  int sensor;
  public:
  alarm(int a, int b){alarmled.set_pin(a); sensor=b; state=0;};
  void set_on(){alarmled.blynk();state=1;};
  void set_off(){alarmled.set_off();state=0;};
  bool is_on(){return state;};
  bool warning(){if(state==1&&analogRead(sensor)>10) return 1; else return 0;};
};

void led::blynk(){
 current=millis();
if(state) if((current-previous)>800) {set_off(); previous=current;}
if(!state) if((current-previous)>800) {set_on(); previous=current;}
}

alarm door= alarm(9,doorsensor);
led test= led(13);


 void fakeloop(){
  test.blynk();
  if(digitalRead(button)) door.set_on(); else door.set_off();
  //light
  cmil=millis();
  value=analogRead(rpin);
  parsed=map(value,setmin,setmax,0,1023);
  parsed=constrain(parsed,0,1023); //no overscale
tr=map(parsed,0,1023,0,255);
analogWrite(trpin,tr);
if(door.warning()) {tone(buzz,440); Blynk.email("fili27182@gmail.com", "#arduino", "Warning, door's open!!"); Blynk.notify("Warning");
} else noTone(buzz);
//if(cmil-pmil>900){Serial.print("read:");Serial.println(value);Serial.print("write:");Serial.println(tr);Serial.println(); pmil=cmil;}
//delay(1);
}

void setup()
{
  SwSerial.begin(9600);
  Blynk.begin(auth);
  timer.setInterval(1000L, fakeloop);
}

void loop()
{
  Blynk.run();
  timer.run();
}

Schematics

Comments

Similar projects you might like

Enter the house like a Sith Lord

Project tutorial by Prasantha Jayakody

  • 25,393 views
  • 10 comments
  • 84 respects

Automated door for chicken house

by Quelud

  • 2,439 views
  • 2 comments
  • 9 respects

Rain Warning Display on Mobile for your Home Garden

Project showcase by Kaustubh Agarwal

  • 10,899 views
  • 7 comments
  • 34 respects

Control Lights with your Phone from Anywhere in the World!

Project showcase by Kaustubh Agarwal

  • 25,555 views
  • 4 comments
  • 45 respects

Lights On/Off using Twitter

Project showcase by Kaustubh Agarwal

  • 5,913 views
  • 0 comments
  • 16 respects
Add projectSign up / Login