Asked — Edited
Resolved Resolved by Dunning-Kruger!

Cds (Visible Light Sensor)

Can someone explain how to interface a light sensor (2 wires) to the EzB. I would like the robot to be able to tell light from dark.

Thanks.


ARC Pro

Upgrade to ARC Pro

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!

#1  

It's probably an analog device... You can try using the grd and signal pins of one of the analog ports.... It will be something like 0V in the dark and 5V in bright sunlight (or vice versa)...

United Kingdom
#2  

It depends on the sensor, I presume it's an analogue device which is basically an LDR (light dependent resistor). So when it is lighter the resistance will vary.

If that is the case then a simple circuit connected to the analogue port will work. Similar to a voltage divider, when the resistance of the LDR/light sensor varies so will the voltage that's applied to the signal pin on the analogue port.

You can then use a simple script or ADC control to monitor the port and react accordingly.

A simple LDR circuit could be something like this;

User-inserted image

The LDRs resistance range will determine the value of R1.

Note, this was a very quick schematic and I was too lazy to use the correct symbols however the general idea should be obvious.

#3  

If you use something like this Light sensor you can directly interface it with the EZB without mucking around with adding resistors and such... Basically plug and play....

United Kingdom
#4  

Or this one from Adafruit (costs a little more but I prefer Adafruit stuff, they put more thought in to the help and datasheets etc.)

PRO
USA
#5  

Appreciate the reply. And the two locations for additional sensors. Will be asking about interfacing them in he future. I have one more question, once I am ready to hook the sensor up, can either of you supply me some sample code to read the value from the sensor?

thanks in advance.

#6  

Of course we can... Both Rich's and my links are plug n' play (although I would go with the one Rich suggested, looks like a more elegant solution)... Meaning plug them into the analog ports of the EZb and use the ADC Value control or this simple 2 line of code below (in a script)...


$cds=GetADC(ADC0) # read the analog value of the CDS on analog port 0

Print($cds) #print out the value should be a number between 0 and 255


Where 0 might represent complete darkness and 255 would be bright sun.... Values in between represent varying degrees of brighness

United Kingdom
#7  

Don't forget to loop the code and add in a sleep to reduce bottlenecking the comms...

Personally I would have a script with the following set up.


:loop
$cds = GetADC(ADC0)
Sleep(100)
Goto(loop)

Then have that start with a ControlCommand in an init script.

The variable $cds would be global (i.e. available to all other scripts and controls in ARC). You can then simply use the variable in other scripts which may need it without needing to worry about getting the light value manually.

PRO
USA
#8  

Richard R. Awesome stuff...thanks I will be reaching out for more code support as I get further along with my project.

thanks