Sir I want to on/off fan and bulb based on reading of dht11 sensor reading.
Condition temperature<37° on bulb , temp > 37°off bulb
Humidity <58 on fan , humidity>62 off fan .,
Based on relay
Sir would this will with blynkapp
Please show us your code before we can help.
Sir Master, don’t forgettings to format code for me also
```cpp
Put your Damn code here
```
Becos looks lajk diz resolt
Put your Damn code here
import RPi.GPIO as GPIO
import time
import sys
from time import sleep
def bin2dec(string_num):
return str(int(string_num, 2))
data = []
effectiveData = []
bits_min=999;
bits_max=0;
HumidityBit = “”
TemperatureBit = “”
crc = “”
crc_OK = False;
Humidity = 0
Temperature = 0
pin=4
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.setup(25, GPIO.OUT)
def pullData():
#{{{ Pull data from GPIO
global data
global effectiveData
global pin
data = []
effectiveData = []
GPIO.setup(pin,GPIO.OUT)
GPIO.output(pin,GPIO.HIGH)
time.sleep(0.025)
GPIO.output(pin,GPIO.LOW)
time.sleep(0.14)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
for i in range(0,1000):
data.append(GPIO.input(pin))
"""
for i in range(0,len(data)):
print "%d" % data[i],
print
"""
#}}}
def analyzeData():
#{{{ Analyze data
#{{{ Add HI (2x8)x3 bits to array
seek=0;
bits_min=9999;
bits_max=0;
global HumidityBit
global TemperatureBit
global crc
global Humidity
global Temperature
HumidityBit = ""
TemperatureBit = ""
crc = ""
"""
Snip off the first bit - it simply says "Hello, I got your request, will send you temperature and humidity information along with checksum shortly"
"""
while(seek < len(data) and data[seek] == 0):
seek+=1;
while(seek < len(data) and data[seek] == 1):
seek+=1;
"""
Extract all HIGH bits' blocks. Add each block as separate item in data[]
"""
for i in range(0, 40):
buffer = "";
while(seek < len(data) and data[seek] == 0):
seek+=1;
while(seek < len(data) and data[seek] == 1):
seek+=1;
buffer += "1";
"""
Find the longest and the shortest block of HIGHs. Average of those two will distinct whether block represents '0' (shorter than avg) or '1' (longer than avg)
"""
if (len(buffer) < bits_min):
bits_min = len(buffer)
if (len(buffer) > bits_max):
bits_max = len(buffer)
effectiveData.append(buffer);
#print "%s " % buffer
#}}}
#{{{ Make effectiveData smaller
"""
Replace blocks of HIs with either '1' or '0' depending on block length
"""
for i in range(0, len(effectiveData)):
if (len(effectiveData[i]) < ((bits_max + bits_min)/2)):
effectiveData[i] = "0";
else:
effectiveData[i] = "1";
#print "%s " % effectiveData[i],
#}}}
#{{{ Extract Humidity and Temperature values
for i in range(0, 8):
HumidityBit += str(effectiveData[i]);
for i in range(16, 24):
TemperatureBit += str(effectiveData[i]);
for i in range(32, 40):
crc += str(effectiveData[i]);
Humidity = bin2dec(HumidityBit)
Temperature = bin2dec(TemperatureBit)
#print "HumidityBit=%s, TemperatureBit=%s, crc=%s" % (HumidityBit, TemperatureBit, crc)
#}}}
#}}}
#{{{ Check CRC
def isDataValid():
global Humidity
global Temperature
global crc
#print "isDataValid(): H=%d, T=%d, crc=%d"% (int(Humidity), int(Temperature), int(bin2dec(crc)))
if int(Humidity) + int(Temperature) == int(bin2dec(crc)):
return True;
else:
return False;
#}}}
#{{{ Print data
def printData():
global Humidity
global Temperature
print "H: "+Humidity
print "T: "+Temperature
#}}}
while (Temperature > 37 ):
# Turn all relays OFF
GPIO.output(18, GPIO.LOW)
while (Temperature < 37 ):
# Turn all relays ON
GPIO.output(18, GPIO.HIGH)
while (Humidity > 68 ):
# Turn all relays OFF
GPIO.output(24, GPIO.LOW)
while (Humidity < 68 ):
# Turn all relays ON
GPIO.output(24, GPIO.HIGH)
while(Humidity == Humidity):
GPIO.output(25, GPIO.HIGH)
# Sleep for 5 seconds
sleep(300)
while(Humidity == Humidity):
GPIO.output(25, GPIO.LOW)
# Sleep for 5 seconds
sleep(3600)
#{{{ Main loop
while (not crc_OK):
pullData();
analyzeData();
if (isDataValid()):
crc_OK=True;
print “\r”,
printData();
else:
sys.stderr.write(".")
time.sleep(2);
#}}}
developed with raspberry pi 3 ,help can u help with this sir
sir i have pasted the code sir
sir i have pasted the code sir,can u make it work with blynk app
Damn dude, go edit your post and FORMAT YOUR CODE!
We cant help you until you do.
Use this example, copy it, edit your post, paste in the example, and put all your code in place of CODE
```cpp
CODE
```
Have you tried looking at examples in the.sketch builder? Try those before you ask for help and you will learn a lot, a lot faster. And please do format your code while pasting.