Mahesh Joshi
Published © GPL3+

Smart Home Automation Using Raspberry Pi and Arduino via Web

User makes request to Raspberry Pi via web or mobile app. Raspberry Pi then communicates with Arduino through Bluetooth to control devices.

IntermediateFull instructions provided8 hours14,416
Smart Home Automation Using Raspberry Pi and Arduino via Web

Things used in this project

Story

Read more

Schematics

Entire Schematic diagram

Download circuit schematic from folder schematic

Schematic diagram for arduino

Schematic diagram for bluetooth HC-05, LCD and 8 channel Relay connection for arduino.

Code

C Code for listening request from raspberry pi and sending response back to raspberry pi wireless

C/C++
Open this code in Arduino IDE. Then Click Verify and Upload to Arduino.
// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
const int lightsPin = 8;
const int fanPin = 10;
const int tvPin = 9;
String data = "";
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  digitalWrite(lightsPin, HIGH);
  digitalWrite(fanPin, HIGH);
  digitalWrite(tvPin, HIGH);
  pinMode(lightsPin, OUTPUT);
  pinMode(fanPin, OUTPUT);
  pinMode(tvPin, OUTPUT);
 
  lcd.begin(16, 2);
  //lcd.setCursor(0, 0);
  lcd.print("Welcome, Mahesh");
  lcd.setCursor(0, 1);
  lcd.print("No device:Active");
  // initialize the serial communications:
  Serial.begin(9600);
}

void clearSecondRow() {
  for (int i = 0; i < 16; i++)
  {
    lcd.setCursor(i, 1);
    lcd.write(" ");
  }
}

void loop() {
  // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // read all the available characters
    while (Serial.available() > 0) {
      data = Serial.readString();
      // display each character to the LCD
      if (data == "lights_on") {
        clearSecondRow();
        digitalWrite(lightsPin, LOW);
        lcd.setCursor(0, 1);
        lcd.print("Lights: ON");
        Serial.println(1);
        //lcd.blink();
      } else if (data == "lights_off") {
        clearSecondRow();
        digitalWrite(lightsPin, HIGH);
        lcd.setCursor(0, 1);
        lcd.print("Lights: OFF");
        Serial.println(0);
        //lcd.blink();
      } else if (data == "fan_on") {
        clearSecondRow();
        digitalWrite(fanPin, LOW);
        lcd.setCursor(0, 1);
        lcd.print("Fan: ON");
        Serial.print(1);
        //lcd.blink();
      } else if (data == "fan_off") {
        clearSecondRow();
        digitalWrite(fanPin, HIGH);
        lcd.setCursor(0, 1);
        lcd.print("Fan: OFF");
        Serial.print(0);
        //lcd.blink();
      } else if (data == "tv_on") {
        clearSecondRow();
        digitalWrite(tvPin, LOW);
        lcd.setCursor(0, 1);
        lcd.print("TV: ON");
        Serial.print(1);
        //lcd.blink();
      } else if (data == "tv_off") {
        clearSecondRow();
        digitalWrite(tvPin, HIGH);
        lcd.setCursor(0, 1);
        lcd.print("TV: OFF");
        Serial.print(0);
        //lcd.blink();
      } else if (data == "turn_all_on") {
        clearSecondRow();
        digitalWrite(tvPin, LOW);
        digitalWrite(fanPin, LOW);
        digitalWrite(lightsPin, LOW);
        lcd.setCursor(0, 1);
        lcd.print("All turned: ON");
        Serial.print(1);
        //lcd.blink();
      } else if (data == "turn_all_off") {
        clearSecondRow();
        digitalWrite(tvPin, HIGH);
        digitalWrite(fanPin, HIGH);
        digitalWrite(lightsPin, HIGH);
        lcd.setCursor(0, 1);
        lcd.print("All turned: OFF");
        Serial.print(0);
        //lcd.blink();
      }
    }
  }
}

Smart Home automation complete Source Code

Just clone this repo, and there you go.

Credits

Mahesh Joshi

Mahesh Joshi

1 project • 10 followers
By profession, Sr. Software Engineer, Javascript, React, ReactNative, Nodejs, Ruby, Unity, AWS from decades. Keen interest in IOT Project.

Comments