-2
int coilSetOne = 0;
int coilSetTwo = 1;
int coilSetThree = 2;
int coilSetFour = 3;
int switchInput = 4;

void setup()
{
  pinMode(coilSetOne, OUTPUT);
  pinMode(coilSetTwo, OUTPUT);
  pinMode(coilSetThree, OUTPUT);
  pinMode(coilSetFour, OUTPUT);
  pinMode(switchInput, INPUT);
}

void loop()
{
var switchMode = digitalRead(switchInput)
    if ( switchMode == HIGH ) {
        digitalWrite(coilSetOne, HIGH);
        delay(20);
        digitalWrite(coilSetOne, LOW);
        delay(10);
        digitalWrite(coilSetTwo, HIGH);
        delay(20);
        digitalWrite(coilSetTwo, LOW);
        delay(10);
        digitalWrite(coilSetThree, HIGH);
        delay(20);
        digitalWrite(coilSetThree, LOW);
        delay(10);
        digitalWrite(coilSetFour, HIGH);
        delay(20);
        digitalWrite(coilSetFour, LOW);
}}

If the arduino detects that the switch is powered, it should power the coils. They should stay on for 20m and the delay between coils turning on should be 10ms.

2
  • 2
    Include your code in the post, not out on a link. After you paste the code into your post, select it and click the code icon (or press ctrl-K) to get code-formatting. In your post, tell us what is going wrong, not just that something is wrong. Sep 5, 2016 at 3:49
  • Are you saying there should be a 10ms delay between switching each coil on, or a 10ms after the previous coil is switched off before the next is turned on? You haven't said what the problem you are seeing is so I'm going to vote to close until you can explain the problem. Sep 6, 2016 at 12:12

1 Answer 1

2

I ran your code, and the problem seems to be the "var" you declare, which is not an Arduino type. Use int instead. Also if you have PINs 0 and 1 as output, Using the Serial might prove difficult.

    int coilSetOne = 0;
    int coilSetTwo = 1;
    int coilSetThree = 2;
    int coilSetFour = 3;
    int switchInput = 4;

    void setup()
    {
     // Serial.begin(9600);
      pinMode(coilSetOne, OUTPUT);
      pinMode(coilSetTwo, OUTPUT);
      pinMode(coilSetThree, OUTPUT);
      pinMode(coilSetFour, OUTPUT);
      pinMode(switchInput, INPUT);
    }

    void loop()
    {
      int switchMode = digitalRead(switchInput); //Use int
     /* Serial.print(digitalRead(switchInput));
      Serial.print(" ");
      Serial.print(digitalRead(switchInput) == HIGH);
      Serial.print(" ");*/

      if ( switchMode == HIGH ) {
        Serial.print("#Triggered");

        digitalWrite(coilSetOne, HIGH);
        delay(20);
        digitalWrite(coilSetOne, LOW);
        delay(10);
        digitalWrite(coilSetTwo, HIGH);
        delay(20);
        digitalWrite(coilSetTwo, LOW);
        delay(10);
        digitalWrite(coilSetThree, HIGH);
        delay(20);
        digitalWrite(coilSetThree, LOW);
        delay(10);
        digitalWrite(coilSetFour, HIGH);
        delay(20);
        digitalWrite(coilSetFour, LOW);
      }
     // Serial.println();
    }

You didn't explain us the problem so I'm sorry if I missed the point.

2
  • So I should just switch PINS 1 and 0 to 5 and 6?
    – Zivicium
    Sep 5, 2016 at 17:40
  • yes, if you need to use the serial port; Also the program now compiles, but I can't know if it does just what you need.
    – sassoPera
    Sep 5, 2016 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.