Light Intensity Level Sensor Module
The Light Sensor module can be used on a smart car for the experiment about light seeking. Since the resistance of a photoresistor decreases with strong light, the car can be controlled to move based on the resistance change, that is, to seek for the light and follow it. Also the light intensity can be reflected by the LED bar on the module.
More details can be found in WIKI.
TestCode:
//LightSeeking sensor /*By changing the intensity of the ambient light around the module, you can see different numbers of LEDs on the LED bar graph brighten accordingly.*/ //Email:support@sunfounder.com //Website:www.sunfounder.com //2016.07.02 const int latchPin = 12; //Pin connected to ST_CP of 74HC595 const int clockPin = 8; //Pin connected to SH_CP of 74HC595 const int dataPin = 11; // Pin connected to DS of 74HC595 const int photocellPin = A0; // A attach to A0 int photocell = 0; unsigned char code_val[] = {0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; //Display different numbers of LEDs void setup() { //set pins to output pinMode(latchPin,OUTPUT); pinMode(clockPin,OUTPUT); pinMode(dataPin ,OUTPUT); } void loop() { photocell = analogRead(photocellPin); //read the value of A0 int digital=map(photocell,0,1023,0,8); //Value read is divided into 8 equal portions digitalWrite(latchPin,LOW); shiftOut(dataPin,clockPin,MSBFIRST,code_val[digital]); /* return the latch pin high to signal chip that it no longer needs to listen for information */ digitalWrite(latchPin,HIGH); //pull the latchPin to save the data delay(1); }