תוכנית לבדיקת חיישן אור
/*
Arduino Starter Kit example
Project 6 - Photo Resistor
This sketch is written to accompany Project 6 in the
Arduino Starter Kit
Parts required:
photoresistor
10 kilohm resistor
This example code is part of the public domain
*/
// variable to hold sensor value
int sensorValue;
// LED pin
const int ledPin = 13;
void setup() {
Serial.begin(9600); // open the serial port at 9600 bps, used for the console communication
// Make the LED pin an output
pinMode(ledPin, OUTPUT);
}
void loop() {
//read the input from A0 and store it in a variable
sensorValue = analogRead(A0);
// write the value to the console
Serial.println(sensorValue);
if (sensorValue > 400 )
digitalWrite(ledPin, LOW);
else
digitalWrite(ledPin, HIGH);
// wait for a moment
delay(500);
}
//END!