[Photon] Photo cell (CdS photoresistor) didn't work ! SOS

What I am trying to do is…
[ The Box have eyes - one is just drawing dot, another one is photo cell censor
If you put the light with flashlight or block (cover) the eye (actually photh cell),
the buzzer start to sound.
It should sounds like irritating or being surprised. ]

And I connect devices that I have
(1.Full sized breadboard
2. Particle Photon with Headers
3.NeoPixel Diffused 5mm Throgh-Hole LED
4.Photo cell(CdS photoresistor
5.Piezo Buzzer)
like this…

And create code like this…

//belongs to Yunki Min
//The Box have eyes - one is just drawing dot, another one is photo cell censor
//If you put the light with flashlight or block (cover) the eye (actually photh cell), the buzzer start to sound.
//It should sounds like irritating or being surprised.


// Declare some variables
int publishLight = A0;
int ledPin = D2; 
int speakerPin = D0;

// Create a software timer to publish at an interval

Timer publishBrightness(1000, publish);

void setup() {
    
    // Make the A0 pin an INPUT
    pinMode(A0, INPUT);
    pinMode(ledPin, OUTPUT); 
    pinMode(speakerPin, OUTPUT);
    //Publish Brightness reading
    publishBrightness.start();
}

void loop() {
    
    // Pin SetUp
    publishLight = analogRead(A0);
    //update Temp every .2 seconds
    delay(200);
//}


//void light() {
int melody[] = { 349, 349, 523, 523, 587, 587, 523, 247,247,220,220,197,196,349}; //C4,G3,G3,A3,G3,0,B3,C4
//note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {8,4,4,4,4,4,4,4,4,4,4,4,4,4 };

if (publishLight > 1000){
digitalWrite(ledPin, HIGH);
delay(5000);
//digitalWrite(ledPin, LOW);
//delay(1000);
}

else {
  for (int thisNote = 0; thisNote < 15; thisNote++) {
  int noteDuration = 1400/noteDurations[thisNote];
  tone(speakerPin, melody[thisNote],noteDuration);
  int pauseBetweenNotes = noteDuration * 1.30;
  delay(pauseBetweenNotes);
}
}
    //noTone(speakerPin);
}




// The publish function is called every 1.5s

void publish(){
    
    // Publish something
    Particle.publish("Yunki", String(publishLight));
    // Increment counter
    publishLight;
}

other thing is fine… but the photocell input sensor seems not work.
Could you help me to solve this…?

What does that mean? What values are you getting in your "Yunki" publish under different conditions?

It looks like the Photoresistor is connected wrong. I don’t think you need the resistor or Black GND wire you have connected to the photoresistor.

Have you measured the resistance of your photo resistor?
I guess in combination with that 220Ohm resistor your readings will be well below your threshold of 1000 (of 4095 units).

BTW, you don’t need (and should not use) pinMode() when you only intend to do analogRead() on an A-pin.

I think what he has is correct; it's connected as a voltage divider circuit. The value of the resistor may be incorrect though.

1 Like

The voltage divider seems wired correctly

3v3
 |
photo resistor
 |------------------- A0
resistor (220)
 |
GND

but the 220Ohm seem too low for me