Chpritam Patro
Published © GPL3+

Home automation with bolt wifi module and arduino part-1

This is just a demo project using basic components, stay tuned and follow this account to see the upgrades.

BeginnerWork in progress1 hour716
Home automation with bolt wifi module and arduino part-1

Things used in this project

Story

Read more

Schematics

circuit diagram

use this to make connections

Code

ardunio

C/C++
#include<Servo.h>
Servo a;
//1-on light
//2-off light
//3-on fan 
//4-off fan
//5-on extra
//6-off extra
void setup()
{
  a.attach(5);
  pinMode(4,OUTPUT);//4-fan
  pinMode(3,OUTPUT);//3-light
  pinMode(2,OUTPUT);//2-EXTRA
  Serial.begin(9600);
}
int val;
void loop()
{
  if(Serial.available()>0){
    Serial.println("okk");
    val=Serial.read();
    delay(2);
    Serial.println(val);
  }
   if (val==49)//1
    {
      digitalWrite(4,HIGH);
    }
   if (val==50)//2
    {
      digitalWrite(4,LOW);
    }
    if (val==51)//3
    {
      digitalWrite(3,HIGH);
    }
    if (val==52)//4
    {
      digitalWrite(3,LOW);
    }
    if (val==53)//5
    {
      digitalWrite(2,HIGH);
    }
    if (val==54)//6
    {
      digitalWrite(2,LOW);
    }
}

pyqt5 code

Python
use this code for gui and serial communication.
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'home.ui'
#
# Created by: PyQt5 UI code generator 5.14.2
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets
from boltiot import Bolt

