Introduction: Photoresistor Sensor With Arduino Hand Placard
改作來源:https://www.instructables.com/id/Photoresistor-Sen...
自己DIY追星手舉牌!利用光敏電阻和LED燈,讓LED燈數會隨著暗度增加。打造屬於自己的追星小物!
Step 1: Components Required
- Arduino Uno board * 1
- USB cable * 1
- Photoresistor * 1
- Resistor * 12
- LED * 11
- Breadboard * 1
- Jumper wires
Step 2: Schematic Diagram
此圖為原網址所附的圖示
Step 3: Procedures
左圖為8顆LED燈(原網址),右圖為11顆LED燈
Step 4: Code
const int NbrLEDs = 11;//8 leds
const int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};//11 leds attach to pin 2-12 respectively (改 增加3顆LED燈
const int photocellPin = A0; //photoresistor attach to A0
int sensorValue = 0; // value read from the sensor
int ledLevel = 0; // sensor value converted into LED 'bars'
void setup()
{
for (int led = 0; led < NbrLEDs; led++)
{
pinMode(ledPins[led], OUTPUT);// make all the LED pins outputs
}
}
void loop()
{
sensorValue = analogRead(photocellPin); //read the value of A0
ledLevel = map(sensorValue, 1023, 350, 0, NbrLEDs); // map to the number of LEDs (改 將LED燈在光照下亮燈改為隨亮度漸暗LED燈會一個一個變亮)
for (int led = 0; led < NbrLEDs; led++)//
{
if (led < ledLevel ) //When led is smaller than ledLevel, run the following code.
{
digitalWrite(ledPins[led], HIGH); // turn on pins less than the level
}
else
{
digitalWrite(ledPins[led],LOW); // turn off pins higher than
}
}
}
Step 5: Final Arduino LED Hand Placard
這樣就完成啦!
自己的LED手舉牌自己做!