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) ?



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Can you read an analouge port on it? There is your code :)

yes it have, this is the board:



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

i made this simple code that works :)

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


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 :)

for now all i want is on/off