# RFID sensor Arduino to Processing triggering video

**URL:** https://discourse.processing.org/t/rfid-sensor-arduino-to-processing-triggering-video/16137
**Category:** Electronics (Arduino, etc.)
**Created:** [December 5, 2019, 2:18am UTC](https://discourse.processing.org/t/rfid-sensor-arduino-to-processing-triggering-video/16137 "2019-12-05T02:18:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![GraceOD](https://avatars.discourse-cdn.com/v4/letter/g/977dab/32.png) [@GraceOD](https://discourse.processing.org/u/GraceOD)
#### Post date: [December 5, 2019, 2:18am UTC](https://discourse.processing.org/t/rfid-sensor-arduino-to-processing-triggering-video/16137/1 "2019-12-05T02:18:21Z")

</div>

Hi guys,

I am pretty new to Processing and Arduino so an help would be greatly appreciated.

I have set up an RFID sensor that is being read through my Arduino and I want to play a video through processing, when the RFID is scanned. I can get the video operating through Processing but I need some help on getting the RFID to trigger the video.

Here is my Arduino code

```auto
#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

int test1=4;
int test2=5;
int test3=6;
int test4=7;

void setup() {
   Serial.begin(9600); // Initialize serial communications with the PC
   while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
   SPI.begin(); // Init SPI bus
   mfrc522.PCD_Init(); // Init MFRC522
   delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
   mfrc522.PCD_DumpVersionToSerial();	// Show details of PCD - MFRC522 Card Reader details
   Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

void loop() {
 
 Serial.print(test1); // Send the first Value
 Serial.print(','); // Send a delimiter
 Serial.print(test2); // Send the first Value
 Serial.print(','); // Send a delimiter
 Serial.print(test3); // Send the first Value
 Serial.print(','); // Send a delimiter
 Serial.print(test4); // Send the first Value
 Serial.print(','); // Send a delimiter
 Serial.println(); // Send a carriage-return //// all of those serial prints are trevors code, sending values to processing
 
   // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
   if ( ! mfrc522.PICC_IsNewCardPresent()) {
   	return;
   }

   // Select one of the cards
   if ( ! mfrc522.PICC_ReadCardSerial()) {
   	return;
   }

   // Dump debug info about the card; PICC_HaltA() is automatically called
   mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

**** //// end of code ////

```

and here is my processing code:

```auto
import processing.serial.*; // Import the Processing Serial Library for communicating with arduino
import processing.video.*;

Movie video;

Serial myPort; // The used Serial Port
int test1;
int test2;
int test3;
int test4;
 void setup()
{
  
    println(Serial.list()); // Prints the list of serial available devices (Arduino should be on top of the list)
  myPort = new Serial(this, Serial.list()[2], 9600); // Open a new port and connect with Arduino at 9600 baud
  
  size(2000,2000);
  video = new Movie(this, "TheStoryofMicrofibers.mp4");
  

}

void movieEvent (Movie video){
  video.read();
}

void draw()
{
  image(video, 0, 0);

  print(test1);
  print(test2);
  print(test4);
  print(test3);
}

void serialEvent(Serial myPort) // Is called everytime there is new data to read
{
  if (myPort.available() > 0)
  {
    String completeString = myPort.readStringUntil(10); // Read the Serial port until there is a linefeed/carriage return
    if (completeString != null) // If there is valid data insode the String
    {
      trim(completeString); // Remove whitespace characters at the beginning and end of the string
      String seperateValues[] = split(completeString, ","); // Split the string everytime a delimiter is received
      test1 = int(seperateValues[0]);
      test2 = int(seperateValues[1]);
      test3 = int(seperateValues[2]);
      test4 = int(seperateValues[3]);
    }
  }
}

```

Any help would be great!

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [December 5, 2019, 6:57am UTC](https://discourse.processing.org/t/rfid-sensor-arduino-to-processing-triggering-video/16137/2 "2019-12-05T06:57:25Z")

</div>

Please format your code by choosing the edit pencil, then selecting all your code and pressing the \</\> button.  
For what I can see, you are only sending a beam of 4,5,6,7,\n nothing more. And in the Processing sketch you are printing values in draw(). That is good for a short test, but it’s a slow process, and can’t be used while playing a video. You can use a boolean if block in draw() waiting for the required incoming serial values, and then play the video in the else part, when received, and setting the boolean false.
