You are required to design a system which will control the operation of a saw in a mill. The saw will be replicated by a motor. Once a button is pressed (button should act as a switch) to turn on the saw, it should give the user a countdown from 5 to 0 when the saw is activated. The system however will not start after the counter reaches zero until the operator has demonstrated that his hands are away from the saw by pressing down on two buttons, proving his hands are clear of the cutting edge. If he has not done this during the 5 second window, the saw should not start and the system should reset. During operation, if it any stage either safety button is released, the motor should immediately stop and the
system should reset.
I think I may have to use something called millis to do the countdown timer. Especially how to write the code in the globals and get it to make the switches do what they are supposed to do. I have also been advised to use else statements. I have a code done out and a system wired up but it does not work. I have zero experience in this so any advice is welcome.
const int Safety1 = 12; // the number of the pushbutton pin that is for safety
const int Safety2 = 11; // the number of the pushbutton pin that is for safety
const int Starter = 10; // the number of the pushbutton pin that is for starting purpose
int MotorPin = 9; //The pin of the WIN LED.
int buttonState_Safety1 = 0; // variable for reading the pushbutton status
int buttonState_Safety2 = 0; // variable for reading the pushbutton status
int buttonState_Statter = 0; // variable for reading the pushbutton status
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.
If your switches are switching the Arduino input LOW, do you have PULL_UP resistors? Or you should activate the software PULL_UP resistors.
If your switches are switching the Arduino input HIGH, do you have PULL_DOWN resistors fitted?
luckyh1:
You are required to design a system which will control the operation of a saw in a mill. . Once a button is pressed (button should act as a switch) to turn on the saw, it should give the user a countdown from 5 to 0 when the saw is activated.
Your name is doctor evil and i claim my five pounds.
Here is the deal. I am looking for some advice from someone who perhaps can assist/guide me in successfully running the program and wiring the circuit. I am not looking to be held by the hand but you must understand the challenge Arduino presents if you do not have a flair for it. I would like to learn if anybody can guide me through the basics. Starting from the fundamentals. I am a worker so I will get to grips with it with some guidance.
AWOL:
You're attending an academic institution - surely there must be someone who can advise you there?
My thinking on this is that the profs are well aware of Arduino.cc and consider this forum to be both asset and distraction - a reference book that is filled with inaccuracy as well as accuracy.
Getting students to work through the forum noise to implement a given set of requirements is part of the training; social media is part of the solution... These students have a far different future than I did in 1969: information is everywhere, not just in a few cherished text references.
Code Tags are the icon in the upper right of your editing screen: the icon look like </> and you paste your code between the symbols.
const int Safety1 = 12; // the number of the pushbutton pin
that is for safety
const int Safety2 = 11; // the number of the pushbutton pin that is for safety
const int Starter = 10; // the number of the pushbutton pin that is for starting purpose
int MotorPin = 9; //The pin of the WIN LED.
int buttonState_Safety1 = 0; // variable for reading the pushbutton status
int buttonState_Safety2 = 0; // variable for reading the pushbutton status
int buttonState_Statter = 0; // variable for reading the pushbutton status
unsigned int a = 0; // variable
void setup()
{
pinMode(Safety1, INPUT); // Pin settings
pinMode(Safety2, INPUT);
pinMode(Statter, INPUT);
pinMode(MotorPin, OUTPUT);
}
void loop()
{
buttonState_Safety1 = digitalRead(Safety1); // Digitally reading switch condition
buttonState_Safety2 = digitalRead(Safety2);
buttonState_Statter = digitalRead(Statter);
if (buttonState_Safety1 == LOW || buttonState_Safety2 == LOW) // if safety buttons actives
{digitalWrite(MotorPin, LOW);}// Motor Pin Low
else
{
if (buttonState_Starter == LOW )
{
for(int b=0; b<6 ; b++)
{
digitalWrite(MotorPin, LOW); // Motor Pin Low
delay(1000); // delay of 1 sec
}
if (buttonState_Safety1 == HIGH|| buttonState_Safety2 == HIGH) // if safety buttons de actives
{digitalWrite(MotorPin, HIGH);} // Motor Pin high
}
}
}
luckyh1:
Once a button is pressed (button should act as a switch) to turn on the saw, it should give the user a countdown from 5 to 0 when the saw is activated.
The system however will not start after the counter reaches zero until the operator has demonstrated that his hands are away from the saw by pressing down on two buttons, proving his hands are clear of the cutting edge.
If he has not done this during the 5 second window, the saw should not start and the system should reset.
During operation, if it any stage either safety button is released, the motor should immediately stop and the
system should reset.
Once upon a time, prospective programmers drew crude little flow charts using plastic templates!
These days, we more often talk about state-machines:
An UNO is a microcontroller (not a microprocessor) and the "brains" can only do one-thing at a time. It is critically important to not write your code in a "blocking" fashion. So, do not do
delay(5000) ;
To represent 5 seconds since that line of code prevents the uC from doing any other checks.
Do some reading about Arduino nonblocking code. Draw a state-machine diagram. Google will provide numerous articles but prefix your query with "Arduino" or use Google's site search syntax:
Example
non blocking code site:arduino.cc
I may have recieved good advice from others but you are the first that I can understand
Retired now but once was a Corporate IT instructor.
All of our members are good eggs, some will however hound the hell out of you for not following forum rules. It is a P.I.T.A. but worth a read ... The topics are identified with a pushpin icon at the top of every sub-forum.
there is a simple sketch called button in your IDE examples that will let you do the button press part.
you are correct in that mills is part of the name. millis() is the function to get the system time
you can review the example in blink without delay to see how it works.
There are three actors in that play. you need to watch the one you care about least. not sure how to describe it better than that.
there is a little wraping of your mind around the concept.
if you want to add some bells and whistles....
buy some bells and whistles.
like a truck backing up... beep-beep-beep for that 5 seconds.
the a nice little blast if you release one of the buttons too early.
Well....
There is no substitute for experience (repeatedly). And in all my many years, I have never seen a program that could not be improved.
But you are using typed variables with descriptive names: that is good.
One thing I would recommend is that as you progress through various revisions, save the previous (working hopefully) version. You can "clean up" your hard-disk after you submit your project. I just finished a project (mini-Sniffer) a few months ago, and I went through 9 versions before I published:
Sniffer.ino, Sniffer1.ino, Sniffer2.ino, ... Sniffer9.ino
Here's a tip: Always use Tools > Auto Format on your code, especially before posting it to the forum. The automatic indentation can be very useful for troubleshooting and also makes your code much easier to read. If your professor will be looking at your source code I'm sure it wouldn't hurt your grade either.
Another tip: Always compile your code before posting it to the forum. Your code doesn't even compile because of some typos. Make the effort to fix the super simple easy issues so we can focus on helping you with the more complicated stuff.