Go Down

Topic: Simple switching circuit to pulse a motor? (Read 608 times) previous topic - next topic


So essentially what I am doing here is powering a small motor via a "digital" switch. What I would like to happen is that once the motor is switched on the motor is on for 7 seconds then off for 7 seconds continuously forever. If the switch is pressed then the motor and the cycle stops.

If the switch is pressed again then the whole thing kicks off again.

I am sure this should be really quite straight forward ? any help appreciated. I am not too sure how to interrupt the delay function?

Code: [Select]
int QTCPin = 12;      // select the input pin for the switch
int MotPin = 11; // select the outpin for the Motor circuit
int QTCval ;      // variable to store the value coming from the switch

void setup() {
 pinMode(QTCPin, INPUT);  // declare the Switch as an INPUT
 pinMode(MotPin, OUTPUT); //declare the Motpin as an OUTPUT

void loop() {

  QTCval = digitalRead(QTCPin);    // read the value from the PIN
if(QTCval== HIGH)  
         {digitalWrite(MotPin, HIGH);
         delay (1000*7);
         digitalWrite(MotPin, LOW);
          delay (1000*7);
         digitalWrite(MotPin, LOW);  


Go Up