College Project

Hi All.

I have this project to complete.

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.

Thanks in advance.

M

(deleted)

You're attending an academic institution - surely there must be someone who can advise you there?

Hi.

I see exactly where you think this is going.

Here is what I have so far.

I will post a pic of the circuit tomorrow.

Thanks

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
}
}
}

Don't institutes of technology teach you how to read a few simple instructions?

CODE TAGS?

int buttonState_Safety1 = 0;      // variable for reading the pushbutton status
int buttonState_Safety2 = 0;      // variable for reading the pushbutton status

Why do these variables need global scope?

int MotorPin = 9;

The other pins are constants - are you planning on changing this pin whilst the program is running?

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.

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?

What model Arduino are you using?

Thanks.. Tom... :)

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. :)

Ok Folks,

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.

Thank You

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.

Ray

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: https://www.visual-paradigm.com/solution/statemachine/

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

Ray

Ray's Projects

Thanks Ray Byrne.

I may have recieved good advice from others but you are the first that I can understand

luckyh1: Thanks Ray Byrne.

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.

Ray

Ok.

So how rubbish is my code and how do I learn?

Thanks

M

you need three momentary buttons.

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.

luckyh1: Ok.

So how rubbish is my code and how do I learn?

Thanks

M

how do you learn ?

one step at a time.

get an LED to light when you release your button.

have it stay on for 5 seconds after you release.

have a second LED go on when both other buttons are pressed.

as you get these things to work, it will make more sense to you.

and come back with what worked and what did not, we can help you over the rough spots.

luckyh1: Ok.

So how rubbish is my code and how do I learn?

Thanks

M

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

Read about those state-machines. You will see some good examples: http://playground.arduino.cc/Code/FiniteStateMachine

Section 8.2 may help with electrical switch logic Ray

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.

Hardware-wise, it’s pretty simple it seems to me:
Homework1.jpg

Add a shift register & 7-segment display if you want to display the countdown.