搜索
bottom↓
回复: 9

使用发光二极管作为光传感器(例)

[复制链接]

出0入0汤圆

发表于 2016-5-9 09:40:49 | 显示全部楼层 |阅读模式
本帖最后由 sunplus 于 2016-5-9 09:46 编辑

自己使用数码管做了一个数字时钟,参考了坛友lcw_swust的代码:
代码中提到数码管可以作为类似光敏元件
发光二极管不仅可以作为发光元件,而且还可以作为光敏二极管检测光强度。
网上的例子并不多
感谢坛友lcw_swust
http://www.amobbs.com/forum.php?mod=viewthread&tid=5480294
以下是 网上的实现方法:
自己用了下面的例子,已经得到验证。
LEDs are commonly used as lights, but then can also be used as photodiodes to detect light. This example circuit uses a single LED to sample the ambient light level and then glow at an appropriate brightness. It is tragically flawed by a slow refresh rate in the dark, but it shows how to sense.

//
// This example shows one way of using an LED as a light sensor.
// You will need to wire up your components as such:
//
//           + digital2
//           |
//           <
//           > 100 ohm resistor
//           <
//           |
//           |
//         -----
//          / \  LED, maybe a 5mm, clear plastic is good
//         -----
//           |
//           |
//           + digital3
//
// What we are going to do is apply a positive voltage at digital2 and
// a low voltage at digital3. This is backwards for the LED, current will
// not flow and light will not come out, but we will charge up the
// capacitance of the LED junction and the Arduino pin.
//
// Then we are going to disconnect the output drivers from digital2 and
// count how long it takes the stored charge to bleed off through the
// the LED. The brighter the light, the faster it will bleed away to
// digital3.
//
// Then just to be perverse we will display the brightness back on the
// same LED by turning it on for a millisecond. This happens more often
// with brighter lighting, so the LED is dim in a dim room and brighter
// in a bright room. Quite nice.
//
// (Though a nice idea, this implementation is flawed because the refresh
// rate gets too long in the dark and it flickers disturbingly.)
//
#define LED_N_SIDE 2
#define LED_P_SIDE 3

void setup()
{}

void loop()
{
  unsigned int j;

  // Apply reverse voltage, charge up the pin and led capacitance
  pinMode(LED_N_SIDE,OUTPUT);
  pinMode(LED_P_SIDE,OUTPUT);
  digitalWrite(LED_N_SIDE,HIGH);
  digitalWrite(LED_P_SIDE,LOW);

  // Isolate the pin 2 end of the diode
  pinMode(LED_N_SIDE,INPUT);
  digitalWrite(LED_N_SIDE,LOW);  // turn off internal pull-up resistor

  // Count how long it takes the diode to bleed back down to a logic zero
  for ( j = 0; j < 30000; j++) {
    if ( digitalRead(LED_N_SIDE)==0) break;
  }
  // You could use 'j' for something useful, but here we are just using the
  // delay of the counting.  In the dark it counts higher and takes longer,
  // increasing the portion of the loop where the LED is off compared to
  // the 1000 microseconds where we turn it on.

  // Turn the light on for 1000 microseconds
  digitalWrite(LED_P_SIDE,HIGH);
  digitalWrite(LED_N_SIDE,LOW);
  pinMode(LED_P_SIDE,OUTPUT);
  pinMode(LED_N_SIDE,OUTPUT);
  delayMicroseconds(1000);
  // we could turn it off, but we know that is about to happen at the loop() start
}

A more elaborate version with 20 LEDs and thorough documentation can be found here: http://blog.blinkenlight.net/experiments/measurements/led-camera/

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2016-5-9 11:21:02 | 显示全部楼层
                           

出0入0汤圆

发表于 2016-5-9 11:43:49 | 显示全部楼层
喇叭也可用来检测声波震动

出0入0汤圆

发表于 2016-5-9 12:00:12 来自手机 | 显示全部楼层
看到两个发光二极管互相通信

出0入0汤圆

发表于 2016-5-9 12:03:26 | 显示全部楼层
难道是在led矩阵上用笔画画那个?

出0入0汤圆

 楼主| 发表于 2016-5-9 12:09:31 | 显示全部楼层
led矩阵 触摸视频

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2016-5-11 03:57:37 来自手机 | 显示全部楼层
可学习型的电视遥控器就是这么用的

出0入0汤圆

发表于 2016-5-11 07:58:04 来自手机 | 显示全部楼层
飞思卡尔的电子胸牌也是这样做的。

出0入399汤圆

发表于 2016-5-11 08:38:58 | 显示全部楼层
貌似论坛很多老帖子都弄过哦

出0入0汤圆

发表于 2016-5-11 09:29:12 | 显示全部楼层
学习 了!!!!!
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-17 12:45

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表