newb with a problem

It has been awile since I was last here but I found some great help so I thought I would check back. I am trying to but together a sketch to run a home made electric motor and for what ever reason the code isn't working. The basics of the circuit are 2 inputs ( position sensors) and 2 outputs ( motor drive pulse) the other stuff in the code is for later improvement, motor needs to run before I add to the list of stuff. The trigger 1 and 2 inputs are normally HIGH and are pulled LOW by a npn via the position sensor. If needed I can try to post a pic of the hardware side? But this is what I have come up with... the triggers do pull down as seen on scope, but drive pins never go HIGH. Also I am using pin 15 and 17 so that I can use the sensor board v4 buckled connections. And also just trying to get trigger1/motor1 to work as the other half is the same just out of phase. Peace rawbush

// constants won't change. They're used here to set pin numbers

const int trig1 = 15; // sets trigger 1 to pin 15 aka anolog1 const int trig2 = 2; // sets trigger 2 to pin 2 const int drive1 = 17; // sets drive 1 to pin 17 aka anolog3 const int drive2 = 4; // sets drive 2 to pin 4 const int capcha = 5; // sets cap charge to pin 5 const int capdis = 6; // sets cap discharge to pin 6 const int PULSE =1000; // drive time on in ms

// plan to add more options later

// variables will change: int trig1State = HIGH; // variable for reading trigger 1 status int trig2State = HIGH; // variable for reading trigger 2 status

void setup() { pinMode(trig1, INPUT); // initialize the trigger 1 pin as an input pinMode(trig2, INPUT); // initialize the trigger 2 pin as an input pinMode(drive1, OUTPUT); // initialize the drive 1 pin as an output pinMode(drive2, OUTPUT); // initialize the drive 2 pin as an output pinMode(capcha, OUTPUT); // initialize the cap charge pin as an output pinMode(capdis, OUTPUT); // initialize the cap discharge pin as an output }

void loop() { // Read trigger inputs and fire motor cuircuit 1 digitalRead(trig1); // read trigger 1 input condition if (trig1 == LOW){ digitalWrite(drive1,PULSE); // On pulse -drive 1- to motor for PULSE ms

} // Read trigger inputs and fire motor cuircuit 2 digitalRead(trig2); // read trigger 2 input condition if (trig2 == LOW){ digitalWrite(drive2, PULSE); // On pulse -drive 2- to motor for PULSE ms } }

You need to go back and review how "digital write" works. Hint: the only valid output values are HIGH and LOW. "1000" won't work.

You need to read the source and see how "digitalWrite" works. "1000" will work exactly as well as "HIGH".

digitalRead(trig1);             // read trigger 1 input condition
 if (trig1 == LOW){
 digitalWrite(drive1,PULSE);

So, digitalRead returned the state of the trig1 pin. You discarded that value.

Then, you see if the pin number is equal to LOW. Since 15 is not equal to LOW, the if block is not executed.

Same problem with the other block of code in loop().

Well this code kinda works as it does turn the motor, just not the way intended. As for reading material is there more then what is found at http://arduino.cc/en/Reference/HomePage ?
the code

// constants won’t change. They’re used here to set pin numbers

const int trig1 = 15; // sets trigger 1 to pin 15 aka anolog1
const int trig2 = 2; // sets trigger 2 to pin 2
const int drive1 = 17; // sets drive 1 to pin 17 aka anolog3
const int drive2 = 4; // sets drive 2 to pin 4
const int capcha = 5; // sets cap charge to pin 5
const int capdis = 6; // sets cap discharge to pin 6
const int PULSE =500; // drive time on in ms

// plan to add more options later

// variables will change:
int trig1State = HIGH; // variable for reading trigger 1 status
int trig2State = HIGH; // variable for reading trigger 2 status
int drive1State = LOW; // sets drive 1 low
int drive2State = LOW; // sets drive 2 low
long previousMillis = 0; // will store last time drive was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)

void setup() {
pinMode(trig1, INPUT); // initialize the trigger 1 pin as an input
pinMode(trig2, INPUT); // initialize the trigger 2 pin as an input
pinMode(drive1, OUTPUT); // initialize the drive 1 pin as an output
pinMode(drive2, OUTPUT); // initialize the drive 2 pin as an output
pinMode(capcha, OUTPUT); // initialize the cap charge pin as an output
pinMode(capdis, OUTPUT); // initialize the cap discharge pin as an output
}

void loop()
{
if (millis() - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = millis();

// if the LED is off turn it on and vice-versa:
if (drive1State == LOW) {
drive1State = HIGH;
interval = PULSE;
} else {
drive1State = LOW;

}
// set the LED with the ledState of the variable:
digitalWrite(drive1, drive1State);
}

}

Well this code kinda works as it does turn the motor, just not the way intended.

What does it do, and what did you intend for it to do?

Thanks for the help, As for what it did do. The motor started turning automaticly, like it didn't wait for the trigger also it pulsed at random as the motor would stop and spin both directions at diffrent times. I do think that there is feed back in the trigger circuit causing this. When the motor pulses I think the coil is inducing a magnetic flux into the trigger coil and then it reads that as a trigger? I just ordered six hall efffect sensors to use them in the trigger circuit, this should eleminate the feed back.

What is suppose to happen: once power is applied to the arduino and also the motor (seperate power sources) turn the motor by hand to cause trigger to activate pulse the motor to create rotation trigg2/drive2 is same but out of phase of 1 repeat