zoukankan      html  css  js  c++  java
  • Arduino 各种模块篇 光敏感应模块 light sensor

    It looks like this one:

    This one isn't a digital light sensor, so it's very simple.

    http://www.seeedstudio.com/wiki/Grove_-_Light_Sensor

    File:Twig-Light.jpg

    With seeeduino and it's grove shield, this would be very easy to use.

    Now we can do a little experiment:

    using a LED and a light sensor.

    condition 1) If the sensor detects light, the LED will no longer be on. 2) If the sensor detects no light, the LED will be on.

    Here is the codes and demo.

    File:Light Sensor Connector.jpg.jpg

    codes:

    /*
    /* Grove - Light Sensor demo v1.0
    * 
    * signal wire to A0.
    * By: http://www.seeedstudio.com
    */
    #include <math.h>
    const int ledPin=12;                 //Connect the LED Grove module to Pin12, Digital 12
    const int thresholdvalue=10;         //The treshold for which the LED should turn on. 
    float Rsensor; //Resistance of sensor in K
    void setup() {
      Serial.begin(9600);                //Start the Serial connection
      pinMode(ledPin,OUTPUT);            //Set the LED on Digital 12 as an OUTPUT
    }
    void loop() {
      int sensorValue = analogRead(0); 
      Rsensor=(float)(1023-sensorValue)*10/sensorValue;  // using the sensor's analog voltage to caculate the accurate resistance value of it.
      if(Rsensor>thresholdvalue)              // thresholdvalue = 10 which means if the Rsensor is more than 10K oms (ligth sensor been covered)
      {
        digitalWrite(ledPin,HIGH);            // light sensor covered ==> light on the LED
      }
      else                                    // light sensor detects light
      {
      digitalWrite(ledPin,LOW);               // light off the LED
      }
      Serial.println("the analog read data is ");
      Serial.println(sensorValue);
      Serial.println("the sensor resistance is ");
      Serial.println(Rsensor,DEC);//show the ligth intensity on the serial monitor;
      delay(1000);
    }
  • 相关阅读:
    BZOJ 2260: 商店购物
    BZOJ 4349: 最小树形图
    BZOJ 1115: [POI2009]石子游戏Kam
    BZOJ 1413: [ZJOI2009]取石子游戏
    BZOJ 2275: [Coci2010]HRPA
    BZOJ 4730: Alice和Bob又在玩游戏
    BZOJ 1455: 罗马游戏
    BZOJ 3509: [CodeChef] COUNTARI
    BZOJ 1513: [POI2006]Tet-Tetris 3D
    #大数加减乘除#校赛D题solve
  • 原文地址:https://www.cnblogs.com/spaceship9/p/3372184.html
Copyright © 2011-2022 走看看