1. 조도센서 CdS
- 밝으면 저항이 작아짐 = Vout 전압이 작아짐
- 어두우면 저항이 커짐 = Vout 전압이 커짐
2. 실습
const byte cds = A0;
void setup()
{
Serial.begin(115200);
}
void loop()
{
int ad_cds;
float v_cds;
ad_cds = analogRead(cds);
v_cds = (float)ad_cds / 1024.0 * 5;
Serial.print("AD_CDS = ");
Serial.println(ad_cds);
Serial.print("V_CDS = ");
Serial.println(v_cds);
Serial.println(" ");
delay(1000);
}
#include <MiniCom.h>
#include <Analog.h>
MiniCom com;
Analog cds(A0, 0, 100);
void check(){
int value = cds.read();
com.print(1, "Illu: ", value);
}
void setup(){
com.init();
com.setInterval(100, check);
com.print(0, "[[CDS Test"]]);
}
void loop(){
com.run();
}
3. led도 같이 켜지게 해보셈
#include <MiniCom.h>
#include <Analog.h>
#include <Led.h>
MiniCom com;
Analog cds(A0, 0, 100);
Led led(8);
void check() {
int value = cds.read();
led.setValue(value > 50);
com.print(1, "Illu: ", value);
}
void setup() {
com.init();
com.setInterval(100, check);
com.print(0, "[[CDS Test]]");
}
void loop() {
com.run();
}