Photocell

חיישן אנלוגי המשמש למדידת עוצמת תאורה.

ניתן לקנות את החיישן בכל חנות אלקטרוניקה, בזול.

מעגל:

רגל אחת של ה Photocell מחוברת ל 5V
הרגל השנייה מחוברת לAnalog Pin של ה Arduino ול GND דרך נגד 1k – חום-שחור-אדום-זהב.

photocell

תוכנה:

את הערך של ה Analog pin קוראים ב AnalogRead (כמו קריאת ערך ה potentiometer)

התוכנה הבאה תגרום ללד המחובר לפין 13 של הארדואינו להבהב בקצב המותאם לכמות האור – מהר יותר ככל שיש פחות אור:

int potPin = 2;    // select the input pin for the photocell
int ledPin = 13;   // select the pin for the LED
int val = 0;           // variable to store the value coming from the sensor

void setup() {
 pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
}

void loop() {
 val = analogRead(potPin);       // read the value from the sensor
 digitalWrite(ledPin, HIGH);  // turn the ledPin on
 delay(val);                                     // stop the program for some time
 digitalWrite(ledPin, LOW);    // turn the ledPin off
 delay(val);                                    // stop the program for some time
}

Comments are closed.