In this tutorial ill be showing you how to build a obstacle avoiding or a smart car(both are the same, just the name is......).What it does is it will stop when an object comes in front of it ...
Things required-
For mounting,If you use the base plate I've done here then you can easily mount the components on it.It does not actually matter where you mount the components but the sensor should be facing ahead without any obstacle coming before it...Better let it be just at the front so that it can detect objects more accurately....
So now for the circuit part, its not that difficult,though you may have to give a separate power supply for the Arduino which I have not shown in this diagram.So what happens in the circuit is that when the sensor sends message to the Arduino that there is some obstacle in front of it ,which will then cut the circuit and stop the car its that simple you can also add some leds to make it look more good....
And now the code....
int irrecv=A0; int motor=6; void setup(){ pinMode(irrecv,INPUT); pinMode(motor,OUTPUT); } void loop(){ int i=digitalRead(irrecv); if(i==HIGH){ digitalWrite(motor,HIGH); /*low will make the motor spin as the gnd pin is connected to it.*} else{digitalWrite(motor,LOW)} }
If you are using leds to decorate then use this code instead of it-
int irrecv=A0; int motor=6; int led=13;//led computable pin void setup(){ pinMode(irrecv,INPUT); pinMode(motor,OUTPUT); } void loop(){ int i=digitalRead(irrecv); if(i==HIGH){ digitalWrite(motorpin,HIGH); /*low will make the motor spin as the gnd pin is connected to it.*/} else{digitalWrite(motor,LOW); digitalWrite(led,HIGH) } }