Archive

Posts Tagged ‘light’

OPL530 – Sensing Light (or so I thought)

July 14, 2012 Leave a comment

The OPL530 (click here for the datasheet (.PDF)) and the OPL5## series are “Photologic Sensors“. Unfortunately, I bought two of these when what I was actually looking for was a simple photodetector/photoresistor. Turns out that my datasheet comprehension is not as great as I thought, and this sensor is something entirely different. This sensor is actually a photodiode with an integrated circuit intended to be paired with a infrared LED with a wavelength of 935nm, and provides logic output, meaning; HIGH or LOW (1 or 0). I believe that the use of photologic sensors is intended for applications such as non-contact object sensing (think detecting rotating fan blades), end of travel sensing, and door position sensing.

As I understand it, the basic function of this sensor is; if it detects the light of an infrared LED, past a certain threshold, it will output the signal HIGH or 1, otherwise it will output LOW or 0. If this is true, and there is only two possible outputs, then this sensor most definitely cannot be used in a way similar to a photoresistor, which provides a variable analog output.

The projects that I had in mind required a sensor that would measure general lighting of the environment, something like a photoresistor. Perhaps this ambient light sensor (.PDF) was more in line of what I needed, or I can just go and buy a couple actual photoresitors off Digikey.

I do have a photoresistor … somewhere around here … and will follow up with a brief tutorial on its use as soon as I can find it.

Continue for more information about the sensor…

Read more…

if Test

January 9, 2012 Leave a comment

The “if” is a test you give to the Arduino. In this test you make the questions and you determine what happens when it passes or fails. If the test that you made is passed, as in something happens that you wanted to happen, then you want the Arduino to do a certain action. Optionally, if the test is failed or something unexpected happens and the test is failed, you can tell the Arduino to take a different action.

If you wanted to make a test on the Arduino that would turn on a light for 5 seconds every time someone walked through a door it would look something like this:

if (PersonWalkingThroughDoor == 1) {
 digitalWrite(LIGHT, HIGH);
 delay(5000);
 digitalWrite(LIGHT, LOW);
 }

And a translated human readable version to understand whats going on:

if (a person walks through the door) {
 turn on the light;
 wait 5 seconds;
 turn off the light;
 }

Now, let’s try to understand the Arduino version of the test and see why it works…

A person can only be walking through the door or not, we can represent this as 1 or 0, respectively. Then, we can assign this state to a certain variable – which can be thought of as a digital box that can hold thing – we’ll call this variable “PersonWalkingThroughDoor”.

If a person is walking though a door our variable PersonWalkingThroughDoor would equal 1, otherwise it would be 0. Given this basic setup we can run a test, and that is exactly what this part of our code does:

if (PersonWalkingThroughDoor == 1) {

If our variable PersonWalkingThroughDoor is equal to 1, then it would pass our test and go into the action phase, where it would preform a certain task.

digitalWrite(LIGHT, HIGH);
delay(5000);
digitalWrite(LIGHT, LOW);
}

What happens in our “action phase” are just some basic commands, first we use digitalWrite() to set the pin attached to the LIGHT variable to HIGH (turning on the light), then we wait 5000 milliseconds, then we turn the light off.
Finally, if you want to expand the function of the test then you can include an “else” clause which would look something like this:


 if (PersonWalkingThroughDoor == 1) {
 digitalWrite(LIGHT, HIGH);
 delay(5000);
 digitalWrite(LIGHT, LOW);
 }
 else {digitalWrite(LIGHT, LOW);}

In that case, if the initial test is failed you can tell the Arduino to take a different action. In our case it would simply keep the light off if there is nobody walking through the door, and it truly inessential as the light is turned off by default after 5 seconds.

So that’s it, that’s the basic overview of an if function. You might know it, but the best way to understand it is to try it out yourself.

Understanding LEDs

January 5, 2012 Leave a comment

Ah, LEDs. To me, they are to electronics what fire was to the early man.

Such a simple thing. Take any coin cell battery – making sure the plus side of the battery goes with the longer leg of the LED – slide the legs of the LED over the battery and you have LIGHT!

Here’s a simple explanation on how LEDs work from reddit user speedstix:

LED’s are semiconductor technologies that are really good at converting electricity to light. There are two types of semiconductors. N-type silicon and P-type silicon. N-type silicon has excess electrons in it. P-type silicon has extra holes that electrons are drawn to. This is important to remember. Now if you sandwich N-type silicon and P-type silicon together you get something called a diode. Hence the name Light Emitting Diode (LED). Now when these two materials are sandwiched together where they meet the holes from the P-type silicon attract the electrons from the N-type silicon. (think of north and south poles of magnets and how opposites attract) This attraction creates a barrier. Now if you connect a positive DC voltage to the P-type side and the negative part of this voltage to the N-type side this barrier gets smaller and smaller and eventually electrons will jump from the P-type side to the N-type side. Remember from before these jumping electrons are what creates light. Depending on how big or small this barrier is you will get different coloured light. Also if you reverse this voltage you make the barrier bigger and bigger and no electrons will pass. This is exactly what a diode is intended to do. Only allow current to flow in one direction.

For a more detailed explanation you can go here: HowStuffWorks.com

A nice macro image of an LED via wikipedia:

(Side Note: Remember that electrons flow Cathode (-) to Anode (+), and conventional electric current flows positive to negative.)