Spot welder coding issues

hi every baddie,
i have some troubles with my diy spot welder arduino code.

i am using a “encoder” to control a counter variable called (position), its a number witch is displayed in a lcd i2c scree.

i am all so using a solid state relay (SSR) to control a microwave transformer and a push-button as a trigger.

i came up with the code to control that variable (number) called “position “ and display it in the lcd screen.

and here is my problem :

i want to make that number (or the variable position) as a pulse duration and out-put it to the SSR corresponding pin. for that i will use a push-button as a triggering in-put (with a debouncing function).

And i don’t know how, it is something advanced for me for now; so come to ask for your help and advising generosity.

And here's my code so far

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include "EncoderStepCounter.h"

#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_ADDR 0x3C
#define ENCODER_PIN1 2
#define ENCODER_INT1 digitalPinToInterrupt(ENCODER_PIN1)
#define ENCODER_PIN2 3
#define ENCODER_INT2 digitalPinToInterrupt(ENCODER_PIN2)

//int SWITCH = 7;
//int SSR = 13;

EncoderStepCounter encoder(ENCODER_PIN1, ENCODER_PIN2);

Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();

display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Welcome");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 17);
display.println("This is");
display.println("a Spot");
display.println("welder");

display.display();

delay(3000);

encoder.begin();

attachInterrupt(ENCODER_INT1, interrupt, CHANGE);
attachInterrupt(ENCODER_INT2, interrupt, CHANGE);
}

void interrupt() {
encoder.tick();
}
signed long position = 0;

void loop() {
signed char pos = encoder.getPosition();
if (pos != 0) {
position += pos;
encoder.reset();
Serial.println(position);
}
display.clearDisplay();

display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("pulse:");
display.setTextSize(4);
display.setTextColor(WHITE);
display.setCursor(50, 30);
display.println(position);

display.display();

}

spot_welder.ino (1.59 KB)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.... :slight_smile:

  #include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include "EncoderStepCounter.h"

#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_ADDR   0x3C
#define ENCODER_PIN1 2
#define ENCODER_INT1 digitalPinToInterrupt(ENCODER_PIN1)
#define ENCODER_PIN2 3
#define ENCODER_INT2 digitalPinToInterrupt(ENCODER_PIN2)

//int SWITCH = 7;
//int SSR = 13;

EncoderStepCounter encoder(ENCODER_PIN1, ENCODER_PIN2);

Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);
void setup() {
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay();

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("Welcome");
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 17);
  display.println("This is");
  display.println("a Spot");
  display.println("welder");

  display.display();

  delay(3000);
 
  encoder.begin();
 
  attachInterrupt(ENCODER_INT1, interrupt, CHANGE);
  attachInterrupt(ENCODER_INT2, interrupt, CHANGE);
}

void interrupt() {
  encoder.tick();
}
signed long position = 0;


void loop() {
  signed char pos = encoder.getPosition();
  if (pos != 0) {
    position += pos;
    encoder.reset();
    Serial.println(position);
  }
display.clearDisplay();

   display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("pulse:");
   display.setTextSize(4);
  display.setTextColor(WHITE);
  display.setCursor(50, 30);
  display.println(position);

  display.display();



}

Would you help me plz

Alyoussefrou:
Would you help me plz

There is a spot welder on maker.com complete with code have a look at it.It uses a nano and a oled. I am looking for the url. Will post it ASAP

here it is

cheers!

Oh yah thank you its a ready cake.
I prefer making my own within the help of others
And that link is for a car battery spot welder not like mine it’s very different
Thank you sire