class Ui_fan_2(object):
    def setupUi(self, fan_2):
        fan_2.setObjectName("fan_2")
        fan_2.setWindowModality(QtCore.Qt.ApplicationModal)
        fan_2.resize(1088, 799)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(fan_2.sizePolicy().hasHeightForWidth())
        fan_2.setSizePolicy(sizePolicy)
        fan_2.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.widget = QtWidgets.QWidget(fan_2)
        self.widget.setGeometry(QtCore.QRect(140, 60, 781, 431))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.widget.sizePolicy().hasHeightForWidth())
        self.widget.setSizePolicy(sizePolicy)
        self.widget.setObjectName("widget")
        self.gridLayout = QtWidgets.QGridLayout(self.widget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.labelfan = QtWidgets.QLabel(self.widget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.labelfan.sizePolicy().hasHeightForWidth())
        self.labelfan.setSizePolicy(sizePolicy)
        self.labelfan.setMaximumSize(QtCore.QSize(29, 17))
        self.labelfan.setObjectName("labelfan")
        self.gridLayout.addWidget(self.labelfan, 0, 0, 1, 1)
        self.fanon = QtWidgets.QPushButton(self.widget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.fanon.sizePolicy().hasHeightForWidth())
        self.fanon.setSizePolicy(sizePolicy)
        self.fanon.setMaximumSize(QtCore.QSize(80, 25))
        self.fanon.setObjectName("fanon")
        self.gridLayout.addWidget(self.fanon, 0, 1, 1, 1)
        self.fanoff = QtWidgets.QPushButton(self.widget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.fanoff.sizePolicy().hasHeightForWidth())
        self.fanoff.setSizePolicy(sizePolicy)
        self.fanoff.setMaximumSize(QtCore.QSize(80, 25))
        self.fanoff.setObjectName("fanoff")
        self.gridLayout.addWidget(self.fanoff, 0, 2, 1, 1)
        self.labellight = QtWidgets.QLabel(self.widget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.labellight.sizePolicy().hasHeightForWidth())
        self.labellight.setSizePolicy(sizePolicy)
        self.labellight.setMaximumSize(QtCore.QSize(42, 17))
        self.labellight.setObjectName("labellight")
        self.gridLayout.addWidget(self.labellight, 1, 0, 1, 1)
        self.lighton = QtWidgets.QPushButton(self.widget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lighton.sizePolicy().hasHeightForWidth())
        self.lighton.setSizePolicy(sizePolicy)
        self.lighton.setMaximumSize(QtCore.QSize(80, 25))
        self.lighton.setObjectName("lighton")
        self.gridLayout.addWidget(self.lighton, 1, 1, 1, 1)
        self.lightoff = QtWidgets.QPushButton(self.widget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lightoff.sizePolicy().hasHeightForWidth())
        self.lightoff.setSizePolicy(sizePolicy)
        self.lightoff.setMaximumSize(QtCore.QSize(80, 25))
        self.lightoff.setObjectName("lightoff")
        self.gridLayout.addWidget(self.lightoff, 1, 2, 1, 1)
        self.labelextra = QtWidgets.QLabel(self.widget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.labelextra.sizePolicy().hasHeightForWidth())
        self.labelextra.setSizePolicy(sizePolicy)
        self.labelextra.setMaximumSize(QtCore.QSize(47, 17))
        self.labelextra.setObjectName("labelextra")
        self.gridLayout.addWidget(self.labelextra, 2, 0, 1, 1)
        self.extraon = QtWidgets.QPushButton(self.widget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.extraon.sizePolicy().hasHeightForWidth())
        self.extraon.setSizePolicy(sizePolicy)
        self.extraon.setMaximumSize(QtCore.QSize(80, 25))
        self.extraon.setObjectName("extraon")
        self.gridLayout.addWidget(self.extraon, 2, 1, 1, 1)
        self.extraoff = QtWidgets.QPushButton(self.widget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.extraoff.sizePolicy().hasHeightForWidth())
        self.extraoff.setSizePolicy(sizePolicy)
        self.extraoff.setMaximumSize(QtCore.QSize(80, 25))
        self.extraoff.setObjectName("extraoff")
        self.gridLayout.addWidget(self.extraoff, 2, 2, 1, 1)

        self.retranslateUi(fan_2)
        self.fanon.clicked.connect(self.fanonclick)
        self.fanoff.clicked.connect(self.fanoffclick)
        self.lighton.clicked.connect(self.lightonclick)
        self.lightoff.clicked.connect(self.lightoffclick)
        self.extraon.clicked.connect(self.extraonclick)
        self.extraoff.clicked.connect(self.extraoffclick)
        QtCore.QMetaObject.connectSlotsByName(fan_2)
        api_key ="91a27806-4174-4001-9d24-b42a37a3a513"
        device_id  = "BOLT5778783"
        mybolt = Bolt(api_key, device_id)
        response=mybolt.serialBegin(9600)
    def extraonclick(self):
        api_key ="91a27806-4174-4001-9d24-b42a37a3a513"
        device_id  = "BOLT5778783"
        mybolt = Bolt(api_key, device_id)
        response=mybolt.serialWrite("5")
        print(response)
    def extraoffclick(self):
        api_key ="91a27806-4174-4001-9d24-b42a37a3a513"
        device_id  = "BOLT5778783"
        mybolt = Bolt(api_key, device_id)
        response=mybolt.serialWrite("6")
        print(response)
    def lightonclick(self): 
        api_key ="91a27806-4174-4001-9d24-b42a37a3a513"
        device_id  = "BOLT5778783"
        mybolt = Bolt(api_key, device_id)
        response=mybolt.serialWrite("1")
        print(response)
    def lightoffclick(self):
        api_key ="91a27806-4174-4001-9d24-b42a37a3a513"
        device_id  = "BOLT5778783"
        mybolt = Bolt(api_key, device_id)
        response=mybolt.serialWrite("2")
        print(response)
    def fanonclick(self):
        api_key ="91a27806-4174-4001-9d24-b42a37a3a513"
        device_id  = "BOLT5778783"
        mybolt = Bolt(api_key, device_id)
        response=mybolt.serialWrite("3")
        print(response)
    def fanoffclick(self):
        api_key ="91a27806-4174-4001-9d24-b42a37a3a513"
        device_id  = "BOLT5778783"
        mybolt = Bolt(api_key, device_id)
        response=mybolt.serialWrite("4")
        print(response)

    def retranslateUi(self, fan_2):
        _translate = QtCore.QCoreApplication.translate
        fan_2.setWindowTitle(_translate("fan_2", "Form"))
        self.labelfan.setText(_translate("fan_2", "LIGHT"))
        self.fanon.setText(_translate("fan_2", "OFF"))
        self.fanoff.setText(_translate("fan_2", "ON"))
        self.labellight.setText(_translate("fan_2", "FAN"))
        self.lighton.setText(_translate("fan_2", "ON"))
        self.lightoff.setText(_translate("fan_2", "OFF"))
        self.labelextra.setText(_translate("fan_2", "EXTRA"))
        self.extraon.setText(_translate("fan_2", "ON"))
        self.extraoff.setText(_translate("fan_2", "OFF"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    fan_2 = QtWidgets.QWidget()
    ui = Ui_fan_2()
    ui.setupUi(fan_2)
    fan_2.show()
    sys.exit(app.exec_())

Credits

Chpritam Patro
3 projects • 9 followers
Contact

Comments

Please log in or sign up to comment.