Hello. So I've tried connecting everything like it is shown here: Connecting a Photoresistor to an Arduino and it works but only for about a minute and then port monitor stops scrolling. The only difference is that I use 82K resistor. What's wrong?
Post your code.
Mark
So I've tried connecting everything like it is shown here: Connecting a Photoresistor to an Arduino and it works but only for about a minute and then port monitor stops scrolling.
The person who wrote that is an idiot. There is no resistor in line with that LED, there needs to be one. About 220 ohms should do.
He does say:-
Pin 13 has built in resistor.
But that is rubbish, look at the schematic there is no resistor.
Are you sure it stops and not that the same thing gets scrolled up the screen so it looks like it has stopped?
Personally I never use resistor for led since I bought 100 for $1 and I don't care if something happens to them but so far all of them are working. The led stops flashing when the thing stops scrolling so no.
@Mark Code is on the website.
try using a toggle on the serial prints to see what's happening without multiple prints
int lightPin = 0; //define a pin for Photo resistor
int threshold = 250;
boolean serialReport;
void setup(){
Serial.begin(9600); //Begin serial communcation
pinMode(13, OUTPUT);
}
void loop(){
Serial.println(analogRead(lightPin));
if(analogRead(lightPin) > threshold )
{
if (serialReport == true)
{
Serial.println("high");
serialReport = false;
}
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
if (serialReport == false)
{
Serial.println("low");
serialReport = true;
}
}
delay(100);
}
Personally I never use resistor for led since I bought 100 for $1 and I don't care if something happens to them but so far all of them are working.
Do you care about burning out your Arduino?
With your sort of attitude to electronics I don't think you deserve any help.
Try this: add a second led to an unused output (without a series resistor if you like, we wont be paying for your replacement parts after all).
Then add this line of code just before the end of loop ()
digitalWrite (p, bitRead (millis (), 9));
where p is the output number with the new led on it. Don't forget to set p to OUTPUT in setup ().
The led should flash around once per second. What happens to the led when the serial output freezes?
If that freezes too, remove all the Serial.print commands from the sketch and re-run.
dainiusb:
Personally I never use resistor for led
In that case you'd better get used to things stopping working, working erratically and burning out. The LED needs a current-limiting resistor in series.
Personally I never use resistor for led ...
Even if the LED or Arduino aren't permanently damaged, without the resistor you are drawing excessive current from the Arduino (exceeding it's specs) and that certainly COULD cause erratic operation and "crashing" of you sketch.
That MIGHT not be the problem, but it's a bad design and it's a good place to start. When you are troubleshooting/debugging you never know for sure what the real problem is until the problem is solved. ![]()
It's easy enough to disconnect the completely LED see it that fixes the scrolling problem.
@DVDdoug Thanks for explanation. I guess I'll get some of them sometime.
It seems that Arduino doesn't stop. I think that serial port monitor is finite that's why it stops showing the values, but Arduino still reacts so it's fine. I haven't used Arduino for a while and because of that I forgot to check several things. Oh well..thanks everyone!