Site Tools


Sidebar

Content

pub:photosister

Photosister

what's Photosister
A photoresistor is a light-controlled variable resistor. The resistance of a photoresistor decreases with the increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in lightsensitive detector circuits. A photoresistor is made of a high resistance semiconductor. In the dark, a photoresistor can have a resistance as high as a few 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.


A Analog output
+ 3.3V
- GND



Microbit

Components
1 * microbit
1 * microbit expansion board
1 * USB cable
1 * Photosister module
- Several Jumper wires

connection diagram:


Code: makecode:


MU python:

#-----------------------------------------------------------
# File name   : Photoresistive.py
# Description : Read the resistance of the photosensitive resistor.
# Author      : jason
# E-mail      : jason@adeept.com
# Website     : www.adeept.com
# Date        : 2019/01/14
#-----------------------------------------------------------
from microbit import *
 
while True:
    reading = pin0.read_analog()
    number = int(reading / 50)
    display.show(str(number))

Click “Download” and download the code onto the micro:bit. The value of the photoresistor can be seen on the matrix LEDs.
Effect Picture:



Arduino

Components
- 1 * Adeept Arduino UNO R3 Board
- 1 * Photoresistor Module
- 1 * USB Cable
- 1 * 3-Pin Wires

Step 1: Build the circuit


Adeept UNO R3 Board Photoresistor Module
A0 A
5V +
GND -

Step 2: Code:
C code:

/***********************************************************
File name: _07_PhotoresistorModule.ino
Description: We measure the light intensity of information with
             photosensitive resistance, and displayed in the 
             serial monitor. 
Website: www.adeept.com
E-mail: support@adeept.com
Author: Tom
Date: 2019/01/14 
***********************************************************/
int photoresistorPin = 0;          // photoresistor  connected to analog pin 0
void setup() 
{                
  pinMode(photoresistorPin, INPUT);//Set analog 0 port mode, the INPUT for the input
  Serial.begin(9600);             //opens serial port, sets data rate to 9600 bps
}
void loop() 
{
 Serial.println(analogRead(0));   //send data to the serial monitor
 delay(50);                        //delay 0.05 s
}

Step 3: Compile and download the sketch to the UNO R3 board.



Open the Serial Monitor in Arduino IDE. Change the intensity of light shone on the photoresistor module and you can see the value displayed on the window changes. Basically, when you shine the stronger light on the module, the value will become greater; when the light dims slowly on it, the value decreases.



Raspberry pi

Components
- 1 * Raspberry Pi
- 1 * GPIO Extension Board
- 1 * 40-Pin GPIO Cable
- 1 * Breadboard
- 1 * ADC0832 Module
- 1 * Photoresistor Module
- 2 * 3-Pin Wires
- 1 * 5-Pin Wires

Step 1: Build the circuit


C code:

/*
 * File name   : photoresistor.c
 * Description : .
 * Website     : www.adeept.com
 * E-mail      : support@adeept.com
 * Author      : Jason
 * Date        : 2019/01/14
 */
#include <wiringPi.h>
#include <stdio.h>
 
typedef unsigned char uchar;
typedef unsigned int  uint;
 
#define     ADC_CS    0
#define     ADC_DIO   1
#define     ADC_CLK   2
 
uchar get_ADC_Result(void)
{
	//10:CH0
	//11:CH1
	uchar i;
	uchar dat1=0, dat2=0;
 
	digitalWrite(ADC_CS, 0);
 
	digitalWrite(ADC_CLK,0);
	digitalWrite(ADC_DIO,1);	delayMicroseconds(2);
	digitalWrite(ADC_CLK,1);	delayMicroseconds(2);
	digitalWrite(ADC_CLK,0);
 
	digitalWrite(ADC_DIO,1);    delayMicroseconds(2); //CH0 10
	digitalWrite(ADC_CLK,1);	delayMicroseconds(2);
	digitalWrite(ADC_CLK,0);
 
	digitalWrite(ADC_DIO,0);	delayMicroseconds(2); //CH0 0
 
	digitalWrite(ADC_CLK,1);	
	digitalWrite(ADC_DIO,1);    delayMicroseconds(2);
	digitalWrite(ADC_CLK,0);	
	digitalWrite(ADC_DIO,1);    delayMicroseconds(2);
 
	for(i=0;i<8;i++)
	{
		digitalWrite(ADC_CLK,1);	delayMicroseconds(2);
		digitalWrite(ADC_CLK,0);    delayMicroseconds(2);
 
		pinMode(ADC_DIO, INPUT);
		dat1=dat1<<1 | digitalRead(ADC_DIO);
	}
 
	for(i=0;i<8;i++)
	{
		dat2 = dat2 | ((uchar)(digitalRead(ADC_DIO))<<i);
		digitalWrite(ADC_CLK,1); 	delayMicroseconds(2);
		digitalWrite(ADC_CLK,0);    delayMicroseconds(2);
	}
 
	digitalWrite(ADC_CS,1);
 
	pinMode(ADC_DIO, OUTPUT);
 
	return(dat1==dat2) ? dat1 : 0;
}
 
int main(void)
{
	uchar adcVal;
 
	if(wiringPiSetup() == -1){
		printf("setup wiringPi failed !");
		return 1; 
	}
 
	pinMode(ADC_CS,  OUTPUT);
	pinMode(ADC_CLK, OUTPUT);
 
	while(1){
		pinMode(ADC_DIO, OUTPUT);
		adcVal = get_ADC_Result();
		printf("adcval : %d\n",adcVal-80);
 
		delay(400);
	}
 
	return 0;
}

Python code:

#!/usr/bin/env python
import ADC0832
import time
 
def init():
	ADC0832.setup()
 
def loop():
	while True:
		res = ADC0832.getResult() - 80
		if res < 0:
			res = 0
		if res > 100:
			res = 100
		print 'res = %d' % res
		time.sleep(0.2)
 
if __name__ == '__main__':
	init()
	try:
		loop()
	except KeyboardInterrupt: 
		ADC0832.destroy()
		print 'The end !'

For C language users:

Step 2: Edit and save the code with vim or nano.

(code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/28_photoresistor/photoresistor.c)

Step 3: Compile

$ sudo gcc photoresistor.c -o photoresistor -lwiringPi

Step 4: Run

$ sudo ./photoresistor

For Python users:

Step 2: Edit and save the code with vim or nano.

(code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/28_photoresistor.py)

Step 3: Run

$ sudo python 28_photoresistor.py

Now, when you try to cover to the photoresistor, you will find that the value displayed on the screen decreasing. On the contrary, when you shine the photoresistor with strong light, the value displayed will increase.


Link for code download:http://www.adeept.com/learn/ Download the kit information as needed.
Video link:http://www.adeept.com/video/

pub/photosister.txt · Last modified: 2019/01/15 10:06 by Adeept