Skip to content

Instantly share code, notes, and snippets.

@Bloody-Badboy
Created February 7, 2024 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bloody-Badboy/9f03ae98bf2e3087b056a8ad3a73e831 to your computer and use it in GitHub Desktop.
Save Bloody-Badboy/9f03ae98bf2e3087b056a8ad3a73e831 to your computer and use it in GitHub Desktop.
Revived my cheap 12V Battery Storage Spot Welding Machine's dead MCU using Arduino Pro Mini https://imgur.com/a/Gro65kt
// https://imgur.com/a/Gro65kt
#define DEBUG 1
#if DEBUG == 1
#define log(s) Serial.print(s)
#define logln(s) Serial.println(s)
#else
#define log(s)
#define logln(s)
#endif
int autopulse_delay = 2000;
int mosfetPin = 6;
int ledPin = 5;
int autopulsePin = 3;
int btnPin = 2;
int buzPin = 4;
int pulseTime;
int pulseTimeShort;
int pulse_arr[] = { 7, 10, 13, 16, 19, 21, 24 };
int pulse_arr_length = sizeof(pulse_arr) / sizeof(int);
int pulseIndex = 0;
unsigned long buttonPressTime;
void setup() {
Serial.begin(9600);
pinMode(mosfetPin, INPUT_PULLUP);
pinMode(mosfetPin, OUTPUT);
digitalWrite(mosfetPin, HIGH);
pinMode(ledPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
pinMode(buzPin, INPUT_PULLUP);
pinMode(buzPin, OUTPUT);
digitalWrite(buzPin, HIGH);
pinMode(btnPin, INPUT_PULLUP);
pinMode(autopulsePin, INPUT);
digitalWrite(ledPin, LOW);
digitalWrite(buzPin, LOW);
delay(250);
digitalWrite(buzPin, HIGH);
}
//-------------------------------------------------------------------------------------------
void loop() {
read_pulse_time();
if (digitalRead(autopulsePin) == HIGH && pulseTime > 0) {
logln("Welding tips touched the nickel strip");
digitalWrite(buzPin, LOW);
delay(25);
digitalWrite(buzPin, HIGH);
delay(autopulse_delay);
double_pulse();
// Wait until switch has been released
do {
logln("Waiting for Welding tips to release.");
digitalWrite(mosfetPin, HIGH);
digitalWrite(buzPin, HIGH);
} while (digitalRead(autopulsePin) == HIGH);
logln("Welding tips released.");
// Delay before impulse can be triggered again
delay(1000);
} else {
digitalWrite(mosfetPin, HIGH);
digitalWrite(buzPin, HIGH);
}
}
//-------------------------------------------------------------------------------------------
void read_pulse_time() {
if (digitalRead(btnPin) == LOW) {
logln("Pulse power button pressed");
buttonPressTime = millis();
delay(300);
do {
logln("Waiting pulse power button to release.");
} while (digitalRead(btnPin) == LOW);
if (millis() - buttonPressTime > 800) {
logln("Long press detected");
pulseIndex = -1;
pulseTime = 0;
digitalWrite(ledPin, HIGH);
digitalWrite(buzPin, LOW);
delay(1000);
digitalWrite(buzPin, HIGH);
} else {
logln("Short press detected");
pulseIndex++;
if (pulseIndex >= pulse_arr_length) {
pulseIndex = 0;
}
pulseTime = pulse_arr[pulseIndex];
for (int i = 0; i <= pulseIndex; i++) {
digitalWrite(buzPin, LOW);
digitalWrite(ledPin, HIGH);
delay(150);
digitalWrite(buzPin, HIGH);
digitalWrite(ledPin, LOW);
delay(150);
}
digitalWrite(ledPin, LOW);
}
log("New pulse duration ");
log(pulseTime);
logln("ms");
} else {
if (pulseIndex >= 0) {
pulseTime = pulse_arr[pulseIndex];
} else {
pulseTime = 0;
}
}
}
void double_pulse() {
pulseTimeShort = (pulseTime / 8); // Impulse with 1/8 the time of pulseTime
if (pulseTimeShort < 1) // Makes the short pulse at least one millisecond
pulseTimeShort = 1;
log("Short pulse duration ");
log(pulseTimeShort);
logln("ms");
log("Pulse duration ");
log(pulseTime);
logln("ms");
digitalWrite(buzPin, LOW);
digitalWrite(mosfetPin, LOW);
delay(pulseTimeShort);
digitalWrite(mosfetPin, HIGH);
delay(pulseTimeShort);
digitalWrite(mosfetPin, LOW);
delay(pulseTime);
digitalWrite(mosfetPin, HIGH);
for (int i = 0; i < 2; i++) {
digitalWrite(ledPin, HIGH);
digitalWrite(buzPin, LOW);
delay(50);
digitalWrite(ledPin, LOW);
digitalWrite(buzPin, HIGH);
delay(25);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment