Hello I'm working on project where I have to increment a motor at 200ms high and 800 ms low the chip I'm using is and L293d to control the speed and direction of the motor. The motor has to change directions after every five pulses and the total cycle frequency of the up and down cycle must be 3Hz.
I figured using a for loop to control my pulses and digitalWrite() since it allows for more control of the on and off times of the pulses. The code is as such so far I have commented out the downward movement for now but you can look at it if you wish, I'm just trying to get the motor to pulse down at the pulse widths as specified above. The code is as such so far:
int enablePin = 11;
int downIn1 = 10;
int upIn2 = 9;
void setup() {
// put your setup code here, to run once:
pinMode(downIn1, OUTPUT);
pinMode(upIn2, OUTPUT);
pinMode(enablePin, OUTPUT);
}
void loop()
{
digitalWrite(upIn2, LOW); //setting Up pin on L293d Low for downward movement
for(int i = 1; i<=5; i++) //loop to increment 5 pulses down
{
digitalWrite(downIn1, HIGH); //Pulse width of 200 ms
delay(200);
digitalWrite(downIn1,LOW); //off width of 800 ms
delay(800);
}
/*digitalWrite(downIn1, LOW); // setting down pin to low so, can begin moving upward
/*setMotor(speed, reverse); //reversing direction
delay(1000);
void setMotor(int speed, boolean reverse) //reverse direction of electrode to up
{
analogWrite(enablePin, speed);
digitalWrite(up, ! reverse);
digitalWrite(in2Pin, reverse);
for(int i = 1; i<=5; i++) //moving electrode upward
{
digitalWrite(upIn2, HIGH); //Pulse width of 200 ms
delay(200);
digitalWrite(upIn2,LOW); //off width of 800 ms
delay(800);
}*/
}
I've also provided the breadboard schematic and the chip profile below, as well as a logic table for the chip that shows directionality for when certain pins are high and low.
The logic table was obtained from:
The breadboard schematic was obtained from
https://learn.adafruit.com/assets/2488
I'm pretty new to arduino so any help would be appreciated. I'm going to work on it some more probably rewire the chip and see if maybe I missed something, but any help would be appreciated but this is just step one of a multi step project; let me know if my code is on the riight track or if is completely off. The bread board image that I provided I'm not using the potentimeter or the button at all so the only wiring in to the chip
Thanks
l293.pdf (281 KB)
Logic for L293d chip.pdf (295 KB)