使用使用Arduino和超声波传感器的俯卧撑计数器和超声波传感器的俯卧撑计数器-项目开发项目开发
Components and supplies
Arduino UNO
× 1
Ultrasonic Sensor - HC-SR04 (Generic)
× 1
Jumper wires (generic)
× 1
4-Digit LED Display Tube, 7-segments, TM1637
× 1
Apps and online services
Arduino IDE
About this project
I like to push-up the exercise. I do it about 10 times at a time, but sometimes I get tired and don't make the right move down and up high enough, and I don't remember the
number of times. So I made a counter to follow the rules. I choose arduino to be the control circuit, an ultrasonic sensor to determine the number of times the body goes up and
down an 7 segment display to show the result. The counter can be reset for next time.
I hope that you like this project. And subscribe my youtube channel.
Thanks for your watching!!!
Code
Push up counter code
Push up counter code C/C++
#include <TM1637Display.h>
//HC-SR04
#define echoPin 2
#define trigPin 3
#define resetPin 4
// 4-digital display pins (Digital Pins)
#define CLK 8
#define DIO 9
TM1637Display display(CLK, DIO);
float duration; //micro second
float d_cm;
long numDisplay=100;
boolean trigUp = false;
boolean trigDown = false;
float counterPushUp=0;
void setup() {
// initialize serial communication:
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;
}
// generate pusle trigger
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
// receive, convert time (us) to cm
duration = pulseIn(echoPin,HIGH);
d_cm = duration * 0.034/2.;
//trigger body
if (d_cm>15 && d_cm<=30){
评论0