Site Tools


pub:photosister

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
pub:photosister [2019/01/14 14:47]
Adeept created
pub:photosister [2019/01/15 10:06] (current)
Adeept ↷ Page moved from pub:photosister:photosister to pub:photosister
Line 16: Line 16:
 substantially differently to photons within certain wavelength bands.\\ substantially differently to photons within certain wavelength bands.\\
  
-图片+{{:​pub:​photosister:​photoresistorzzz.jpg?​400|}}\\
  
  
Line 23: Line 23:
 |    -    |    GND    | |    -    |    GND    |
  
-原理图+{{:​pub:​photosister:​7.png?​600|}}\\
  
  
Line 29: Line 29:
 ===== Microbit ===== ===== Microbit =====
  
 +Components\\
 +1 * microbit\\
 +1 * microbit expansion board\\
 +1 * USB cable\\
 +1 * Photosister module\\
 +- Several Jumper wires\\
  
 +connection diagram:\\
  
 +{{:​pub:​photosister:​photosister_module_bbm.png?​600|}}\\
  
 +Code:
 +makecode:
 +
 +{{:​pub:​photosister:​2019-01-14_181945.png?​600|}}\\
 +
 +MU python:
 +<code 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))
 +</​code>​
 +
 +Click “Download” and download the code onto the micro:bit.
 +The value of the photoresistor can be seen on the matrix LEDs.\\
 +Effect Picture:\\
 +
 +{{:​pub:​photosister:​1m.jpg?​600|}}\\
  
 ---- ----
 ===== Arduino ===== ===== Arduino =====
  
 +Components\\
 +- 1 * Adeept Arduino UNO R3 Board\\
 +- 1 * Photoresistor Module\\
 +- 1 * USB Cable\\
 +- 1 * 3-Pin Wires\\
  
 +Step 1: Build the circuit\\
 +
 +{{:​pub:​photosister:​aphotoresistormodule.png?​600|}}\\
 +
 +
 +|    Adeept UNO R3 Board    |    Photoresistor Module ​   |
 +|    A0    |    A    |
 +|    5V    |    +    |
 +|    GND    |    -    |
 +
 +
 +Step 2: Code:\\
 +C code:\\
 +<code c>
 +/​***********************************************************
 +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
 +}
 +
 +
 +
 +</​code>​
 +
 +Step 3: Compile and download the sketch to the UNO R3 board.\\
 +
 +{{:​pub:​photosister:​1a.png?​600|}}\\
 +{{:​pub:​photosister:​2a.png?​600|}}\\
 +
 +
 +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.\\
 +
 +{{:​pub:​photosister:​photoresistormodulea.jpg?​600|}}\\
  
  
Line 43: Line 136:
 ===== Raspberry pi ===== ===== 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\\
 +
 +{{:​pub:​photosister:​28r.jpg?​600|}}\\
 +
 +C code:\\
 +<code c>
 +/*
 + * 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;
 +}
 +
 +
 +</​code>​
 +
 +Python code:\\
 +<code python>
 +#​!/​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 !'
  
 +</​code>​
  
 +For C language users:\\
 +\\
 +Step 2: Edit and save the code with vim or nano.\\
 +<code c>
 +(code path: /​home/​Adeept_Sensor_Kit_for_RPi_C_Code/​28_photoresistor/​photoresistor.c)
 +</​code>​
 +Step 3: Compile\\
 +<code >
 +$ sudo gcc photoresistor.c -o photoresistor -lwiringPi
 +</​code>​
 +Step 4: Run\\
 +<code c>
 +$ sudo ./​photoresistor
 +</​code>​
 +For Python users:\\
 +\\
 +Step 2: Edit and save the code with vim or nano.\\
 +<code c>
 +(code path: /​home/​Adeept_Sensor_Kit_for_RPi_Python_Code/​28_photoresistor.py)
 +</​code>​
 +Step 3: Run\\
 +<code c>
 +$ sudo python 28_photoresistor.py
 +</​code>​
 +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.\\
  
 +{{:​pub:​photosister:​2r8.jpg?​600|}}\\
  
  
  
 +Link for code download:http://​www.adeept.com/​learn/​ Download the kit information as needed.//\\
 +Video link:http://​www.adeept.com/​video/​ \\
  
  
pub/photosister.1547448423.txt.gz · Last modified: 2019/01/14 14:47 by Adeept