ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Dispositivos y sensores en IoT


Enviado por   •  31 de Octubre de 2022  •  Trabajo  •  520 Palabras (3 Páginas)  •  65 Visitas

Página 1 de 3

# External module imports

import RPi.GPIO as GPIO

import time

from sht21 import SHT21

# Pin Definitons:

buttontemp = 7

buttonhum = 8

tempLedpin = 15

humLedpin = 17

prevButtempState = True

prevButhumState = True

buttempState = True

buthumState = True

print("Setting Broadcom Mode")

# Pin Setup:

GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme

GPIO.setup(buttontemp, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Button pin set

time.sleep(1)

GPIO.setup(buttonhum, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Button pin set

time.sleep(1)

GPIO.setup(tempLedpin, GPIO.OUT) # LED pin set as output

GPIO.setup(humLedpin, GPIO.OUT) # LED pin set as output

# Initial state for LEDs:

GPIO.output(tempLedpin, GPIO.LOW)

GPIO.output(humLedpin, GPIO.LOW)

sht = SHT21(1)

#print initial settings

buttempState = GPIO.input(buttontemp);

print "Initial state for Temperature control is ", 'pressed' if buttempState else 'released';

buthumState = GPIO.input(buttonhum);

print "Initial state for Humidity control is ", 'pressed' if buthumState else 'released';

print("Here we go! Press CTRL+C to exit")

try:

while 1:

buttempState = GPIO.input(buttontemp);

if prevButtempState != buttempState:

print "Temperature control is ", 'activated' if buttempState else 'disabled';

# save last state

prevButtempState = buttempState;

time.sleep(0.1);

buthumState = GPIO.input(buttonhum);

if prevButhumState != buthumState:

print "Humidity control is ", 'activated' if buthumState else 'disabled';

# save last state

prevButhumState = buthumState;

time.sleep(0.1);

alarmtemp = False

alarmhum = False

if buttempState:

if sht.read_temperature() > 45: #excessive heat

alarmtemp = True

if buthumState:

if sht.read_humidity() > 60: #abnormal humidity

alarmhum = True

if sht.read_humidity() < 25: #abnormal humidity

alarmhum = True

if alarmtemp:

GPIO.output(tempLedpin, GPIO.HIGH)

else:

GPIO.output(tempLedpin, GPIO.LOW)

if alarmhum:

GPIO.output(humLedpin,

...

Descargar como (para miembros actualizados) txt (2 Kb) pdf (38 Kb) docx (8 Kb)
Leer 2 páginas más »
Disponible sólo en Clubensayos.com