Hello! i want to make a small project in which when a car detects an obstacle in front of it the DC motors stop rotating and as soon as the obstacle is removed, it starts working again. I have made a circuit and written a code, but as this is my first project i am very new to this and i think there's a problem in either one of those. I am using a PIR motion sensor connected to an Ardiuno Uno which is connected to a L293D motor driver IC which drives 2 DC motors.
Right now, when i simulate my circuit the motors run only for 2-3 seconds when the object in front of the sensor is removed and then they completely stop. After that, when the object is places again in front of the sensor, The motor does the same thing! It again works for 2-3 seconds when it shouldn't.
I will attach my circuit diagram( Sorry its a little messy) and my code that i wrote. Should i try using a different sensor? Any and all Inputs are welcomed. Considering i'm very new to this, Please help me out!
CODE.txt (579 Bytes)
Your code:
int input1=12;
int input2=5;
int input3=9;
int input4=10;
int var;
void setup()
{
pinMode(2,INPUT);
pinMode(input1,OUTPUT);
pinMode(input2,OUTPUT);
pinMode(input3,OUTPUT);
pinMode(input4,OUTPUT);
}
void loop()
{
var=digitalRead(2);
if(var==1)
{
digitalWrite(input1,HIGH);
digitalWrite(input2,LOW);
digitalWrite(input4,HIGH);
digitalWrite(input3,LOW);
}
else
{
digitalWrite(input1,HIGH);
digitalWrite(input2,HIGH);
digitalWrite(input3,HIGH);
digitalWrite(input4,HIGH);
}
}
Why are you calling all your outputs "inputs"? Why do you create names for all the pins except pin 2? Last minute rush?
when i simulate my circuit
How are you simulating it ?
aarg:
Your code:
int input1=12;
int input2=5;
int input3=9;
int input4=10;
int var;
void setup()
{
pinMode(2,INPUT);
pinMode(input1,OUTPUT);
pinMode(input2,OUTPUT);
pinMode(input3,OUTPUT);
pinMode(input4,OUTPUT);
}
void loop()
{
var=digitalRead(2);
if(var==1)
{
digitalWrite(input1,HIGH);
digitalWrite(input2,LOW);
digitalWrite(input4,HIGH);
digitalWrite(input3,LOW);
}
else
{
digitalWrite(input1,HIGH);
digitalWrite(input2,HIGH);
digitalWrite(input3,HIGH);
digitalWrite(input4,HIGH);
}
}
Why are you calling all your outputs "inputs"? Why do you create names for all the pins except pin 2? Last minute rush?
I named those outputs as inputs because they were the inputs to the L293D motor driver IC... and also i am not that well versed in coding.
I am simulating it using TinkerCad.
Check out this other code that i tried. The same problem is occurring when i use this code.
CODE 2.txt (654 Bytes)
UKHeliBob:
How are you simulating it ?
I am using TinkerCad. Its an online free CAD designing tool. Do you recommend using that?
There is nothing obviously wrong with the code, so it appears that the simulator does not work in this case.
Unless, of course the simulator is so good that it realizes you would destroy the Arduino by trying to power motors from the 5V output.
it is pretty simple to put together something like that in real life, and you will learn a lot more doing so.