Arduino Light Sensor Tutorial: Learn to Setup a Photoresistor
This little device can be extremely handy in a lot of projects were measuring. The light is important. This tutorial is incredibly simple, but will hopefully explain and show you how to use a photoresistor in your next project. You wont need much equipment to be able to complete this tutorial. Youll need a arduino uno, one photo resistor one 220 ohm resistor, 3 100 ohm, resistors 1 red LED one green, LED one yellow LED a breadboard and breadboard wire. The circuit we need to build is pretty basic and you shouldnt have too much trouble setting it up. Ill briefly mention each of the parts then go through how to put it all together. The light sensor, also known as a photo resistor, is per piece of equipment, well be using to tell how light or dark it is. When it is dark, it will have a very high resistance of up to 10 mega ohms when dis light, it will probably only have a few hundred ohms of resistance. The LEDs in our sir that will represent the current amount of resistance across the photo resistor green will be when its at low resistance or in lots of light yellow will be when its at medium resistance, or there is shade across it. Finally, red will represent when its at high resistance or in the dark first hook for 5 volt wire up from the Arduino to the positive rail on the breadboard next hook for ground pin to the ground rail on the breadboard next place, the photo resistor onto the Breadboard hook a wire from one end, the positive rail on the other end, have a wire go back to a zero on the Arduino.
Finally, on the other side of the wire at a 220 ohm resistor that goes for ground rail plates for 3, LEDs onto the breadboard, the green, yellow and red on each of your LEDs, add a 100 ohm resistor and have this go back to the ground rail? Now place a wire that goes back to the Arduino, for each of the LEDs. Greg goes to pin 4 yellow goes, pin 3 and finally, green into now were ready to turn it on and deploy the code. If you have had any trouble, please refer to the diagram over arduino my life up, calm. Before we start anything, we first need to set up all our variables for this program. We need four variables to store our pin numbers in one variable to store the value of the analog pin. These are all of type integer now set all the pins for the LEDs to act as outputs. You dont need to worry about setting up the analog pin. The loop is pretty simple instantly too hard to understand. Whats going on, we first get the value from the analog pin. This is our photo resistor. Once we have the value we compare in turn on the relevant LED, for example, the red LED will be when its dark, yellow for shady and finally green for light after this delay for 200 milliseconds turn all the LEDs to light and then check again once youre Done simply upload it to the Arduino and just circuit should come to life.
If you want to download for code, you can find it for download over Arduino my life up calm. Now, if youre, finding things arent working exactly as you would like, then itll be a good time to enter some debugging lines. If you dont know how to set up debugging then be sure to check out my tutorial on the Arduino serial monitor. My advice would be to set up a debug line, telling you the value of the LDR input. This can vary, so you might need a change for values in the script, but best suits you. A problem I found is our light for me, red LEDs, setting off the light sensor. My best advice for this would be to move the light sensor away from a red LED as much as possible. There are so many Arduino projects that you can implement a photoresistor into Ill quickly. Just mention a few vana Ford of wilds doing this tutorial. You could use the photoresistor in a light activated alarm. It alerts you every room goes dark or light. Alternatively, you can use it as a bedside alarm clock that gets louder as it gets brighter. You can use it to activate lights when it starts to get dark. For example. This would work well if you have outside lights, that light up some stairs or similar, but only want them on when it gets to a certain level of darkness. You could also hook it up to a chicken hat so that it automatically opens in the morning when it starts to get bright.
These are just a few ideas to what you could do. I will be looking at doing some pretty cool projects in the future that utilizes on a lot of the sensors I have been talking about. I hope you been able to follow this light sensor tutorial without any issue. If you do come across any trouble have feedback or anything else then feel free to leave a comment below or over arduino. My life up comm until next time have a good one.