Detector of proximity with arduino

Detector of proximity with arduino to apply it in car

In this practice we are going to use Arduino Uno, a system of leds and a pair of motors mounted on kit of chassis to make a car that, on the one hand does him effect of lights of the fantastic car and on the other, it detects with two sensors the presence of an obstacle to avoid that car.

This project has one second variant that consists of making a complement so that a siren activates, when something next is detected (the same to the device of proximity of the present cars)

1 part. Game of Lights

We take 7 diodes leds and one metallic plate from suitable dimensions to locate in the front part of the car. In that plate it is perforated with the reel of 5 mm, 7 orifices for the diodes. If the plate allows the weld, we welded all the terminals negative of the diodes to the plate. In case not it is possible, to unite all the negative terminals and of that union, to weld a resistance of 220 Ohms. Of the other end of the resistance, to weld a cable and to connect it to the GND of the plate of Arduino. The positive terminals of the diodes must knit to a cable and connect the other end from the cable to each one of the ports that we are going to use. The electrical scheme of the diodes is the following one: Connection of diodes

Part 2. We are going to realise a detector of obstacles with several applications, among them, intrusion detection (alarm) or to avoid a shock of a car. Based on http://www.youtube.com/watch?v=-cK5-Nv1Bfk but using another sensor. Therefore, we must lower another bookstore. hc-sr04

First of all, we will make a brief study of device HC-SR04.

The function that it has is to send a train of impulses by the emitter and to count€ the time that it takes in receiving on the other receiving echo in returning. translator-signal

As we can see in the graph, first the pulse arrives from 10 microseconds at the entrance (to trigger). The device waits for a little to that it finishes and it sends a ultrasonic signal of 8 pulses. We hope to that the sound is reflected in some object and arrives at 2 sensorial. Then, the HC-SR04 will send by exit echo a signal with proportional width while it has taken in being received (echo back). To but it widens, but far it was the object.

We happen to the programming. We remember that what comes between * commentaries * or home with //are commentaries that are not executed. /*

This it is our program that uses the HC-SR04 to measure distances. The basic characteristics are VCC 5v (they are taken from the arduino plate) GND connected to GND of the plate from arduino Exit echo to pin 7 of Arduino Entrada Trig to pin 8 of Arduino Mas information, connections that there are within the program:

#define echoPin 7 //We assigned to port 7 the name echoPin7 #define trigPin 8 //Trigger Pin assigns to port 8 #define LEDPin 13 //the diode that is in the plate and that corresponds to port 7 we will call LEDPin to him int maximumRange = 20; //We establish the maximum rank that we are going to measure, in this case are 20 cm int minimumRange = 0; //this is the minimum range long duration, distance; //takes duration and distances as values long //the variables of type Long is variable of extended size that they go from -2,147,483,648 to 2,147,483,647. //we began to assign to values void setup () \ {Serial.begin (9600); //We are going to put the port series So that arduino it informs to us into the values that the ultrasonic measurer takes. pinMode (trigPin, OUTPUT); //Tenth that trigPin will be exit pinMode (echoPin, INPUT); //echoPin will be entered of data pinMode (LEDPin, OUTPUT); //the LED of the plate (port 13) forms as exit} void loop () \ {digitalWrite (trigPin, LOW); //First we put trig under delayMicroseconds (2); //We waited for 2 microseconds digitalWrite (trigPin, HIGH); //we passed it to high activating the HC-SR04 delayMicroseconds (1000); //we waited for 1 ms digitalWrite (trigPin, LOW); /* we pressed the low pulse to finishing the process. In the following point, we hoped to that the signal bounces and the HC-SR04 sends a pulse to us with the corresponding width while pulseIn has taken the wave of sound in bouncing * duration = (echoPin, HIGH); //We took the duration from the pulse/* the instruction pulseIn gives the time us that a wave is in stop (HIGH). In order to spend that remote time, we must divide it by 58,2 * distance = duration/58.2; if (distance >= maximumRange || distance <= minimumRange)/* in the advanced military training tenth if the distance is greater to the one than we indicated at the outset, that is 20 cm or minor to 0, then we sent to the console value -1 and put the activated LED. in order to see the arduino console and to see the measures that are taken it is necessary to go to Herramientas-> serial monitor * \ {Serial.println (- 1€);  //we printed in console -1 digitalWrite (LEDPin, HIGH); //We ignite the LED} else \ {/* In case it is within the rank, we sent to the value to the console using the protocol series of Arduino * Serial.println (distance); //we sent to console the value of the measurement digitalWrite (LEDPin, LOW); } //We put the dull LED delay (100); //We hoped 0.1 second until the new measurement} to unload the file, to puncture in Measurer of distance with HC-SR04 

  3 Part (we add a second sensor). In order to have better control, we needed a second sensor that detects the other flank, so that each sensor will be in charge to control to the motor of its corresponding flank (sensor-right it controls right motor). Nothing new is applied to the program, only that to take two ports but to control to the second sensor.

    Note: Bookstores exist that are applied specifically to program and that consider the different devices. In order to work with some of them, ours for example, it is come as
    1 step is to lower of the arduino Web the bookstore that will be necessary and we can lower it of http://www.ardublog.com/library-for-arduino-ultrasonic-ranging-hc-sr04/
    2 Once decompressed is necessary to install the folder Ultrasonic€ in the directory of the arduino program, that in my computer is in C:\Program You case out (x86) \ Arduino \ libraries
    3 So that the instructions that we put in the programs can be executed, is necessary to tell him that it includes the bookstore and for that reason we must open the program to program Arduino Sketch->Importar Librer­a->Ultrasonic€.

Definitive program: Once we have realised all the previous activities (important so that we are understanding the programming in Arduino) we incorporated the final program so that, on the one hand it controls 7 lights LED for effect of the fantastic car and a function that is in charge to control the motors in case of detecting an obstacle. The program we can lower it of this connection

Fantastic car with 7 leds and sensors ultrasound 

It is necessary to emphasize in that program that we will see a function funcion1 ()€ that is going away to order to verify if we approached an object so that it stops the corresponding motor. The flame whenever a light goes out and goes to the following one (within the routine of the game of lights). Once it is executed, the program continues executing itself where it remained.

As final Activity, to modify the program so that the best possible behavior is had. You can improve it if one adds 4 relays more to control the turn of the motor, so that when is an obstacle, a little is stopped, backed down, it turns, it verifies that the way is free€ and starts up motor both. For this improvement, we needed 6 relays.