It is a creative course filled with creative and fresh buddies. Because I missed the first class this semester, so I built up the photoresistor a little bit later.
This lab aims at figuring out the basic understanding of how Arduino works both on software and hardwares, especially how to connect components to the correct pins with correct circuits. For the photoresistor lab, the components we need are shown in the pictures below.
This lab aims at figuring out the basic understanding of how Arduino works both on software and hardwares, especially how to connect components to the correct pins with correct circuits. For the photoresistor lab, the components we need are shown in the pictures below.
There are basic panels of Arduino, and some circuits, two resistors, a blue LED light and the photoresistor sensor. After resembling, the circuit structure is shown as below.
As for programming, the target is making the LED brightness controlled by the photoresistor, in simple words, the less light sensed by the photoresistor, the darker the LED will be. The utilized codes for this may be:
- int ledPin = 3;
- int photocellInput = 0;
-
- void setup() {
- pinMode(ledPin, OUTPUT);
- }
-
- void loop() {
-
- photocellInput = (analogRead(0)/4); // Divides input 0-1023 to resemble to 0-255
-
- analogWrite(ledPin, photocellInput);
- // The delay can be change to get the desired dimming effect
- delay(20);
- }
The video is going to show the expected function.