毕业设计(一)

今天简单的用光照传感器做毕业设计的一个小部分,先简单的记录一下吧!

大致完成的内容是光照传感器检测环境的光照强度,当检测的数据超过一定的数值(环境较暗的情况),自动点亮LED,否则LED不亮

首先准备的工具:
Arduino UNO R3开发板
光照传感器
LED
杜邦线

连接线
Arduino开发板 光照传感器
3.3V------------------VCC
GND-----------------GND
A0---------------------AO

Led灯正极(长)接13,负极(短)接GND

准备差不多了,上代码!
这里环境越暗,读取的模拟值越大,当数据超过60,就会自动打开LED小灯。可以根据环境的不同状态调整参数。

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 
}
int a=60;
void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);            
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 10000, 0);  
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);           

  // print the results to the serial monitor:
  Serial.print("sensor = " );                       
  Serial.print(sensorValue);      
  Serial.print("\t output = ");      
  Serial.println(outputValue);  
 if(outputValue>=a)
{
  digitalWrite(13,HIGH);
}
else
{
   digitalWrite(13,LOW);
}
  delay(1000);                     
}

毕业设计的路好漫长啊…等我下次更新吧~~

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值