Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
4-Digit LED Display Tube, 7-segments, TM1637
Ultrasonic Sensor - HC-SR04 (Generic)
Software & Tools
Arduino IDE
Project description
Code
Push up counter code
Push up counter code
c_cpp
1#include <TM1637Display.h> 2//HC-SR04 3#define echoPin 2 4#define 5 trigPin 3 6#define resetPin 4 7 8// 4-digital display pins (Digital Pins) 9#define 10 CLK 8 11#define DIO 9 12TM1637Display display(CLK, DIO); 13 14float duration; 15 //micro second 16float d_cm; 17long numDisplay=100; 18boolean trigUp = false; 19boolean 20 trigDown = false; 21float counterPushUp=0; 22 23void setup() { 24 25// initialize 26 serial communication: 27 Serial.begin(9600); 28 pinMode(trigPin,OUTPUT); 29 30 pinMode(echoPin,INPUT); 31 // 32 pinMode(resetPin,INPUT_PULLUP); 33 // 34 35 display.setBrightness(4); 36 display.clear(); 37 delay(500); 38 display.showNumberDecEx(numDisplay, 39 false, true, 4, 0); 40} 41 42void loop() { 43 44 //reset by switch 45 if(digitalRead(resetPin)==0){ 46 47 trigUp=false; 48 trigDown=false; 49 counterPushUp=0; 50 } 51 52 53 // generate pusle trigger 54 digitalWrite(trigPin,LOW); 55 delayMicroseconds(2); 56 57 digitalWrite(trigPin,HIGH); 58 delayMicroseconds(10); 59 digitalWrite(trigPin,LOW); 60 61 // receive, convert time (us) to cm 62 duration = pulseIn(echoPin,HIGH); 63 64 d_cm = duration * 0.034/2.; 65 66 //trigger body 67 if (d_cm>15 && d_cm<=30){ 68 69 trigUp = true; 70 } else if (d_cm < 10){ 71 trigDown = true; 72 } else 73 if(d_cm >30) { 74 } 75 //counter 76 if (trigUp==true && trigDown==true){ 77 78 counterPushUp=counterPushUp+0.5; 79 trigUp=false; 80 trigDown=false; 81 82 } 83 //print 84// Serial.print(d_cm); 85// Serial.print(" --- "); 86// 87 Serial.println(counterPushUp); 88 display.showNumberDecEx(counterPushUp, false, 89 true, 4, 0); 90} 91
Push up counter code
Downloadable files
Push up counter schematic
Push up counter schematic

Push up counter schematic
Push up counter schematic

Documentation
Push up counter schematic fritzing
Push up counter schematic fritzing
Push up counter schematic fritzing
Push up counter schematic fritzing
Comments
Only logged in users can leave comments