Hello all, I myself am fairly new to Arduino. I have already built several example projects
and am keen to expand on several project ideas I have.
The project I am working on currently, is a motor controller system
This will simulate the drive controls used in conveyor systems and other industrial applications.
The system will have 3 push buttons that activate the following:
Button 1-Motor start
Button2-Motor stop
Button3-Emergency stop
The system will also have 3 LEDs that indicate the following:
Green LED-Motor running
Orange LED-Motor stopped
Red LED-Emergency stop activated
The system runs as follows:
Press the start button, motor runs and green LED turns on.
Press the stop button, the motor stops and the red LED turns on.
Press the emergency stop button, the motor stops and both the orange and red LEDs turn on.
I have already written most of the code, however I am having a few issues.
I am unsure of the coding needed to start, stop, and E stop the motor using single momentary button pushes.
I have been experimenting with the "Switch code" to activate either a green or red LED but I haven't had much luck.
I have a Freetronics 2 ch motor shield that I will be using to control the motor. The example coding however, only seems to show how to make the motor run using commands from the serial monitor.
Below is the coding I have done so far.
//Arduino motor drive system
//By Paul Coller
/*The purpose of this sketch is to simulate the control system of a conveyor
drive system.
It comprises 3 inputs (motor start, motor stop, emergency stop) and
4 outputs (motor drive, motor running green LED, motor stopped orange LED,
emergency stop activated red LED)
When Button 1 is pressed, the motor starts and the green LED lights up.
When Button 2 is pressed, the motor stops and the orange LED lights up.
When Button 3 is pressed, the motor(if running) stops and the red LED lights up.
*/
int LED_PIN1 = 8;
int LED_PIN2 = 9;
int LED_PIN3 = 10;
int BUTTON_PIN1 = 11;
int BUTTON_PIN2 = 12;
int BUTTON_PIN3 = 13;
int motorPin = 7;
int val = 0;
void setup() {
pinMode(motorPin, OUTPUT);//Motor power
pinMode(LED_PIN1, OUTPUT);//Motor running
pinMode(LED_PIN2, OUTPUT);//Motor stopped
pinMode(LED_PIN3, OUTPUT);//Emergency stop activated
pinMode(BUTTON_PIN1, INPUT);//Start motor
pinMode(BUTTON_PIN2, INPUT);//Stop motor
pinMode(BUTTON_PIN3, INPUT);//Emergency Stop
}
void loop()
{
val = digitalRead(BUTTON_PIN1);
val = digitalRead(BUTTON_PIN2);
val = digitalRead(BUTTON_PIN3);
if (val == HIGH) {
digitalWrite(motorPin, HIGH);
digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
} else if (val == HIGH) {
digitalWrite(motorPin, LOW);
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN3, LOW);
} else (val == HIGH) {
digitalWrite(motorPin, LOW);
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN3, HIGH);
}
}
I hope I have explained things clearly
Thanks in advance
Paul