We have designed and fabricated a novel photodetector that is composed of sandwich-structured n-type zinc oxide nanorods arrays, p-type polyaniline thin film, and dye-modified n-type ZnO nanorods arrays. When the photodetector is alternatively illuminated by ultraviolet and visible light from the same direction, it outputs alternating current.