Last active
August 16, 2018 04:18
-
-
Save likersacademia/d1dbf00ad0739ad19f85d95c987e290e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 光量値を示すプログラム(10kΩプルダウン、5V電源時) | |
#define cdsPin 1 | |
void setup() { | |
Serial.begin(9600); | |
pinMode(cdsPin, INPUT); | |
} | |
void loop() { | |
// R1のAD値を取得 | |
float cds_ad = analogRead(cdsPin); | |
// AD値を電圧値に変換 | |
float cds_v = cds_ad * 5 / 1023; | |
// 電圧値より、Lux計算 | |
float lux = 10000 * cds_v / (5 - cds_v) / 1000; | |
Serial.print(lux); | |
Serial.println(" Lux "); | |
if (lux > 20) { | |
Serial.println("High lux"); | |
delay(2000); | |
} else { | |
Serial.println("Low lux"); | |
delay(2000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment