// EPOCH PROJECT#6 "ANALOG INPUTS, INTEGERS, AND THE SERIAL MONITOR" // THIS PROJECT BUILDS OFF OF PROJECT#5 // CONNECT THE "LIGHT" PIN TO THE A3 (ANALOG PIN#3) PIN ON CHIP-A. THIS WILL CONNECT THE LIGHT SENSOR OUTPUT TO ONE OF THE ANALOG-TO DIGITAL CONVERTER PINS. int hold = 0; // THIS IS AN INTEGER. IT IS ESSENTIALLY A STORAGE CONTAINER. IT CAN HOLD VALUES FROM -32,768 to 32,767. WE WILL STORE LIGHT SENSOR DATA HERE. void setup() { Serial.begin(9600); // THIS INITIALIZES THE SERIAL MONOTIR, AND SETS THE BAUD RATE TO 9600. MORE ON THIS LATER. IT ISN'T OVERLY IMPORTANT RIGHT NOW. } void loop() { hold = analogRead(3); // THIS COMMAND TAKES A READING FROM THE A3 PIN, WHICH IS CONNECTED TO THE LIGHT SENSOR OUTPUT, AND PLACES THE RESULT IN THE "hold" INTEGER. Serial.print("Light Output: "); // THIS COMMAND PRINTS "Light Output: " TO THE SERIAL MONITOR. NOTICE THE QUOTATION MARKS. WHEN YOU USE QUOTATION MARKS, YOU CAN TYPE WHAT YOU WANT TO PRINT WITHIN IT. Serial.println(hold); // PRINT THE VALUE STORED IN THE "hold" INTEGER. NOTICE THAT THERE ARE NO QUOTATION MARKS, AND ALSO NOTICE THE "ln" AFTER PRINT. THIS TELLS THE PROGRAM TO GO TO THE NEXT LINE AFTER THIS HAS BEEN PRINTED. delay(500); // THIS IS A 500ms DELAY, WHICH MEANS THAT ALL OF THE ABOVE WILL OCCUR EVERY HALF SECOND. THAT IS THE END OF THE PROGRAM. } // NOTES: // The light sensor is a variable resistor. It is called an LDR, or "Light Dependent Resistor". Typically the resistance of the resistor is very high in the darkness, and very low in bright light, and anywhere in between. // The Analog pin (A3) is an analog-to-digital converter (ADC) pin. The ADC samples voltages anywhere between 0v and 5v (The power supply used for the chip. Becuase it is a 10-bit ADC, the sampled value will be anywhere from 0 and 1023. // A basic understanding of binary and hexidecimal are needed to fully understnad this, and this will be covered in another video. However, a value of 0 equals 0v. A value of 1023 = 5v. 2.5v is roughly 511. // Here is how it is calculated. The reference voltage is 5v, and we have a 10-bit ADC, which means that there are 1024 steps, as 0 counts as a step. 5v / 1024 = 0.00488. So 0.00488 volts is the voltage per step. // If we read a value of 333, then we can manually figure out how much voltage is being seen by the analog line. Try it when you run this software. Multiply the number that the serial monitor reads out by 0.00488, and you'll have your voltage // We'll be doing a voltmeter project very soon. // When you program the Epoch with this program, go to the "Tools" pull down menu, and select "Serial Montitor". You should see the program running on it. If you can't open the monitor, check to make sure that the "port" that the Epoch is connected // to is the right one. Tools > port.