본문 바로가기

조도센서

주위 밝기 값을 LCD에 표시하기 준비물 - LCD 모니터 1개 - 조도 센서 1개 - 1㏀ 저항 2개 - 10㏀ 저항 1개 코드 #include const int inputLightPin = A0; const int lcdRsPin = 12; const int lcdEPin = 11; const int lcdD4Pin = 2; const int lcdD5Pin = 3; const int lcdD6Pin = 4; const int lcdD7Pin = 5; //LCD 초기화(RS, E, D4, D5, D6, D7); LiquidCrystal lcd(lcdRsPin, lcdEPin, lcdD4Pin, lcdD5Pin, lcdD6Pin, lcdD7Pin); void setup() { //LCD 크기 지정(2x16) lcd.begin(16, 2.. 더보기
주위 밝기에 따라 piezo 스피커 음 변경 준비물 - 조도센서 1개 - piezo 스피커 1개 - 10㏀ 저항 1개 코드 const int lightInputPin = A0; const int piezoOutputPin = 8; void setup() { } void loop() { int light = analogRead(lightInputPin);//0(0V) ~ 1023(5V) int hertz = map(light, 0, 1023, 31, 4978); tone(piezoOutputPin, hertz, 100); delay(100); noTone(piezoOutputPin); delay(200); } 영상 더보기
주위 밝기에 따라 LED 빛 바꾸기 준비물 - 조도센서 1개 - LED 1개 - 10㏀ 저항 1개 - 220Ω 저항 1개 코드 const int lightInputPin = A0; const int ledOutputPin = 9; void setup() { } void loop() { int light = analogRead(lightInputPin);//0(0V) ~ 1023(5V) //p1~p2의 p0값을 p3~p4값으로 맵핑 //ex)0~1023의 light값 255~0으로 맵핑 int ledLight = map(light, 0, 1023, 255, 0); analogWrite(ledOutputPin, ledLight); } 영상 알게된 점 - 조도센서는 빛이 강할수록 약해지고, 빛이 약할수록 강해지는 저항을 통한 전류를 측정하는 센.. 더보기