Nedzib Sastoque Rangel
Published © GPL3+

Smart Home for a Madagascar Hissing Cockroach

A simple smart home for an exotic pet using NXP Rapid IoT and Raspberry Pi 3.

IntermediateFull instructions provided6 hours794

Things used in this project

Hardware components

Rapid IoT Prototyping Kit
NXP Rapid IoT Prototyping Kit
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Relay (generic)
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
fan
×1

Software apps and online services

Nxp Rapid IoT

Story

Read more

Schematics

Relay

Fan

Code

Python Code

Python
for the raspberry, turn the heater and fan and show in a window the sensors and other parameters
from tkinter import *
from tkinter import *
from tkinter.messagebox import showinfo
from tkinter.commondialog import Dialog
from tkinter.filedialog import *
import serial
import struct
from gpiozero import LED
from time import sleep


relay = LED(14)
fan = LED(15)

e = serial.Serial("/dev/ttyACM0", 9600)
print("Conected")
root= Tk()

def salir():
    e.close()
    root.destroy()

root.configure(bg="white")

root.title('Cockroach')
salir=Button(root,text="Exit",width=10,height=1,command=salir)
salir.pack(side=BOTTOM)

master=LabelFrame(root,text="Cockroach",font=('arial',14,'bold'),width=1000,bg='white')
master.pack(side=TOP)
entradas= LabelFrame(master,text="Inputs",font=('arial',12),bg='white')
entradas.pack(side=LEFT)
lbl1=Message(entradas,text="Temperature-------------------",width=300,bg='white')
lbl1.pack()
temp = Entry(entradas,width=7,bg='white')
temp.pack()
lbl1=Message(entradas,text="Humidity------------------------",width=300,bg='white')
lbl1.pack()
hum = Entry(entradas,width=7,bg='white')
hum.pack()
lbl1=Message(entradas,text="Light-----------------------------",width=300,bg='white')
lbl1.pack()
lig = Entry(entradas,width=7,bg='white')
lig.pack()
lbl1=Message(entradas,text="Air Quality------------------------",width=300,bg='white')
lbl1.pack()
air = Entry(entradas,width=7,bg='white')
air.pack()
barra=Frame(master,bg='white')
barra.pack(side= BOTTOM)
lbls=Message(barra,bg='white',text=" ")
lbls.pack()

salidas= LabelFrame(master,text="Outputs",font=('arial',12),bg='white')
salidas.pack(side=LEFT)
lbl2=Message(salidas, text="Fan------------------",width=300,bg='white')
lbl2.pack(side=TOP)
ven = Entry(salidas,width=15,bg='white')
ven.pack(side=TOP)
lbl3=Message(salidas, text="Heater---------------",width=300,bg='white')
lbl3.pack(side=TOP)
res = Entry(salidas,width=15,bg='white')
res.pack(side=TOP)

recom= LabelFrame(master,text="Recommendations",font=('arial',12),bg='white')
recom.pack(side=LEFT)
lbl2=Message(recom, text="Light-----------------",width=300,bg='white')
lbl2.pack(side=TOP)
rlg = Entry(recom,width=15,bg='white')
rlg.pack(side=TOP)
lbl3=Message(recom, text="Humidity--------------",width=300,bg='white')
lbl3.pack(side=TOP)
rum = Entry(recom,width=15,bg='white')
rum.pack(side=TOP)
lbl3=Message(recom, text="Air Quality-----------",width=300,bg='white')
lbl3.pack(side=TOP)
rai = Entry(recom,width=15,bg='white')
rai.pack(side=TOP)

def readSerial():
     a=e.read()
     if a==b'T':
         temp.delete(0,11)
         ven.delete(0,11)
         a=e.readline()
         #print(a)
         temp.insert(1, a[2:4])
         c=float(temp.get())
         #print(c)
         if c<24:
             res.delete(0,11)
             res.insert(1, "On")
             ven.delete(0,11)
             ven.insert(1, "On")
             fan.on()
             relay.on()
         if c>=24:
             res.delete(0,11)
             res.insert(1, "Off")
             ven.delete(0,11)
             ven.insert(1, "Off")
             fan.off()
             relay.off()
         temp.insert(4," C°")
     if a==b'H':
         hum.delete(0,11)
         a=e.readline()
      #  print(a)
         hum.insert(1, a[2:4])
         c=float(hum.get())
         #print(c)
         if c<=50:
             rum.delete(0,30)
             rum.insert(1, "Put fresh food")
         if c>50:
             rum.delete(0,30)
             rum.insert(1, "Food are good")
         hum.insert(4," %")
     if a==b'L':
         lig.delete(0,11)
         a=e.readline()
         #print(a)
         lig.insert(1, a[2:4])
         c=float(lig.get())
         #print(c)
         if c<=10:
             rlg.delete(0,30)
             rlg.insert(1, "Lights Cool")
         if c>10:
             rlg.delete(0,30)
             rlg.insert(1, "A lot of light")
         lig.insert(4," Lx")
     if a==b'A':
         air.delete(0,11)
         a=e.readline()
       #  print(a)
         air.insert(1, a[2:3])
         c=float(air.get())
         #print(c)
         if c<=60:
             rai.delete(0,30)
             rai.insert(1, "House clean")
         if c>60:
             rai.delete(0,30)
             rai.insert(1, "Clean the house")
         air.insert(4," ppb")

     root.after(10, readSerial)
root.after(100, readSerial)
root.update()
#root.minsize(root.winfo_width(), root.winfo_height())
#root.maxsize(root.winfo_width(), root.winfo_height())
root.mainloop()

Credits

Nedzib Sastoque Rangel

Nedzib Sastoque Rangel

6 projects • 13 followers
#UDistrital Electronics student, I love programming, domotic, create prototypes and learn new things

Comments