Arduino를 사용하여 빛이 있는지 여부를 알려주고 LDR을 사용하고 있습니다. 내 코드는 간단하지만 "light light light light"라는 스팸 대신 "light"라고 말하면 좋을 것입니다. 그리고 light가 꺼지면 "light not"라고 말합니다. "readanalogvoltage"에서 편집 코드 :Arduino IDE : 루프 내부를 한 번 인쇄하십시오.
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0/1023.0);
// print out the value you read:
if (voltage > 1.5)
{
Serial.print("Light");
Serial.println();
delay(5000);
}
if (voltage < 1.5)
{
Serial.print("No Light");
Serial.println();
delay(50);
}
}
글로벌 부울을 사용 하시겠습니까? –