Vernier Software and Technology
Vernier Software & Technology
Arduino and Vernier Sensors

Photogate

Vernier Photogates provide a way to determine when an object passes a location. They are most often used to study free fall, collisions, speed of rolling objects, and period of a pendulum. You can also use them with the Arduino to trigger an action when the Photogate is blocked.

Plug the Photogate into the Digital 1 port on the Vernier Arduino Interface Shield or a Digital Protoboard Adapter wired to Arduino pins 2, 3, 4, and 5 as explained in the Connecting Vernier Sensors to the Arduino Using a Breadboard section. The VernierLib library does not support the Photogate, but the sample sketch, VernierTutorialPhotogate, illustrates how to read the status of the photogate, do timing, and display it on the Serial Monitor. This sketch will also turn on an LED (digital line D13) when the photogate is blocked.

/* VernierTutorialPhotogate (v2018)
 * This sketch will send a status message to the Serial 
 * Monitor on whether the Photogate is blocked or unblocked.
 * It lists the time that the photogate is blocked in microseconds since the program started running or
 * since the last time the counter overflowed.
 * It will also turn on the LED (pin D13) when the 
 * photogate is blocked.
 * 
 * Plug the Photogate into the Digital 1 port on the 
 * Vernier Arduino Interface Shield or into a Digital Protoboard 
 * Adapter wired to Arduino pins 2, 3, 4, and 5.
 */

int photogatePin = 2; //create global variable for pin assignment to sensor
int LEDpin = 13; //create global variable for pin assignment to LED
int photogateStatus; //create global variable for photogate status: LOW=blocked, HIGH=unblocked
int oldStatus = HIGH;
unsigned long timeus = 0; //Time in us

void setup() 
  {
   Serial.begin(9600);           // set up Serial library at 9600 bps
    pinMode(LEDpin, OUTPUT);
    Serial.println("Vernier Format 2");
    Serial.println("Photogate blocked times taken using Ardunio");
    Serial.print("Time");
    Serial.print("us");
  };// end of setup

void loop ()
{
  photogateStatus = digitalRead(photogatePin);//low when blocked
   if (photogateStatus == LOW)
   { 
    digitalWrite(LEDpin, HIGH);// turn on LED
        if (oldStatus == HIGH)
          {
          timeus = micros();
          Serial.println(timeus);
           }
   }
   else digitalWrite(LEDpin, LOW);// turn off LED
   oldStatus = photogateStatus;
 } ;// end of loop



You can also use Vernier Photogates with the sketch, VernierTutorialDropCount. This sketch counts the number of times an object passes through the photogate over a period of ten seconds.


Contents

Introduction

Vernier Engineering Contest

Vernier recognizes instructors for creative uses of Vernier sensors to introduce engineering concepts and/or practices. Vernier Engineering Award »

Go to top