Hello, first time arduino user here(probably relevant)
The board I use is Arduino Uno R3(probably not important)
I set up a L293d motor control circuit thing on a breadboard, i think i got the connections right. It worked a few times. It was stuck in a loop when it worked, on for like 10 seconds(there was only 2500 ms delay in code tho) off for some time and repeat. While I was pressing the reset button it didn't work but when I released the button it worked again.
I want to control the motor so constant loop is no good. Since I have seen the circuit is working, I think the problem with me being unable to control the motor is my code. Basically I want to have two kinds of Input for two directions motor can rotate. I tried to use serial monitor, it kinda works. When I input 0 or 1 i get no answer and when I input anything else it gives me an error message which is intended.
If you aren't familiar with l293d, relevant info here is i need to have a constantly 5v output to enable the circuit and two outputs working like an XOR . While XOR is 1 motor works.
Anyways, here is the code, I didn't comment it but it is easy to follow;
int motorPin1 = 9;
int motorPin2 = 10;
int logicPin = 8;
void setup() {
Serial.begin(9600);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(logicPin, OUTPUT);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(logicPin, HIGH);
}
void loop() {
if(Serial.available() > 0)
{
int SerialInput = Serial.parseInt();
switch (SerialInput)
{
default:
Serial.println("Error!");
break;
case 0:
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
delay(1000);
digitalWrite(motorPin1, LOW);
delay(1000);
break;
case 1:
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
delay(1000);
digitalWrite(motorPin2, LOW);
delay(1000);
break;
}
}
}