Hi,
my first project is a light sensor running an LED.
I want to add a tilt switch to allow the light to be turned off when its dark my turning the board upsidedown.
my sketch is:
#define LED 13 // the pin for the LED
int val = 0;
// variable used to store the value
// coming from the sensor
void setup() {
pinMode(LED, OUTPUT);
// LED is as an OUTPUT
// Note: Analogue pins are automatically set as inputs
}
// a threshold to decide when the LED turns on
int threshold = 200;
void loop() {
val = analogRead(0); // read the value from the sensor
if (val < threshold) digitalWrite(LED, HIGH);
else digitalWrite(LED, LOW);
/
}
I tried to add a photo but having trouble finding the browse button to add it
Can you point me in the right direction?
Thanks
Dave
EDIT: Added photo