Hi, im new to programming... but for school i have to make a model for our bridge design. i have a question on how to implement an emergancy stop in our code, does anyone have tips on the easiest way of doing this. We tried a power off switch but the teachers told us it is not allowed...It would also be a big help if anyone has tips on showing the stop in a flowchart
Thanks for all the help everyone!! we are going to try the interrupt
Do not put emergency stop in code. Use a complete power OFF switch because that is the safest method.
Welcome to the forum
The need for an emergency stop implies that it could be needed at any time under any circumstances. If that is the case then the only safe way to implement it is a physical switch that cuts power to the whole device.
Any solution involving code reading the state of an input to trigger the emergency stop relies on that code running as expected at all times. You cannot rely on that
thanks for the recomendation, that was our original idea but onfortunatly that is not allowed... the stop has to be in the code.
thanks for the recomendation, that was our original idea but onfortunatly that is not allowed... the stop has to be in the code.
And as for the flowchart, since IoT can be triggered at any step (or evens during a multi instruction step), you don’t check for an emergency stop at every step. It’s treated as a global, asynchronous interrupt.
The usual method is to place an external event symbol with a dashed arrow leading to an EMERGENCY STOP terminator, showing it can trigger anytime, outside the normal sequence. The diagram assumes the system or operator will act on it immediately when necessary.
You could also research Event-Driven Process Chain (EPC) diagram
So where are you stuck ?
You need to arrange the code so that the emergency stop button is read as often as possible. That means no use of delay() or long for loops or while loops in the code that would cause the emergency stop input from being read
What is the purpose of the project, what hardware are you using and what code have you written ?
Our model needs to run completly on its own (open and close id motion is detected) would that be possible with the methode your recomending? if so do you have tips where i can research and learn (sites/ youtube chanels)
You should challenge whoever said that and say
- what if the code has a bug or is stuck in a long running calculation?
- What if the chip crashes for some reason ?
Emergency stops should be immediately effective and not depend on other systems.
If you need to have it in code then it’s just a button you need to deal with. Make sure you write non blocking code and let the loop() run as fast as possible.
you might benefit from studying state machines. Here is a small introduction to the topic: Yet another Finite State Machine introduction
the project uses LED (about 20), 3 servo and 3 Motion detectors, our current idea is to write in the code before every step to check if the stop is pressed. my biggest question is if there is a way of writing the code to make the bridge stop opening if the emergency stop is pressed halfway opening
Thanks! i will start researching! The reason they gave us for banning the power off switch was because it would me to easy....
How is the bridge opening handled in the code ? Is it done as a number of steps using a for loop, for instance ? If so then that is not a good way to do it. Instead, let the loop() function do what its name suggests and on each iteration of loop(), check whether it is time for the next step.
It sounds like your project would benefit from being written as a state machine. Only execute the code for the current state, ie bridge opening or bridge closing but always execute the code to test the emergency stop input. If an emergency stop input is detected then move to the emergency state, stop moving the bridge and do whatever is appropriate at that point
As a matter of interest, how are the servos powered in your project ?
That’s how professional systems are done ➜ easy = security in that case
Whoever is telling you that does NOT know what they are talking about. I am an industrial electrician and I am telling your instructor he/she is dead wrong and if I discover their identity will be reported.
An EMERGENCY switch is a mechanical disconnect breaking all phases mechanically. It must be red and very visible mounted near the machinery it controls.
It is possible to have an upstream CONTACTOR that is electronically controlled and can be tripped by one of several sensors or other remote switches. One such situation is fire suppression. If a heat/smoke detector is triggered, besides causing the fire retardant to be released it also sends a signal to trip the mains contactor since waiting for a human to trip the emergency off may take to long. I am sure there are other scenarios, but your instructor needs to word the assignment very carefully.
"Emergency" is a distracting name because it implies it is for safety, and cutting power is the right answer for a safety issue. If someone dropped a coin into the circuit causing it to misbehave and the bridge was going to crush someone, cutting power is right "Emergency" action. Operators can't depend on the coding to save life & limb.
Maybe think of your software-affecting button as an "abort" or "halt" or "stop" button and do the state-machine stuff per:
Flow-chart wise, maybe write a tight loop checking if the bridge is still moving, and include the button checking in that loop.
Your other topic on the same subject deleted.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
Thank you.
Consider how your code will recover after any emergency stop, whether power off or just a software switch. How are you going to know the state of operation of your bridge so it can either be reset or can be continued from where the stop occurred?
we still need to start building the scale model itself, so were not completely sure of how we are going to power the servo... the way we have started writing our code and making the flowchart is before every step to check if the emergency button is pressed, however this would mean that if the button is pressed halfway during opening the bridge will continue opening and only stop after it is finnished... i have done some research online and have found out about an "interrupt" but i have a few questions.... first of all would this be something you would recommend for my project?
second of all does this methode actually stop what the arduino is reading/doing immedietly or does it finnish for example turning the servo.
Also would it be possible that if the emergency button is pressed and the program interrupted to add 2 buttons for manual opening and closing?
after the "emergency" is over the code needs to continue what is was doing.
Now i have done some research online and have found out about an "interrupt" but i have a few questions.... first of all would this be something you would recommend for my project?
second of all does this methode actually stop what the arduino is reading/doing immedietly or does it finnish for example turning the servo.
Also would it be possible that if the emergency button is pressed and the program interrupted to add 2 buttons for manual opening and closing?