glerumkyle
Published © GPL3+

Pushup Counter, helps with stay-at-home training!

This simple arduino project counts every push up you do and displays it on an LCD. It also provides visual and auditory support.

BeginnerShowcase (no instructions)5,255
Pushup Counter, helps with stay-at-home training!

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
all microcontrollers work if they have at least 11 digital and 1 analog input!
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Buzzer, Piezo
Buzzer, Piezo
×1
Button
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Pushup Counter Connections

Fritzing Schematic

Code

Arduino IDE code

Arduino
the code for the pushup counter
/* PUSH UP COUNTER
BY: Kyle Glerum

An ultrasonic sensor measures the distance between you and your head, if the distance is larger than 20 cm a rgb-led will shine red,
if the distance is between 10 and 20 cm, it turns magenta
and if it is less than 10 cm it turns blue, and a point appears on a lcd screen.
Every ten pushups it makes a sound.
You can reset the score with the push of a button.
 */
 
#include <LiquidCrystal.h> // include LCD library

#define BLUE 12 // define RGB-led pins
#define RED 10

const int trigPin = 8; //set pins for the ultrasonic sensor, button and buzzer
const int echoPin = 9;
const int buttonPin = A0;
const int b = 13;

long duration; // set integers
int distance;
int i;
int buttonState = 0;
int x = 1;
int y = 1;

LiquidCrystal lcd(6, 7, 2, 3, 4, 5); // set lcd pins

void setup() {
  Serial.begin(9600); // begin in 9600 baud 
  
  pinMode(trigPin, OUTPUT); //set pin modes
  pinMode(echoPin, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(b, OUTPUT);
  pinMode(RED, OUTPUT);
  pinMode(BLUE, OUTPUT);

  lcd.begin(16, 2); // begin lcd, define scale of lcd (16 places in a row, 2 rows)
  lcd.print("Push Ups:");



}

void loop() {
  digitalWrite(trigPin, HIGH); // send out an ultra sonic sound for 10 microseconds and measure the time it took for the sound to go from the trigpin to the echo pin
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034/2; //convert the time the signal took to travel to distance in cm

  if (distance >= 20) {digitalWrite(RED, HIGH); //configure RGB-led to burn red, magenta or blue depending on distance
                       digitalWrite(BLUE, LOW);}
  if (distance <= 20) {digitalWrite(BLUE, HIGH);}
  if (distance <= 10) {digitalWrite(RED, LOW);}

  if (i == (10 * y) && x == (1 * y)) { //this if statement plays a sound every ten pushups
                 tone(b, 146.8);
                 delay(50);
                 noTone(b);
                 delay(100);
                 tone(b, 146.8);
                 delay(50);
                 noTone(b);
                 delay(50);
                 tone(b, 293.7);
                 delay(100);
                 noTone(b);
                 x ++;
                 y ++;
  }
  else if (distance <= 10) {delay(350);} //this if else statement makes sure that the time between pushup-readings always stay the same
  
  buttonState = digitalRead(buttonPin); //these lines of code resets every integer and the lcd to the original state by the press of a button
  if (buttonState == HIGH) {
    i = 0;
    x = 1;
    y = 1;
    lcd.setCursor(0,1);
    lcd.print("0      "); } 
    
  lcd.setCursor(0, 1); // set cursor on the second row
  
  if (distance <= 10 ) {i ++;} //print a point if a pushup has been done
    lcd.print(i,DEC);                 
         
  while (distance <= 10) { //if the distance stays smaller then ten for a while, this piece of code makes sure that only one point is given for one pushup
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
      duration = pulseIn(echoPin, HIGH);
      distance = duration * 0.034/2;
  delay(100);}
}

Credits

glerumkyle

glerumkyle

1 project • 0 followers

Comments