Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Mod NatdaoPeter MaSarah HanKevin Vo
Published © GPL3+

Pushup Counter

Using Kemet SS-430 to count push up.

BeginnerFull instructions provided10 hours14,028

Things used in this project

Story

Read more

Custom parts and enclosures

Arduino with Breadboard case

Arduino with Breadboard case

Schematics

Pushup Counter Schema

Pushup Counter Schema

Prototype board

Prototype board

Code

Arduino UNO code

Arduino
Arduino UNO code for the pushup counter.
#include <WiFi.h>

char ssid[] = "YourWifi";     //  your network SSID (name)
char pass[] = "YourWifiPassword";    // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status
WiFiClient client;

int sensorPin = A1;    // select the input pin for the potentiometer
int ledPin = 2;      // select the pin for the LED
int buttonPin = 3;      // select the pin for the Button
int greenledPin = 4;      // select the pin for the LED
int buzzerPin = 5;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

unsigned long PyroRead = 0;
unsigned long IR_threshold = 198000;
// Note: SS-430 has two pulses of 200msec per detection.
// IR_threshold is in microsec (usec), therefore 198msec threshold

int Detected = LOW;
int IR_sensed = 0;

int pushupCount = 0;
char server[] = "192.168.1.12";    // name address for Google (using DNS)
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // declare the ledPin as an OUTPUT:
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  pinMode(greenledPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode (sensorPin, INPUT); // IR Sensor connected to A1
  pinMode (buttonPin, INPUT); // Button Pin

    // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);

  // if you're not connected, stop here:
  if ( status != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    while(true);
  }
  // if you are connected, print out info about the connection:
  else {
    Serial.println("Connected to network");
    //connected to network, blink it 3 times
    digitalWrite(greenledPin, HIGH);
    delay(500); 
    digitalWrite(greenledPin, LOW);
    delay(500); 
    digitalWrite(greenledPin, HIGH);
    delay(500); 
    digitalWrite(greenledPin, LOW);
    delay(500); 
    digitalWrite(greenledPin, HIGH);
    delay(500); 
    digitalWrite(greenledPin, LOW);
  }
}

void loop() {
  while ((IR_sensed < 2)) { //Break after 2 good triggers
    PyroRead = pulseIn(sensorPin, HIGH); //Measure trigger point
    Serial.println(PyroRead);  // stop the autonomous robot
    if (PyroRead > IR_threshold) { //Make sure trigger is over 198msec)
      IR_sensed++; //Mark as a good trigger
    }

    
    buttonState = digitalRead(buttonPin);
  
    if (buttonState == HIGH) {
      // turn LED on:
      digitalWrite(greenledPin, HIGH);
      String tmp;
      tmp = String(pushupCount);
      
      Serial.println("\nStarting connection to server...");
      // if you get a connection, report back via serial:
      if (client.connect(server, 3000)) {
        Serial.println("connected to server");
        // Make a HTTP request:
        client.println("GET /?pushup=" + tmp + " HTTP/1.1");
        client.println("Host: 192.168.1.12");
        client.println("Connection: close");
        client.println();
      }
      digitalWrite(greenledPin, LOW);
      pushupCount = 0;
    }
  }

  if (Detected == HIGH) { // Turn LED OFF if it was previous ON
    Detected = LOW;
    digitalWrite(ledPin, LOW);
    digitalWrite(buzzerPin, HIGH);
    delay(200);
    digitalWrite(buzzerPin, LOW);
    pushupCount += 1;
  }
  else {
    Detected = HIGH; // Turn LED ON if it was previous OFF
    digitalWrite(ledPin, HIGH);
  }

  PyroRead = 0; // Reset readings
  IR_sensed = 0;

  delay(200); // Accept triggers after a 200ms, the default takes about 200ms anyway
}

firebase relay code

JavaScript
relay firebase through local server
const http = require('http');
const url = require('url');
const querystring = require('querystring');
// Import Admin SDK
var admin = require("firebase-admin");
var serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://databaseName.firebaseio.com"
});
// Get a database reference to our blog
var db = admin.database();
var ref = db.ref("pushup");
ref.once("value", function(snapshot) {
console.log(snapshot.val());
});
const hostname = '192.168.1.12';
const port = 3000;
const server = http.createServer((req, res) => {
const queryObject = url.parse(req.url,true).query;
var dt = new Date();
var utcDate = dt.toUTCString();
if(queryObject != null && queryObject.pushup != null)
{
console.log(queryObject.pushup);
var newPostRef = ref.push().set({
count: queryObject.pushup,
time: utcDate
});
var postId = newPostRef.key;
console.log(postId);
console.log(utcDate);
}
//console.log(querystring.parse(queryObject));
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});

Kemet Test Code

Arduino
Testing using the hand written by Kemet, written on https://ec.kemet.com/blog/pyro-switch-hidden-ir-detection/
int Pyro = A1;
unsigned long PyroRead = 0;

unsigned long IR_threshold = 198000;

// Note: SS-430 has two pulses of 200msec per detection.

// IR_threshold is in microsec (usec), therefore 198msec threshold

int LED = 7;

int Detected = LOW;

int IR_sensed = 0;

void setup() {

pinMode (7, OUTPUT); //LED Connected to Pin 7

pinMode (A1,INPUT); // IR Sensor connected to A1

}

void loop() {

while ((IR_sensed < 2)){ //Break after 2 good triggers PyroRead = pulseIn(A1, HIGH); //Measure trigger point if(PyroRead > IR_threshold){ //Make sure trigger is over 198msec)

IR_sensed++; //Mark as a good trigger

}

}

if (Detected == HIGH){ // Turn LED OFF if it was previous ON

Detected = LOW;

digitalWrite(7, LOW);

}

else {

Detected = HIGH; // Turn LED ON if it was previous OFF

digitalWrite(7, HIGH);

}

PyroRead = 0; // Reset readings

IR_sensed = 0;

delay(1000); // Accept triggers after a second

Credits

Mod Natdao

Mod Natdao

1 project • 1 follower
Fitness
Peter Ma

Peter Ma

49 projects • 394 followers
Prototype Hacker, Hackathon Goer, World Traveler, Ecological balancer, integrationist, technologist, futurist.
Sarah Han

Sarah Han

13 projects • 79 followers
Software Engineer, Design, 3D
Kevin Vo

Kevin Vo

4 projects • 3 followers

Comments