Light Blocking Module / photo interrupter

  • Photoelectric sensor / photo interrupter

Below you can see the corresponding code:

An example of a project for the ky-010

//Author: Danny van den Brande, arduinosensors.nl
//Hello world! I made a simpel example on what you can do with the KY-010
//In this case we made a simpel alarm with a piece of plastic, 
//i used a atm card to put in the sensor any piece of plastic will work, 
//when you remove it the alarm will trigger and print a value and text in the serial monitor. 
//You can make it print on a lcd to, or for more advanced stuff make it send a sms or add relays, whatever you want it to do! 
int PhotoElectricSensor = A0; 
int buzzer = 7;
int RedLed = 4;
int GreenLed = 5;
int BlueLed = 6;
int val ;

void setup ()
{
  Serial.begin(9600);
  pinMode (buzzer, OUTPUT) ;
  pinMode (RedLed, OUTPUT) ;
  pinMode (GreenLed, OUTPUT) ;
  pinMode (BlueLed, OUTPUT) ;
}
void loop ()
{
  val = analogRead (PhotoElectricSensor) ;
  Serial.print(val);// printing the value in the serial monitor
  if(val < 50&& val < 500) 
  {
    Serial.println(" ATM CARD NOT PLACED");// Open the serial monitor to see this.
    digitalWrite (GreenLed, LOW);
    alarmsound(10);// Change if you want the alarm to last longer if card is removed
  }
  
  else if (val > 500 && val < 1023) 
  {
    Serial.println(" ATM CARD IN PLACE");// the alarm will not trigger and the green led will be on.
    digitalWrite (GreenLed, HIGH);

    
  }
 
  delay(1000);
}

void alarmsound(int duration){ // alarm section, alarm will flash red and blue when trigger, if not it will stay green.
  for (int p = 0; p < duration; p++){
for (int i = 0; i <80; i++) 
    {
      digitalWrite (buzzer, HIGH) ;
      digitalWrite (RedLed, HIGH) ;
      delay (1) ;
      digitalWrite (buzzer, LOW) ;
      digitalWrite (RedLed, LOW) ;
      delay (1) ;
    }
    for (int i = 0; i <100; i++) 
    {
      digitalWrite (buzzer, HIGH) ;
      digitalWrite (BlueLed, HIGH) ;
      delay (1) ;
      digitalWrite (buzzer, LOW) ;
      digitalWrite (BlueLed, LOW) ;
      delay (1) ;
    }
  } 

}


Specifications
Input Analog
Working voltage: 3.3v-5v

Write a review

Please login or register to review

Photoelectric sensor / photo interrupter

  • Webwinkel Keurmerk en klantebeoordelingen

  • 14 dagen bedenktijd 
  • Verzendkosten voor eigen rekening
  • Product Code: KY-010
  • Availability: 14
  • 2.29€

  • Ex Tax: 1.89€

Similar Products

Key Switch Button Module

Key Switch Button Module

Below you can see the corresponding code: An example project for the KY-004//Hello world! This time..

2.49€ Ex Tax: 2.06€

Rotary Encoder Module

Rotary Encoder Module

Below you can see the corresponding code: An example project for the Rotary encoder.  /* Autho..

2.29€ Ex Tax: 1.89€

Infrared Emission / Sender

Infrared Emission / Sender

Below the corresponding code:# Include <IRremote.h> int RECV_PIN = 11; / / define input pin o..

2.36€ Ex Tax: 1.95€

Analog Temp Sensor Module

Analog Temp Sensor Module

Below the corresponding code:#include <math.h>  int sensorPin = A5; // select the input ..

2.36€ Ex Tax: 1.95€