Car Turn Signal

by Harry Ou in Circuits > Arduino

334 Views, 2 Favorites, 0 Comments

Car Turn Signal

IMG_1068.jpg

This project uses a distance sensor to detect if it's safe for your "car" to turn.


With the press of a button the distance sensor detects if there is an object in a 10 inch or less distance, if it does detect an object, it will flash a warning with red LEDs and a buzzer, if there is nothing close by it will use the yellow LEDs to signify you are turning to other drivers.

This instructable will teach you how to make your own version of this circuit.


Research & Brainstorming: Initially wanted to make a calculator, but my classmate said he might make one. I got the idea from the earlier project where a lot of my classmates made a police siren for their model cars. I thought of a car blinker because I didn't fully understand how to use the ultrasonic distance sensor and how it operated at first and wanted to learn how it works, and apply it to my own circuit. Brainstorming what I wanted for the circuit was difficult at first but once I got an idea of what I really wanted the layout became easy. I went through many designs and even struggled adding a simple four pin button to the circuit, but eventually everything smoothed out.

Supplies

unnamed (1).jpg

Wiring

Tremendous Crift-Elzing.png
IMG_1073.jpg
IMG_1067.jpg
IMG_1073.jpg

White wires are used to connect the components to a positive energy source, while the black wires are used to signify when you should connect it to a negative terminal. First lets start with connecting the components with their negative sides.


Power Source: Connect Ground from arduino to negative, use jumper wires to connect both negative sides of the breadboard

LEDs: Connect the cathode or shorter side of the LEDs to ground via 330ohm resistor

Button: connect one side/leg to ground via 10kohm resistor (In my case I used terminal 1a)

Buzzer: Connect negative leg to ground via wire

Ultrasonic Distance Sensor: Connect negative leg to ground via wire


Now onto the messier, but hopefully clear in the diagram, positive wires.


Power Source: Connect 5V from arduino to negative, use jumper wires to connect both positive sides of the breadboard

Button: The neighboring leg of the side going to negative must be connected to positive on the breadboard (In my case I used terminal 2a)

Ultrasonic Distance Sensor: Vcc to positive on the breadboard


Onto the more complex part of the wires going to a power source, below I will first put the pin and then the piece of hardware it is attached to.


Pin 2: Push Button (Terminal 2b)

Pin 3: Trig on ultrasonic distance sensor

Pin 4: Echo on ultrasonic distance sensor

Pin 5: Red LED1

Pin 6: Red LED2

Pin 7: Yellow LED1

Pin 8: Yellow LED2

Pin 9: Yellow LED3

Pin 10: Buzzer


Coding

v4-460px-Write-Arduino-Software-in-C-Step-5.jpg

On the Arduino IDE app we will begin our coding by going through a step by step process. To access the full Tinkercad layout of the wiring plus the code visit this link. From there you can copy paste the code and follow the schematic better. Here I will be going through my code and explaining how it works.


  1. Starting up our variables:

int buttonPin = 2;

int trigPin = 3;

int echoPin = 4;

int redLED1 = 5;

int redLED2 = 6;

int yellowLED1 = 7;

int yellowLED2 = 8;

int yellowLED3 = 9;

int buzzer = 10;


The variables that we set at the start are given numbers, these are the numbers of the pins we are using on the arduino as an input and output source. You can change these numbers at anytime for personal preference or in case one of your pins isn't working.

int pins_output[] = {trigPin, redLED1, redLED2, yellowLED1, yellowLED2, yellowLED3,buzzer};

int pins_input[] = {buttonPin, echoPin};


I put all of the variables in a list, sorted by whether these pins need to be used for Input or Output, easier to sort and more efficient code for when we have to turn them on.

bool buttonPressed = false;

boolean variables are just variables that have true or false statements, currently our button isn't being pressed so it is false, when it is pressed, it will change to true which will activate our code.


2. Setting up our code

void setup() {

for (int a = 0; a < 8; a++) {

pinMode(pins_output[a],OUTPUT);

}

for (int b = 0; b < 2; b++) {

pinMode(pins_input[b],INPUT);

}

Serial.begin(9600);

}

It goes through the list we made called "pins_output" and turns each of them to an output signal, similarly it goes through each pin in our list "pins_input" and turns each of them to an input signal. We setup the serial monitor so we can check if our code is working.


3. Using the Distance Sensor

Each individual line is explained after the // (to prevent the explanation from interfering with the code)

void loop() {

long duration, inches; // declares variables, duration is the time for the echo signal to return (in milliseconds), inches is the calculated distance

digitalWrite(trigPin,LOW); // ensures a clean signal

delayMicroseconds(2);

digitalWrite(trigPin,HIGH); // sends out the signal

delayMicroseconds(10);

digitalWrite(trigPin,LOW); // turns it off after 10 milliseconds

duration = pulseIn (echoPin,HIGH); // detects how long the signal takes to come back

inches = duration /74 /2; // converts the time the signal took to find an object and turns it into inches


4. Confirming with serial monitor

Once you're done setting up the distance sensor, go to your serial monitor and move your hand certain distances away from the monitor, if everything works correctly the serial monitor will say approximately how much inches away your hand is.

if (digitalRead(buttonPin) ==HIGH) { // used to check if the sensor is working in your serial monitor, good for debugging in case of potential errors

Serial.print("Distance: ");

Serial.println(inches);

}


5. Turning on your LEDs and buzzers

Now we must bring the purpose to this circuit, delete the "}" at the end of the button statement as we have to extend the if statement to apply to the LED's as well. Above I have linked the "}" you have to delete above for more clarification.

if (inches < 10) { // if there is an object less than 10 inches a way it flashes a warning to the driver by turning the buzzer and lights on and off

digitalWrite(redLED1, HIGH);

digitalWrite(redLED2, HIGH);

digitalWrite(buzzer, HIGH);

delay(200);

digitalWrite(redLED1, LOW);

digitalWrite(redLED2, LOW);

digitalWrite(buzzer, LOW);

delay(200);

} else { // else means in any other circumstance there is nothing close by. The turn signal activates letting the driver signal their turn to other drivers

digitalWrite(yellowLED1, HIGH);

delay(300);

digitalWrite(yellowLED1, LOW);

digitalWrite(yellowLED2, HIGH);

delay(300);

digitalWrite(yellowLED2, LOW);

digitalWrite(yellowLED3, HIGH);

delay(300);

digitalWrite(yellowLED3, LOW);

}

}

}

Example Video

IMG_1069.jpg

And there you have it! You're own simple car blinker circuit. If everything goes smoothly it should operate as intended, like in the video attached: Video file too large so just click here to see it on google drive.