Home » KY-018 Photo resistor module and Raspberry Pi example

KY-018 Photo resistor module and Raspberry Pi example

by shedboy71

In this example we take a look at the KY-018 Photo resistor module and connect this to a Raspberry Pi using an ADC add on board

A photoresistor (or light-dependent resistor, LDR, or photo-conductive cell) is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity.

A photoresistor can be applied in light-sensitive detector circuits, and light-activated and dark-activated switching circuits.

A photoresistor is made of a high resistance semiconductor. In the dark, a photoresistor can have a resistance as high as several megohms (MΩ), while in the light, a photoresistor can have a resistance as low as a few hundred ohms. If incident light on a photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band.

The resulting free electrons (and their hole partners) conduct electricity, thereby lowering resistance. The resistance range and sensitivity of a photoresistor can substantially differ among dissimilar devices. Moreover, unique photoresistors may react substantially differently to photons within certain wavelength bands.

Parts List

Name link
Raspberry Pi 4 Aliexpress product link

Amazon. com link

Ebay search

37 sensor kit AliExpress Product link

Amazon link

ebay link

connecting wire Aliexpress product link

Amazon.com link

Ebay link

Analog zero https://rasp.io/analogzero/

 

Layout

Being a device that outputs an analog value we need to connect this to an ADC converter – in this case we use a MCP3008 in the form of an Analog Zero module. The LDR is easy to connect to the Analog Zero

pi and ky-018 layout

pi and ky-018 layout

Code

Save this example as ldr.py

import RPi.GPIO as GPIO
import time
from gpiozero import MCP3008

led = 7

GPIO.setmode(GPIO.BOARD)
GPIO.setup(led,GPIO.OUT)
GPIO.output(led,False)

try: 
	while True:
		adc = MCP3008(channel=0)
		voltage = 3.3 * adc.value
		print("Measured voltage is ",voltage);
		time.sleep(0.2)

except KeyboardInterrupt:
    GPIO.cleanup()

Copy this to your raspberry pi and open up a terminal and type in

sudo python ldr.py

 

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More