Sunday, January 17, 2016

Learning about photoresistors

I tried setting up a circuit that included a photoresistor and the expected outcome didn't happen.  OK, let's start with something simpler, let's test if the photoresistor is working.  I found several versions of this program and here is what I wrote (copied).  My first compile, missed a wiggly parenthesis.  After a successful compile I downloaded the code to my arduino.  Hmmm forgot a step, didn't go to tools and open the serial monitor, so I couldn't see the output.  Finally, got it together and the program ran successfully, so I knew I was using a working photoresistor.  Now I'll go back to the original program, Circuit 6 in the Vilros handbook and try again.

const int kPin_Photocell = A0;
void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:

    int value = analogRead(kPin_Photocell);

    Serial.print("Analog Reading = ");
    if(value < 200){
      Serial.println(" - Dark");
    }else if (value < 400){
      Serial.println(" - Dim");
    else if(value < 600){
      Serial.println(" - Light");
    else if(value < 800){
      Serial.println(" - Bright");
      Serial.println(" - Very Bright");

No comments: