In previous studies, polyaniline nanofiber sensor on interdigital electrode is sensitive to light. Herein, we prepared a flexible hydrogel sensor with polyaniline nanofiber as the active material and polyacrylamide hydrogel as the flexible substrate. Comparing the properties of above two different kinds of sensors with polyaniline nanofiber, the photocurrent generated by PANIhydrogel sensor under external light stimulation is about 1~2 orders of magnitude higher than interdigital electrode sensor, indicating the PANI-hydrogel sensor is more sensitive. The two sensors can all respond to different wavelengths of monochromatic light, especially sensitive to light of smaller wavelengths such as ultraviolet light (380 nm) and blue light (475 nm). Moreover, the volt-ampere characteristic curve in response to external light stimulation can be clearly distinguished only when the appropriate concentration of proton acid is doped (3 g citric acid, 7 g acetic acid, and 3 ml HCl).