Look in System Preferences under "Keyboard". There is an option to have it automatically illuminate when it's dark. Note that if you manually force the keyboard to zero brightness using F5/F6, it disables this option in the system preferences and you won't get any auto-lighting. Therefore, you have to leave it on at least 1 bar of brightness and then the light sensor will determine when it is bright enough to disable the illumination. I have found unfortunately that when I do this, I think the computer turns on the backlight much too early (turns it on when it's still plenty bright in the room) thus I just work the brightness manually.
Also I think that the backlit keyboard is too bright except for the lowest setting, and only really useful in very dim/pitch black situations. Therefore I just use the keys to turn it on/turn it off. I've actually noticed that the screen brightness control is too sensitive to light changes as well and so I don't use that auto feature anymore either which is too bad because I really liked that feature on my PBG4.