Project showcase

Start/Stop Chronometer © GPL3+

That's a two-module chronometer for your MTB (or any others sports) to measure your time in a determined circuit!

  • 368 views
  • 0 comments
  • 3 respects

Components and supplies

Apps and online services

About this project

Me and my friend are always in competition for something, in every sports, from ski to run, to MTB. I decided to build this Chronometer to have a precise measurement of the time spent to complete a pre-made circuit. You just have to choose a start and an end point, and place the two module (we 3D-printed a case for it because we soldered everything on a circuit board, you can also do this if you want something definitve) to start the competition.

Hope you have fun!

Credits for the wiring label to: https://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

Schematics

Start/RX
Make sure to wire everything as you see, 'cause the nRF24L01 needs to be wired in a certain way! I recommend you to check the label with the appropriate wiring for your board and library that i uploaded in the photos, so you can enjoy your chronometer at its fullest.
Cattura ue7bhngton
Stop/TX
As i already said, make sure that you follow the wiring label so you won't have any errors.
Cattura1 epyyo0s3x0

Code

Code for the Start/RXC/C++
This code will make the timer start when you pass in front of the UltraSonic Sensor.
#include <LiquidCrystal.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN 9
#define CSN_PIN 53

LiquidCrystal lcd(12, 11, 5, 4, 3, 10);

int trigPin = 6;
int echoPin = 7;
int greenLed = 38;
int redLed = 39;
int m;
int s;
int dc;
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[10];
bool newData = false;

void setup() {
  lcd.begin(16, 2);
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  digitalWrite(greenLed, LOW);
  pinMode(53, OUTPUT);
  Serial.begin(9600);
  Serial.println("SimpleRx Starting");
  radio.begin();
  radio.setDataRate( RF24_250KBPS );
  radio.openReadingPipe(1, thisSlaveAddress);
  radio.startListening();
}

void loop() {
  int duration;
  int distance;
  digitalWrite(redLed, HIGH);
  digitalWrite(trigPin, HIGH);
  delay(1);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance <= 100 && distance >= 0) {
    digitalWrite(greenLed, HIGH);
    while (digitalRead(greenLed) == HIGH) {
    tempo();
    getData();
    showData();
  }
}
}

void tempo() {

  
  lcd.setCursor(0,1);
  dc = dc + 1;
  lcd.print(m);
  lcd.print(":");
  lcd.print(s);
  lcd.print(".");
  lcd.print(dc);
  delay(100);
  

  if (dc == 9) {
  dc = 0;
  s = s + 1;
  }
  
  if (s == 60) {
  s = 0;
  m = m + 1;
  }
}

void getData() {
    if ( radio.available() ) {
        radio.read( &dataReceived, sizeof(dataReceived) );
        newData = true;
    }
}

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        digitalWrite(ledVerde, LOW);
        newData = false;
    }
}
Code for the Stop/TXC/C++
This code will make the green led on the arrive turn on, making the timer stop and the first green led turn off.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN 9
#define CSN_PIN 10

int trigPin = 3;
int echoPin = 4;
int ledVerde = 5;
char dataToSend[10] = "Message 0";
char txNum = '0';

RF24 radio(CE_PIN, CSN_PIN);

const byte slaveAddress[5] = {'R','x','A','A','A'};

void setup() {
  Serial.begin(9600);
  Serial.println("SimpleTx Starting");
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT);
  pinMode(greenLed, OUTPUT);
  digitalWrite(greenLed, LOW);
  radio.begin();
  radio.setDataRate( RF24_250KBPS );
  radio.setRetries(3,5); // delay, count
  radio.openWritingPipe(slaveAddress);
}

void loop() {
  int duration;
  int distance;
  digitalWrite(greenLed, LOW);
  digitalWrite(trigPin, HIGH);
  delay(1);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance <= 100 && distance >= 0) {
    digitalWrite(greenLed, HIGH);
    while (digitalRead (greenLed == HIGH)) {
    send();
 }
}
}

void send() {

    bool rslt;
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2

    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt) {
        Serial.println("  Acknowledge received");
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }
}

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}

Comments

Similar projects you might like

Pac-Man LED Pixel Panel Costume

Project tutorial by Ben Muller

  • 4,498 views
  • 3 comments
  • 78 respects

LoRa Gateway for DeviceHive

Project tutorial by DeviceHive IoT team

  • 1,156 views
  • 2 comments
  • 16 respects

IoT Bird Feeder with Sigfox and Tweeter

Project showcase by Gaël Porté

  • 326 views
  • 0 comments
  • 7 respects

Raspberry Pi and Arduino Laptop

Project tutorial by Dante Roumega

  • 17,563 views
  • 6 comments
  • 44 respects

SmartWay

Project tutorial by Universum

  • 173 views
  • 0 comments
  • 4 respects

Arduino-Based Automatic Guitar Tuner

Project tutorial by Ben Overzat

  • 3,168 views
  • 0 comments
  • 10 respects
Add projectSign up / Login