Let's Make Robots!

Light Sensor on a atmega8 based

Hi :)

Can anyone send me a sample of c code to use a Light Sensor (LDR) ?

 

regards.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

for now all i want is on/off

 

regards

i made this simple code that works :)

#include <sleep.h>
#include <sound.h>
void main()
{
while(1)
{
if (in_c(0)==1) // if have light
{
sound(2000,100); // beep
}
sleep(200);
}
}

 

im using an atmega8

Cool.. However - I think you are only reading a digital port there, though I am not sure :)

Point is; You should get a value out - like a number from 0-255 - not just "on/off".. if that is what you want at least :)

yes it have, this is the board:

 

Picture%203.png

What I ment was: Can you write the code that reads an analouge input? If so, just hook up the LDR to it, and read the input. That will be the code you are asking for: It is just an analouge input that you need to read in order to read the LDR :)

If you are not sure how to hook it up, this might help: http://letsmakerobots.com/node/1833

Can you read an analouge port on it? There is your code :)