Go Down

### Topic: Photo Resistor question (Read 732 times)previous topic - next topic

#### Drew Davis

##### Oct 26, 2012, 09:01 pm

Hello,

I got the program below off of this website and I'm wondering if somebody could explain what

Thanks
Drew Davis

int lightPin = 0;  //define a pin for Photo resistor
int ledPin=11;     //define a pin for LED

void setup()
{
Serial.begin(9600);  //Begin serial communcation
pinMode( ledPin, OUTPUT );
}

void loop()
{
Serial.println(analogRead(lightPin)); //Write the value of the photoresistor to the serial monitor.
analogWrite(ledPin, analogRead(lightPin)/4);  //send the value to the ledPin. Depending on value of resistor
//you have  to divide the value. for example,
//with a 10k resistor divide the value by 2, for 100k resistor divide by 4.
delay(10); //short delay for faster response to light.
}

#### guix

#1
##### Oct 26, 2012, 09:05 pm
Hello, look there is a comment at the right of that line

#### Lakes

#2
##### Oct 26, 2012, 09:11 pm
lightpin is defined here as pin 0 (zero) on the arduino board, this is the arduino pin that has the photoresistor connected to it.
The resistance of the photoresistor varies with the amount of light that falls on it, pin zero reads this value same as it would with a pot (variable resistor).

Serial.print prints out this value to the serial monitor as well as controlling the brightness of the LED.

#### Drew Davis

#3
##### Oct 26, 2012, 09:15 pm
Let me rephrases my questionâ€¦

I understand that it prints the value to the serial monitor but how does that effect the program?
Also, what is a serial monitor? Sorry to ask such basic questions.

Thanks,
Drew Davis

#### AWOL

#4
##### Oct 26, 2012, 09:24 pm
Quote
I understand that it prints the value to the serial monitor but how does that effect the program?

It doesn't affect the program in any way apart from slowing it down a bit.

The serial monitor is one means by which you may monitor the output of your sketch.
It's a type of basic terminal emulator.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### Drew Davis

#5
##### Oct 26, 2012, 09:41 pm
I just deleted it and the program worked fine!