Homework 04-Combined Circuit-Elena Brown

5 Nov

I set up the arduino to fade an LED on and off using a LDR light sensor.

Here is the code that was used to accomplish this:IMG_2675

const int LED = 13; //pin for the LED
const int LDR = 7; //input pin for the sensor

int val = 0//starting value of 0

void setup() {
pinMode(LED, OUTPUT); // LED is an output
pinMode(LDR, INPUT); //BUTTON is an input
}

void loop() {
val = digitalRead(LDR);//read and store input value

if (val == HIGH) {
digitalWrite(LED, HIGH);//turn LED on
} else {
digitalWrite(LED, LOW);//turn LED off
}
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s