Hello, this is my first post! I want to make my L.E.D. dim/turn off when more light is present, and when a switch is toggled ON. I'm using a 560 Ohm resistor serving as what I believe is a step down to ground, and a photo resistor on my 5V coming from the arduino. Currently, the more light shines on the PhotoResistor, the brighter the L.E.D. becomes. Of course, this is to be expected, because as the light level increases, the resistance decreases. I would like the resistance to increase. How would I go about doing this? I've included a picture as to show how it all looks.
Hi Markrose, and welcome.
You can't.
You have to accept that the hardware is as-is (that's why it is hardware).
So if you want the behavior to change, you should do that by programming in the correct way.
I hope you are using AnalogInput from the examples in IDE (which does something similar to what you described, but not the same), because that means you are going through the examples to get started.
If you want to work this out the easiest way i can think of, look up map in reference on this site.
Swap resistor and photoresistor, than more lights 'd lower voltage.
Magician is probably right, based on how you would use a resistor and a photoresistor for input.
And that is easier than reprogramming and so also easier than i could think of.
But i can't say i got that that is how you have wired it up from your description, and the huge photo doesn't help here either.
My "you can't" is the answer to you asking how to make the photoresistor have the resistance increase with more light.
Ok, thank you for the info; I switched around the PhotoResistor and the regular, 560 Ohm resistor, and would ya look at, it behaves the exact same way as before! (no sarcasm) Is the non-photo resistor too high of a resistance? I could think of a way to make it (the photoresistor) input through analog into the Arduino, and then make it so that the lower the voltage, the lower the PWM. More voltage from the resistor into the Arduino, more voltage to the L.E.D. If it makes any difference, I'm using an Arduino Leonardo. But, seeing that it's 11PM where I live, I think it's time to call it a night and continue on this tomorrow. Please, do reply on how you think it's possible to wire it up!
EDIT: If I program it, it makes the Arduino more of a microcontroller rather than a power source, which was what I wanted; a microcontroller. Guess I'm programming this puppy!
Also, sorry for the MASSIVE picture, my camera is a bit too high-res for online stuff.
So we seem to live in the same timezone.
To get how this works, some explanation is in order.
You can't measure resistance with an Arduino.
But you can measure a voltage up to the voltage that is powering your Arduino (typically 5 volts).
If you would connect a resistor of some kind to either 5 volts or GND, and the other side to the input pin then you would always see the level you connected to.
If you connect 2 resistors and the input pin to the point where both resistors are joining, you create a voltage divider.
In case one of them is a variable (photo) resistor, and the other one fixed then you can measure the entity that is causing the variation in that resistor.
The division of the 5 volts over the resistors is the same as their ratio.
Now if the fixed resistor is tied to GND and the photo resistor is tied to 5 volts, more light would lead to a lower resistance and the input level gets a bit more towards the 5 volts.
If the photoresistor is tied to GND and the other one to 5 volts, more light leads to the input getting closer to GND.
The photo shows a toggle switch, your 560 Ohm resistor (seems a bit of a low value to me) and the photoresistor.
It's unclear to me what the switch is for, and how the resistors are connected.
And it's also unclear how the Arduino is connected to all this.
Could you tell a bit more about that ?
The toggle switch is just... there. Hmm, wonder why I put that. I'm going to remove that now.
I have such low resistance mainly due to the fact that I've been using it indoors (not much light at 11PM); when it's daylight (which it is, now), I'll slap in a 10K resistor.
Arduino Leonardo into USB Port, 5V to positive rail on breadboard, ground rail to ground on Arduino. The rest of the circuit is visible on the previous picture. I may take another picture without the unimportant bits like the wires not plugged into anything when I was experimenting with other stuff. In fact, the next post will have a new picture.
Hope this cleared up some stuff.
Here's yet another massive picture. I recommend downloading it to view it. Ignore the right half of the breadboard, I'm doing something else there that requires programming.
Well, that looks like:
5 volts - 10K - LED - PhotoResistor - GND.
There's no wires visible apart from the power supply (with odd colors by the way).
So i guess you want to have this work without controlling it with your Arduino ?
That is not going to work, at least because the 10K is much too large in this case.
Your 560R resistor would be better and that might be what you had before (i don't know).
You are experimenting with several LEDs (there was a red LED before, and i see an IR LED).
You got that you need to limit current if you are powering a LED from 5 volts , "serving as what you believe is a step down to ground".
That remark makes some more sense to me now.
It is not exactly what that resistor is for.
That resistor limits current to your LED.
In that case 560 Ohms isn't a bit low as i stated before, but it's twice what is recommended for this (most used in the examples over here is 220 or 270 Ohms), but you can use that 560R without a problem, you'll just have a somewhat dim LED.
The 10.000 Ohms resistor limits the current so much that there will be barely any light emitting from the LED.
And the photo resistor will be of very little influence anymore.
Hoe do you want to wire this all up to your Arduino and have it control the LED brightness:
First you need to do is to build the voltage divider.
You can have a go with that using your 10K resistor and the photo resistor, wire them like:
5 volts - 10K - photoR - GND, and connect the junction of the two resistors to the Arduino input pin.
Also connect Arduino output pin - 560R - LED Anode - LED Cathode - GND.
Now you can read the voltage, which will be lower at more light, at your Arduino input pin.
And you can control the LED at your Arduino output pin accordingly.
Use one of the output pins that has a ~ mark next to it, it means that pin is PWM capable.