Vincent ArthurCj Roberts
Published

Fitness Challenge

An easy-to-use system that counts how many pull-ups one can do in two minutes.

IntermediateFull instructions provided77
Fitness Challenge

Things used in this project

Hardware components

ELEGOO 37-in-1 Sensor Module Kit V1.0
ELEGOO 37-in-1 Sensor Module Kit V1.0
×1
Jumper wires (generic)
Jumper wires (generic)
×12
Photon 2
Particle Photon 2
×2
Ally Peaks DoorWay Pull Up Bar
×1
ZipTies
×3
Double Sided Tape
×1
Piece of Cardboard
×1
USB Cable, Mini USB Type B Plug
USB Cable, Mini USB Type B Plug
×2
Computer
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Google Sheets
Google Sheets

Hand tools and fabrication machines

Scissor, Electrician
Scissor, Electrician
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Schematics

Circuit Diagram for Circuit Board A & B

Code

IR Trigger Code

C/C++
Code detects if IR reciver is getting IR signal from the transmitter. If so then publishes an event for the motion counter code to activate. If the motion sensor is waiting for the IR event to be published then this photon will look for the IR signal to then send the event.
// Pins for IR emitter and receiver
const int irEmitterPin = D2;
const int irReceiverPin = D3;

// Timer to start ultrasonic sensor 5 seconds after IR detection
Timer startUltrasonicTimer(5000, startUltrasonic);

void setup() {
  // Initialize Serial communication
  Serial.begin(9600);

  // Initialize pins for IR emitter and receiver
  pinMode(irEmitterPin, OUTPUT);
  pinMode(irReceiverPin, INPUT);

  // Attach interrupt for IR detection
  attachInterrupt(irReceiverPin, irDetectHandler, FALLING);

  // Subscribe to the start ultrasonic event
}

void loop() {
  // Main loop - nothing to do here
}

// Function to start ultrasonic sensor 5 seconds after IR detection
void irDetectHandler() {
  Serial.println("IR Detected!");
  startUltrasonicTimer.start();
}

// Function to start the ultrasonic sensor
void startUltrasonic() {
  Serial.println("Starting Ultrasonic Sensor!");
  startUltrasonicTimer.stop();
  // Publish an event to start the ultrasonic sensor on the other device
  Particle.publish("startDetectionEvent", "VAPhoton2", PRIVATE);
}

// Handler for the start ultrasonic event on the other device
void startUltrasonicHandler(const char *event, const char *data) {
  startUltrasonic();
}

Motion Sensor Code

C/C++
This code is the code used for the motion sensor. It will begin detecting motion after the IR Sensor is triggered and then will count how many passes occur in front of it. If the IR sensor has not been triggered it will send a signal to the other Photon to look for the IR trigger.
#include <Particle.h>

// Pin for PIR Motion Sensor
const int pirPin = D3;

// Timer to stop detection after a 1-minute duration
Timer stopDetectionTimer(60000, stopDetection);

// Flag to indicate if the motion detection is active
bool motionDetectionActive = false;

// Flag to indicate if the detection count has been published
bool countPublished = false;

// Variable to count detections
volatile int detectionCount = 0;

void setup() {
  // Initialize Serial communication
  Serial.begin(9600);

  // Initialize pin for PIR Motion Sensor
  pinMode(pirPin, INPUT);

  // Subscribe to the start detection event from IT_Worked
  Particle.subscribe("startDetectionEvent", startDetectionHandler, "IT_Worked");
}

void loop() {
  if (motionDetectionActive && !countPublished) {
    // Check if motion is detected
    if (digitalRead(pirPin) == HIGH) {
      // Increment the detection count
      detectionCount++;
      Serial.println("Motion Detected!");
      delay(2000); // Adjust this delay based on your sensor's characteristics
    }
  }
}

// Function to start motion detection
void startDetection() {
  Serial.println("Motion Detection Started!");
  motionDetectionActive = true;
  countPublished = false; // Reset the flag
  detectionCount = 0; // Reset the detection count
  // Start the timer to stop detection after a 1-minute duration
  stopDetectionTimer.start();
}

// Function to stop motion detection
void stopDetection() {
  Serial.println("Motion Detection Stopped!");
  motionDetectionActive = false;

  // Check if the count has not been published yet
  if (!countPublished) {
    // Publish the total detection count
    Particle.publish("detectionCountEvent1", String(detectionCount), PRIVATE);
    countPublished = true; // Set the flag to indicate that the count has been published
  }
}

// Handler for the start detection event from IT_Worked
void startDetectionHandler(const char *event, const char *data) {
  startDetection();
}

Credits

Vincent Arthur

Vincent Arthur

1 project • 0 followers
Cj Roberts

Cj Roberts

1 project • 0 followers

Comments