Hi all, finally the parts arrived from China..
I did modify the setup, I now have connect one direction of the motor to Normally Closed and the other direction Normally Open on the Relay board, Then I have another relay that feed 230V into the common on that relay. This way I can stop the bar half open in case something happens. See picture here
The code I am running is displayed below,can I make this code simpler somehow or improve it?
// constants won't change. They're used here to
// set pin numbers:
const int buttonPinSpritOpp = 9; // the number of the pushbutton pin
const int buttonPinSpritNed = 12; // the number of the pushbutton pin
const int buttonPinVinOpp = 10; // the number of the pushbutton pin
const int buttonPinVinNed = 11; // the number of the pushbutton pin
const int ledPinSpritOpp = 7; // the number of the pushbutton pin
const int ledPinSpritNed = 6; // the number of the pushbutton pin
const int ledPinVinOpp = 4; // the number of the pushbutton pin
const int ledPinVinNed = 3; // the number of the pushbutton pin
const int motorPinVin = A2; // the number of the motor pin
const int motorPinOnOff = A3;//
const int motorPinSprit = A0; // the number of the motor pin
int intCode =-1;
long startTime = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(motorPinSprit, OUTPUT);
pinMode(motorPinVin, OUTPUT);
pinMode(motorPinOnOff, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPinSpritOpp, INPUT_PULLUP);
pinMode(buttonPinSpritNed, INPUT_PULLUP);
pinMode(buttonPinVinOpp, INPUT_PULLUP);
pinMode(buttonPinVinNed, INPUT_PULLUP);
digitalWrite(motorPinSprit,HIGH);
digitalWrite(motorPinVin,HIGH);
digitalWrite(motorPinOnOff, HIGH);
Serial.begin(9600);
Serial.println("starting now...");
}
void loop() {
if ( Serial.available()) // Check to see if at least one character is available
{
startTime = millis();
char ch = Serial.read();
if( isDigit(ch) ) // is this an ascii digit between 0 and 9?
{
intCode = (ch - '0'); // ASCII value converted to numeric value
}
}
if (millis() -startTime> 2000 ){
intCode=-1;
}
if ((digitalRead(buttonPinSpritOpp) == HIGH && digitalRead(buttonPinSpritNed) == LOW) || intCode==1) {
digitalWrite(motorPinSprit,HIGH);
digitalWrite(motorPinOnOff,LOW);
digitalWrite(ledPinSpritOpp,HIGH);
digitalWrite(ledPinSpritNed,LOW);
Serial.println("Sprit opp");
}
else if ((digitalRead(buttonPinSpritOpp) == LOW && digitalRead(buttonPinSpritNed) == HIGH)|| intCode==2) {
digitalWrite(motorPinSprit,LOW);
digitalWrite(motorPinOnOff,LOW);
digitalWrite(ledPinSpritNed,HIGH);
digitalWrite(ledPinSpritOpp,LOW);
Serial.println("Sprit ned");
}
else{
digitalWrite(motorPinSprit,HIGH);
digitalWrite(motorPinOnOff,HIGH);
digitalWrite(ledPinSpritOpp,LOW);
digitalWrite(ledPinSpritNed,LOW);
}
if ((digitalRead(buttonPinVinOpp) == HIGH && digitalRead(buttonPinVinNed) == LOW) || intCode==3) {
digitalWrite(motorPinVin,HIGH);
digitalWrite(motorPinOnOff,LOW);
digitalWrite(ledPinSpritOpp,HIGH);
digitalWrite(ledPinSpritNed,LOW);
Serial.println("Vin opp");
}
else if ((digitalRead(buttonPinVinOpp) == LOW && digitalRead(buttonPinVinNed) == HIGH)|| intCode==4) {
digitalWrite(motorPinVin,LOW);
digitalWrite(motorPinOnOff,LOW);
digitalWrite(ledPinSpritNed,HIGH);
digitalWrite(ledPinSpritOpp,LOW);
Serial.println("Vin ned");
}
else if (intCode==0){
digitalWrite(motorPinOnOff,HIGH);
digitalWrite(ledPinSpritOpp,LOW);
digitalWrite(ledPinSpritNed,LOW);
Serial.println("Shutting off");
}
else{
digitalWrite(motorPinVin,HIGH);
digitalWrite(motorPinOnOff,HIGH);
digitalWrite(ledPinSpritOpp,LOW);
digitalWrite(ledPinSpritNed,LOW);
}
delay(400);
}
Thanks for all the input so far!