#include <Wire.h>
#include <LiquidCrystal.h>
// Initialize the library by creating an instance
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int timedata = A0; // analog pin0 , a Potentiometer is connected with A0 pin of Arduino.
int timerawdata = 1; // stores the value coming from the Potentiometer.
int settime = 0; // time duration in milliseconds (initial value)
int startb = 0; // button to start the welding
int relay = 6; // the output relay
int ReadyLed = 1; // when this LED is turned ON, it means you can start the welding
int Sflag = 0; // stops the unnecessary repetition of code.
int spotcount = 0; // counts the amount of spot welds
int refresh = HIGH; // refresh the display
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(startb, INPUT_PULLUP);
digitalWrite(startb, HIGH);
pinMode(timedata, INPUT); // POTENTIOMETER CONNECTED
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
pinMode(ReadyLed, OUTPUT);
delay(100);
digitalWrite(ReadyLed, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SPOT WELDER");
lcd.setCursor(0, 1);
lcd.print("VERSION 1.0");
Serial.println("VERSION 1.0");
delay (3000);
lcd.clear();
}
void loop() {
if (timerawdata != analogRead(timedata)){
timerawdata = analogRead(timedata);
settime = map(timerawdata, 0, 1023, 1, 1000); // 0.1 to 1000 milliseconds
refresh = HIGH;
}
if (digitalRead(startb) == LOW){
digitalWrite(ReadyLed, LOW);
digitalWrite(relay, HIGH);
delay(settime);
digitalWrite(relay, LOW);
digitalWrite(ReadyLed, HIGH);
spotcount = spotcount + 1;
refresh = HIGH;
}
if (refresh == HIGH){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ON Time:");
lcd.print(settime);
lcd.print("ms");
lcd.setCursor(0, 1);
lcd.print("Pulses:");
lcd.print(spotcount);
if (spotcount > 0 && settime < 1000){
delay (1000 - settime);
}
Serial.println(settime);
refresh = LOW;
}
if (digitalRead(startb) == HIGH && spotcount != 0) {
spotcount = 0;
}
}