Photoreceptor and Diodes
Here is my gif for assignment 3! It shows the GIPO LED glowing red in the light, and glowsing blue when I cover the photoreceptor with my finger.
|
This is what the Serial Monitor shows as the LED switched from red to blue.
Here is my schematic for assignment 3! The schematic shows how my circuit board should be connected.
|
Here is my math for how I chose the proper resistances to use. I chose to use 220 ohms of resistance for the GPIO LED, and 10 kohms of resistance for the photoreceptor. The photoreceptor would work just fine with a lower resistance, but a higher resistance saves energy. As the resistance of the photoreceptor translates to the LED being either red or blue, the exact amount of resistance doesn't matter.
|
This is the code I used to make my the LEDs and GIOP on my arduino blink and fade!
int red = 0; // variable, will change depending on color of light void setup() { pinMode(3, OUTPUT); // initialize pin 3 as output pinMode(6, OUTPUT); // initialize pin 6 as output pinMode(A0, INPUT); // initialize pin A0 as input Serial.begin(9600); // initialize serial monitor } void loop() { // the following two lines of code are from our class activity on 1/25/21 int sensorValue = analogRead(A0); // read the analog in value int outputValue = map(sensorValue, 500, 900, 255, 0); // map it to the range of the analog out if (outputValue <= 150){ // if the output value is less than or equal to 150 analogWrite(3, 15); // turn light red at value 15 analogWrite(6, 0); // turn light blue at value 0 red = 1; // variable "red" equals 1 } if (outputValue > 150){ analogWrite(6, 75); // turn light blue at value 75 analogWrite(3, 0); // turn light red at value 0 red = 0; // variable "red" equals 0 } if (red == 1) { // if variable "red" equals 1 Serial.println("The light is red."); // print that the light is red to the Serial Monitor } if (red == 0) { // if the variable "red" equals 0 Serial.println("The light is blue."); // print that the light is blue to the Serial Monitor } } |