Práctica 01:
Fotoresistor

Componentes

  • Fotoresistor
  • Condensador de 1μF
  • Zumbador activo (Una sola frecuencia)
  • Opcional: MCP3008

Fotoresistor

Es un tipo especial de resistencia

Cuando incide la luz la resistencia es BAJA y cuando hay oscuridad la resistencia es muy ALTA

Condensador (1μF)

Los condensadores son componentes eléctricos que almacenan carga

Código Python


#!/usr/bin/env python3

from gpiozero import LightSensor

ldr = LightSensor(4)

while True:
    print(ldr.value)
	

Buzzer (activo)

Cuando se aplica un voltaje vibra con una frecuencia determinada

Código Python para probar el buzzer activo


#!/usr/bin/env python3

from gpiozero import Buzzer
from time import sleep

buzzer = Buzzer(20)

while True:
    buzzer.on()
    sleep(1)
    buzzer.off()
    sleep(1)
    # También existe buzzer.beep()
	

Código Python para todo el circuito


#!/usr/bin/env python3

from gpiozero import LightSensor, Buzzer
from time import sleep

ldr = LightSensor(4)
buzzer = Buzzer(20)

while True:
    sleep(0.1)
    if ldr.value < 0.5:  # Medir límites y ajustar valor
        buzzer.on()
    else:
        buzzer.off()
	

Opcional

Los pins GPIO de la Raspberry Pi son digitales. Entrada o salida a 0 (LOW) ó 1 (HIGH).

Mediante un chip ADC (conversor analógico digital) se pueden leer valores analógicos (temperatura, humedad, potenciómetros)

https://www.raspberrypi.org/learning/physical-computing-with-python/analogue/