Recycled Sensors

Our goal is to reuse (recycle) a system made up of two Vernier photogates.For this we built an interface that allows the connection of photogates and sending data to a mobile phone or to a Raspberry PI by bluetooth.

We used an Arduino Uno card, a Sparkfun vernier Interface shield, an Itead bluetooth shield and a Raspberry PI 3B.

We installed the photogates in a recycled acrylic tower

With the arduino board connected to a PC (it is crucial that the shields are physically separated from the Arduino board) we transfer the following code to the board (This code is based on those on SparkFun and Arduino websites and added and improvement for our purpose)

#include <SoftwareSerial.h> 
SoftwareSerial Azul(0,1); // RX | TX Cria uma porta série (UART) virtual
unsigned long TimeA = 0;
unsigned long TimeB = 0;  //variáveis do tempo
unsigned long TimeC = 0;
int PhotogatePin =6; //Sensor A
int PhotogatePinb =2; //Sensor B
int LEDpin =13; //LED
boolean FlagA = false; //Guarda se já passou no ponto A
boolean FlagB = false; //Guarda se já passou no ponto B

void setup() {
    Azul.begin(9600);  //Baud Rate para a porta série Azul 
    pinMode(LEDpin, OUTPUT); 
    Serial.println("Vernier Arduino");
    Serial.println("Tempo de feixe interrompido na photogate");
    Serial.print("\t"); //tab character
    Serial.println ("Tempo"); //change to match sensor
    Serial.print("\t"); // tab character
    Serial.println ("microsegundos");
void loop () {
   //Quando passa alguma coisa no A
   if (digitalRead(PhotogatePin) == LOW) { //Caso o sensor seja ativado
      digitalWrite(LEDpin, HIGH); //Ativa o LED
      TimeA = millis(); //Tempo atual
      //Espera que o objeto passe completamente por A
      //Faz com que o código seja executado apenas uma vez por cada objeto que cai
      while (digitalRead(PhotogatePin) == LOW) {
      TimeA = millis() - TimeA; //A = Tempo atual - Tempo inicial A
      TimeC = millis(); //Guarda o tempo inicial de C

      //Mensagens consola
      Serial.print("A - ");
      FlagA = true; //Regista que o objeto passou em A

   //Semelhante ao if anterior mas para B
   else if (digitalRead(PhotogatePinb) == LOW) { 
      digitalWrite(LEDpin, HIGH);
      TimeB = millis();
      while (digitalRead(PhotogatePinb) == LOW) { //Pause
      TimeB = millis() - TimeB;
      Serial.print("B - ");
      FlagB = true;

   //Caso o objeto tenha passado por A e B
   if ((FlagA == true) && (FlagB == true)) {
      //Reset das flags
      FlagA = false;
      FlagB = false;

      //C = Tempo inicial C - Tempo atual
      //Tempo inicial e tempo atual são medidos quando o objeto sai do sensor A e B, e não quando entra nestes
      TimeC = millis() - TimeC; 
      Serial.print("C - ");
   else digitalWrite(LEDpin, LOW); //Desliga o led
// Feed any data from bluetooth to Terminal.
 // if (Azul.available())
  // Serial.write( and
  // Serial.println(",");

   // Feed all data from terminal to bluetooth
  if (Serial.available())
 } ;

Then we dedicated ourselves to the bluetooth shield.

The DAT-CMD cursor must be in DAT mode.

In the UART multiplexer the following jumper connections must be placed: D0-RX and D1-TX, in order for the board to work in UART mode. These connections (D0 and D1) are among the few that are free on SparkFun's shield.

Finally we put the SparkFun shield on top of the bluetooth shield and set up the following set.

Attention: Whenever it is necessary to (re)load the code on the arduino board, it is necessary to have this procedure: power off the board, physically remove the shields; power on the board; load the code; power off the board, physically reposition the shields; power on the board; and it already is.

Now we have to connect the photogates to Arduino. The photogate plugs are BTD (digital), so we connected the top photogate to the Digital 1 connector and the bottom photogate to the Digital 2 connector (SparkFun shield BTD connectors).

And that's it

Now the data:

On our mobile phone we have downloaded the Serial Bluetooth Terminal app.

We have connected the mobile phone to the itead name device with the secret password (1234). We hit the call button and it's done.

Or install a serial terminal application on Raspberry PI (RPI) LXTerminal and connect it to ited device.

Follow these steps:

Open LXTerminal in RPI

1 - Install serial terminal app "minicom"

[pi@raspberrypi:~ $] sudo apt-get install minicom -y

2- launch bluetoothctl

[pi@raspberrypi:~ $] bluetoothctl

3- Find your itead device

[bluetooth]# agent on

[bluetooth]# default-agent

[bluetooth]# scan on

your device is xx:xx:xx:xx:xx:xx itead

4 - Pair RPI to itead

[bluetooth]# pair xx:xx:xx:xx:xx:xx

5 - connect itead to the serial port and start minicom app

[pi@raspberrypi:~ $] sudo rfcomm bind 0 xx:xx:xx:xx:xx:xx

[pi@raspberrypi:~ $] sudo minicom -D /dev/rfcomm0

To confirm connection cross the photogates with one hand, starting with the top one.

Values appear on app screen (in Serial Bluetooth Terminal app in the mobile phone or in minicom app in RPI LXTerminal .

A - time interval value measured in top photogate;

B - time interval value measured at low photogate;

C - time interval value measured between the two photogates.

As an example of using this system we measure the acceleration of gravity so we share a procedure for that purpose

guia do dia inglês.docx