Please help.

I’m a noob to the Arduino and if I posted in the wrong place I’m sorry. I started three weeks ago and bought the ELEGOO stater kit for mega 2560. I have done most of the project of the. I thought I could start my project that I wanted to do and that is why I bought the starter kit.

I want a programmable timer to heat treat firing pins for bolt action rifles.

I found a program that I thought would be easy enough to make a few modifications and I would be done. Not as easy as it sounds.

I think I only need three changes to this program.

  1. Add two buttons, one to increase the time on timer, and the other is to decrease the time the timer and have it displayed on the LCD Screen. On the first time it runs it can say Heat treat done Timer=(variable) right now the time is an integer for 10 seconds but I figure out how to change the time or display the variable.

  2. Add a button AKA “Cycle Start” to start the timer, and relay. I cant figure that out either.

  3. After the timer is done I want the buzzer to go of a few seconds then be “ready for state” to change the time if needed and or “Cycle Start” to run the timer again. And have the LCD screen say Heat treat done Timer=(variable) until then.

//Arduino Self-Timer
//T.K.Hareendran
//www.electroschematics.com
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
int runTimer = 1;
int runFor = 10; // time in seconds
int buzzerPin = 13;
int relayPin=4;
int data = 0;

void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(relayPin,OUTPUT);
lcd.begin(16, 2);
}

void loop() {
if(runTimer == 1){
digitalWrite(relayPin,HIGH); // relay is OFF during countdown
/* *change to HIGH if you want the relay to be ON while countdowning /
lcd.clear();
lcd.print(“TIMER=”);
//Start timer
timer();
} else {
digitalWrite(relayPin,LOW); // relay is ON when time expired
/
*change to LOW if you want the relay to be OFF when the time expired */
}
runTimer = 0;
lcd.noDisplay();
delay(250);
for(int duration = 0; duration < 100; duration ++){
digitalWrite(buzzerPin, HIGH);
delayMicroseconds(500);
digitalWrite(buzzerPin, LOW);
delayMicroseconds(500);
}
lcd.display();
delay(250);
}

void timer() {
for(int timer = runFor;timer > 0; --timer){
if(timer >= 10) {
lcd.setCursor(6,0);
} else {
lcd.setCursor(6,0);
lcd.print(“0”);
lcd.setCursor(7,0);
}
lcd.print(timer);
lcd.print(" SECOND!");
delay(1000);
}
lcd.setCursor(0,0);
lcd.clear();
lcd.print(" HEAT TREAT DONE");
lcd.setCursor (0,1);
lcd.print(“TIMER=”);
lcd.print(" SECONDS");

}

heat_treat_version_15.ino (1.44 KB)

I think you are making the typical beginners mistake. Trying to do too much at once.
The sample Projects you already worked through probably contained a sample for a single push button.
Take that one and expand it to detect three different Buttons (to later be +, - and start).
Once that works, try to find a sample that simply Counts down, for example once per second from 10 to 0.
You have obviously already worked out how to do the Displays and start/stop the relay (again, the samples you already worked through probably had such a sample).
Once that’s all done, you are 90% there. Now all you Need to do is Combine everythig.

This is a somewhat complicated project - a lot going on. Your other issue is that the clock in an Arduino is not terribly accurate (which is one reason they are relatively cheap).

If you want to learn arduino, start with some simpler example code. What JaBa said.

If you want a programmable firing pin heater timer, head over to "Gigs and Collaborations" and see if anyone will do it for moneys. But really - if that's what you want then there are a dozen phone apps that will count down perfectly well and don't cost a bomb. The standard clock app on your phone will probably do it.

Start smaller. But having an end goal in mind is a great idea and helps keep you focused and motivated.

I got It.

//Arduino Self-Timer
//T.K.Hareendran
//www.electroschematics.com
//Modified for heat treat firing pins jbs3jason
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int runTimer = 1;
int buzzerPin = 13;
int relayPin = 4;
int data = 0;
int timeup = 1; // Increse time
int timedown = 2; // Decrease time
int start = 3; // Cycle start
int buttonState = 0;
int lastUpButtonState = LOW;
int lastDownButtonState = LOW;
int lastStartButtonState = LOW;
int b = 10;
int runFor = b; // time in seconds

void setup() {
const int set = 8;
pinMode(buzzerPin, OUTPUT);
pinMode(relayPin, OUTPUT);
pinMode(timeup, INPUT);
pinMode(timedown, INPUT);
pinMode(start, INPUT);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.clear();
lcd.print(" HEAT TREAT DONE");
lcd.setCursor (0, 1);
lcd.print(“TIMER=”);
lcd.print(" SECONDS");
}

void loop(){
buttonState = digitalRead(timeup);
if (buttonState != lastUpButtonState) {
if (buttonState == HIGH) {
b++ ;
}
lastUpButtonState = buttonState ;
displayTimeValue() ;
}

buttonState = digitalRead(timedown);
if (buttonState != lastDownButtonState) {
if (buttonState == HIGH && b > 2) {
b-- ;
}
lastDownButtonState = buttonState ;
displayTimeValue() ;
}

buttonState = digitalRead(start);
if (buttonState != lastStartButtonState) {
if (buttonState == HIGH)
runHeatTreatCycle(b) ;
lastStartButtonState = buttonState ;
displayTimeValue() ;
}
}

void displayTimeValue(){
lcd.setCursor(0, 0);
lcd.clear();
lcd.print(" HEAT TREAT DONE");
lcd.setCursor (0, 1);
lcd.print(“TIMER=”);
lcd.print(b);
lcd.print(" SECONDS");
}

void timer(){
for (int timer = runFor; timer > 0; --timer) {
if (timer >= 10) {
lcd.setCursor(6, 0);
} else {
lcd.setCursor(6, 0);
lcd.print(“0”);
lcd.setCursor(7, 0);
}
lcd.print(timer);
lcd.print(" SECOND!");
delay(1000);
}
}

void runHeatTreatCycle(int time) {
digitalWrite(relayPin, HIGH); // relay is On during countdown
lcd.clear();
for(int t = time; t > 0 ; t–){
lcd.print(" HEAT TREATING");
lcd.setCursor (0, 1);
lcd.print(“TIMER=”);
lcd.print(t);
lcd.print(" SECONDS");
digitalWrite(buzzerPin, HIGH);
delay(500);
digitalWrite(buzzerPin, LOW);
delay(500);
}
digitalWrite(relayPin, LOW); // relay is OFF during countdown
digitalWrite(buzzerPin, HIGH);
delay(3000);
digitalWrite(buzzerPin, LOW);
}