Push Up Counter Using Arduino

by TechnoFrost in Circuits > Microcontrollers

1212 Views, 2 Favorites, 0 Comments

Push Up Counter Using Arduino

maxresdefault (2).jpg

I am going to show you how to make a DIY push up counter with arduino and the ultrasonic sensor

Supplies

1. Arduino Uno

2. HC-SR04 Ultrasonic Module: https://amzn.to/2zLomJU

3. 4 Digital Display TM1637: https://amzn.to/30Qg2DK

4. Passive Buzzer: https://amzn.to/2BeYzu3

5. Switch: https://amzn.to/3hKNL7N

Wiring

Screenshot (707).png

Wiring is pretty straightforward, just follow the schematics given above and you will be fine

Coding

Screenshot 2022-10-08 010613.png

First of all we need to install the library

Open "Sketch" then go to "Library Manager" in the Arduino development software, then search for TM1637, and then install TM1637.


Enter the code given below

#include <TM1637Display.h>
//HC-SR04
//Youtube link: https://youtu.be/u9JauTRP_cc
#define echoPin  2
#define trigPin  3
#define resetPin 4


// 4-digital display pins
#define CLK 8
#define DIO 9
TM1637Display display(CLK, DIO);


float duration; //micro second
float cm;
long numDisplay=100;
boolean trigUp = false;
boolean trigDown = false;
float counterPushUp=0;
int buzzer=7;// Passive buzzer pin


void setup() {


  pinMode(buzzer,OUTPUT);
  Serial.begin(9600);
  pinMode(trigPin,OUTPUT);
  pinMode(echoPin,INPUT);
  pinMode(resetPin,INPUT_PULLUP);
  display.setBrightness(4);
  display.clear();
  delay(500);
  display.showNumberDecEx(numDisplay, false, true, 4, 0);
  
}
 


void loop() {
  
  //reset by switch
  if(digitalRead(resetPin)==0){
    trigUp=false;
    trigDown=false;
    counterPushUp=0;
  }
  digitalWrite(trigPin,LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(100);
  // receive, convert time (us) to cm
  duration = pulseIn(echoPin,HIGH);
  cm = duration * 0.034/2.;
  if (cm>15 && cm<=30){
    trigUp = true;
  } 
  else if (cm < 10){
    trigDown = true;
  } 
 else if(cm >30) {
  }
 
  if (trigUp==true && trigDown==true){
    counterPushUp=counterPushUp+0.5;
    trigUp=false;
    delay(500);
    tone(7,800,40);//buzzer pin 7 frequency 800 duration 500
    trigDown=false;
  }


  display.showNumberDecEx(counterPushUp, false, true, 4, 0);
}

Downloads

Testing

Connect the Arduino to the laptop, hit upload and do them push ups!!!


Keep tinkering!