ardutronic
Published © CC BY-NC-SA

How I Made My Own Boxing Machine?

I just always liked boxing machines! It is an interesting option for family meetings or competition among friends.

IntermediateFull instructions provided10 hours5,505
How I Made My Own Boxing Machine?

Things used in this project

Hardware components

SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Arduino Nano R3
Arduino Nano R3
×1
SparkFun 7-Segment Serial Display - Red
SparkFun 7-Segment Serial Display - Red
×1
Relay Module (Generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Boxer

Schematics

Boxer

Code

Code

Arduino
int button = 12;
int pressed;
int state;
int stateK;
int stateK2 = 1;
int relay = 7;
int kontakt = 10;

unsigned long currentTime;
long startTime;
long endTime;
int Time;
int showTime;
int showTime2;

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

#include <TM1637Display.h>
// Define the connections pins:
#define CLK 4
#define DIO 3
// Create display object of type TM1637Display:
TM1637Display display = TM1637Display(CLK, DIO);
// Create array that turns all segments on:
const uint8_t data[] = {0xff, 0xff, 0xff, 0xff};
// Create array that turns all segments off:
const uint8_t blank[] = {0x00, 0x00, 0x00, 0x00};

void setup() {
  pinMode(relay, OUTPUT);
  pinMode(button, INPUT);
  pinMode(kontakt, INPUT);
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  myservo.attach(5);  // attaches the servo on pin 9 to the servo object

  Serial.begin(9600);
  myservo.write(150);
  digitalWrite(relay, LOW);
  display.clear();
    display.setBrightness(7);
    display.setSegments(data);
  delay(1000);
  display.clear();
}

void loop() {
  state = digitalRead(button);
  stateK = digitalRead(kontakt);

  currentTime = millis();
  if (state == HIGH)
  {
    delay(30);
    myservo.write(0);
    delay(200);
    digitalWrite(relay, HIGH);
    delay(1000);
    myservo.write(150);
    delay(300);
    digitalWrite(relay, LOW);
    pressed++;
    delay(2000);
  }

  if (state == LOW)
  {
    digitalWrite(relay, LOW);
    myservo.write(150);
  }

  if (pressed == 1)
  {
    if (endTime == 0)
    {
      showTime2 = 0;
      falling();
      rising();
      Serial.println(stateK);
      display.showNumberDec(showTime2);
    }
    if (endTime >= 1)
    {
      showTime = map(Time, 0, 400, 1, 999);
      showTime2 = (1100 - showTime);
      Serial.println(Time);
      if(showTime2 >= 999)
      {
        showTime2 = 999;
      }
      display.showNumberDec(showTime2);
      delay(5000);
      pressed = 0;
      Time = 0;
      startTime = 0;
      endTime = 0;
    }
  }
}

void falling() //wykrywa 0
{
  if (stateK != stateK2) //wykrylo 0
  {
    if (stateK == LOW)
    {
      startTime = currentTime;
      stateK2 = stateK; //k2 = 0
    }
  }
}

void rising() //wykrywa 1
{
  if (stateK != stateK2) //wykrylo 1
  {
    if (stateK == HIGH)
    {
      endTime = currentTime;
      stateK2 = stateK; //k2 = 1
      Time = (endTime - startTime);
    }
  }
}

Credits

ardutronic

ardutronic

39 projects • 39 followers
I'm 20 years old student of electronic technical college. I'm passionate about electronics as well as editing movies

Comments