Arduino Tool Gate With Night Light Circuit
by Nimai122 in Circuits > Arduino
735 Views, 5 Favorites, 0 Comments
Arduino Tool Gate With Night Light Circuit
The Project I made is an Tool Gate which is mainly seen in highways, but instead of a human being who lets you pass the barrier it a distance sensor, you will need a few supplies especially an Arduino and a code to make this Project work, we will be going through a few steps and show you the brief detail on how this project is made and works.
I have been working with arduino for a long time know but for people who don't really know what an arduino is, it a microcontroller which is equipped with sets of digital and analog input/output pins it help you to make various types of design with can be interfaced with various expansion board and other circuit, the reason we are using an arduino is that it is simple to control and code which can help beginners learn and try various arduino projects.
A distance sensor is an sensor that can determine if there is any object within it's certain radius, this is very helpful as it can determine if any vehicle is standing there and can be coded to open the gate that is blocking the vehicle.
A servo motor is a motor that can turn a whole 180 degrees turn and it is very helpful in out toll gate project as it can be coded to be used as a toll which can be moved using the help of the distance sensor.
The way this project works is that the distance sensor detects anything within it's radius, let say for example:- someone is driving a bike and comes near the toll gate, when it approaches the gate the distance sensor detects a motion and then is coded in a way that the distance sensor will tell the servo motor to turn 90 degrees which allows the biker to pass through, after the bike has passed the motion sensor does not detect anything which means it will tell the servo motor to go back to it's position which is to turn 90 degrees back.
I also uploaded 2 pictures one with the distance sensor on the board and one without the distance sensor on the board so you can see what is the wiring behind the distance sensor which is for the power and ground.
I will also be adding an additional circuit called Night Light, as it is a light that stays the same in the morning but as get's darker the light gets brighter until it looks pitch dark and the light is at is 100% brightness, it is an additional feature that I added to make sure the toll gate can look as real as possible compared to the toll gate's in real life.
Supplies
Supplies for the Toll Gate:-
(Click on the names to go to the website where you can purchase those items)
(Additional:- Night Light)
- LED
- Photoresistor
- 2 resistor with 5.2K
- Jumper Cables
- We will be making the Night Light on the same Breadboard where the tool gate is made
Arduino and Servo Motor
Step 1:- In the first step we will connect the servo motor with the Arduino, the supplies we will need for this will be Arduino, servo motor, and 3 jumper cables of any color.
The servo motor has 3 wires from the bottom the first one is black which is ground, the second one is red which is power and the last one is orange or sometimes yellow which is signal and this one can be connected to any of the pin/numbers on the right side of the Arduino so I connected it to 9.
Black/brown wire = Ground
Red wire = Power
orange/yellow wire = Arduino pin on the right side like example:- Pin9
Arduino, Servo Motor and Distance Sensor
Step 2:- For the Second step we will now connect the servo motor and the arduino with the distance sensor, but we cannot connect them directly so we will take the help of the breadboard.
First we will take the whole circuit we made with the arduino and servo motor and then bring a breadboard near it, before we start wiring for the distance sensor always remember to first add the power and ground pins to the breadboard like shown in the 3rd picture
Then we will add the distance sensor on the left side of the breadboard closer to the arduino.
An distance sensor has 4 pin's which are, Power, Trigger/Trig, Echo, and Ground, we will have to wire them in this order
So first we will place the distance sensor in the J section of the arduino on number's 7,8,9,10 as it has 4 pins each pin will fit into each number, on the number 7 which is power pin for the distance sensor, we will be connecting a jumper cable from anywhere on the 7th row to the power rail, on number 8 we will be connecting the Trig pin from the distance sensor, so we can connect a jumper cable anywhere on the 8th row to on of the pins in the arduino which is why I connect the trig pin to number 3 on the arduino, for number 9 which is the echo pin for the distance sensor we will be connecting the echo pin with a jumper cable to any one of the pins in the arduino, that is why I connected the echo pin to the pin 5 in the arduino, and last but not the least we have the number 10 which is the ground pin and for this pin we will be connecting a jumper cable from anywhere on the 10th row to the ground rail which is above the 10th row.
The Power pin is connected = Power rail
The Trig pin is connected to = 3
The Echo pin is connected to = 5
The Ground pin is connected = Ground rail
Coding
Step 3(Last Step):-In this last step we will have to write a code for this project which you can copy and paste it into your code section as text.
Code:-
#include<Servo.h> Servo myservo; const int trigPin=3; const int echoPin=5; long tmeduration; int distance; void setup() { myservo.attach(9); pinMode(trigPin,OUTPUT); pinMode(echoPin,INPUT); Serial.begin(9600); } void loop() { digitalWrite(trigPin,LOW); delayMicroseconds(2); digitalWrite(trigPin,HIGH); delayMicroseconds(10); digitalWrite(trigPin,LOW); tmeduration=pulseIn(echoPin,HIGH); distance=(0.034*tmeduration)/2; if(distance<=20){ myservo.write(90); } else{ myservo.write(0);} Serial.print("distance:"); Serial.println(distance); delay(1); }
Night Light(Optional/Additional)
The night light circuit, is a circuit that contain led, photoresistor, 2 resistor's with 5.2kOhms( you can even use a 10K ohms which is better in my opinion or else use the one closest to 10k Ohms) and some Jumper Cables, this circuit turn's on at night and in the daylight it's off. It actually looks like a solar panel but instead of collect energy when it's sunny it blocks the flow currents towards the light bulb but as it gets darker it slowly releases them making the light bulb brighter as it gets darker.
It is an additional feature that you can add to your Arduino Tool Gate, as it makes your project look more professional and closer to the one in real life.
I have posted 2 images 1 with only the circuit and the other one with the toll gate circuit as if you wanted to only make a night light then you can do that too.
Night Light Step 1
Step 1:- For the Night Light circuit we will first start with the LED wiring, in which we will be doing the LED side and later in the next step we will do the photoresistor side.
for the LED wiring before we start we need to add power and ground as without them our circuit would not work, next step would be to add the bulb and the 5.2k( or 10K) resistor on the anode side of the bulb( a bulb has 2 sides the shorter side is called cathode and the longer side is called anode), then on the cathode we will be adding a black wire which is connect from the bulb to the ground rail below. We will be also adding a wire which is connect from the resistor to any of the pin's on the right side of the arduino, so I choose number 7 but you can choose anything, and make sure that if you choose a different number don't forget to change the number in the code also or else it will think you'r wire is on number 7 instead of the number you choose.
This will make a basic layout of how the Night Light circuit will look first.
Night Light Step 2
Step 2:- In the Second step we will be making the photoresistor which will act like a solar panel but it is not a solar panel, In the morning the photoresistor blocks the LED from turning on, but as it get's darker the LED slowly start's to brighten up until it's dark which will make the LED brighten up 100%.
Now for the photoresistor we will be adding it a little away from the LED, then we will add a resistor to one of it's terminals( A photoresistor has 2 terminals and both of them are the same), and then a black wire connecting the resistor and the ground. we will also need to add a red wire which will be connect from the other terminal to the power rail below. We will also be adding a wire which is connect from the middle of the photoresistor and resistor to any of the pin's on the left side of the arduino, which in my case I connected it to A0, the pin I choose is the same as the one's on the right it's just that I connected it to A0 so it would look more neater. but if you want to you can connect it to any of the pin on the right side too, but as I said in the code don't forget to change the number if you change the pin or else it will keep thinking that the wire is connect to A0 when in real it is connect to one of your pin's in the right.
This was the last step to the Night light circuit but there is one more left, which is the coding for the Night Light, and the coding I will paste down will only be for night light and if you want it combined then you need to go to Step 8
Night Light Code
The code for the Night Light is down below but, *Disclaimer The Code I will be pasting down is only for Night Light not Night Light and Toll Gate combined so got to Step 8 to find the code for both the circuit combined*.
Code:-
int ldr=A0;//Set A0(Analog Input) for LDR. int value=0; void setup() { Serial.begin(9600); pinMode(7,OUTPUT); } void loop() { value=analogRead(ldr);//Reads the Value of LDR(light). Serial.println("LDR value is :");//Prints the value of LDR to Serial Monitor. Serial.println(value); if(value<300) { digitalWrite(7,HIGH);//Makes the LED glow in Dark. } else { digitalWrite(7,LOW);//Turns the LED OFF in Light. } }
Toll Gate and Night Light Coding Combined
This is the code for the combination of both the Toll Gate and the Night Light circuit
Code:-
#include<Servo.h> Servo myservo; const int trigPin=3; const int echoPin=5; long tmeduration; int distance; int ldr=A0;//Set A0(Analog Input) for LDR. int value=0; void setup() { myservo.attach(9); pinMode(trigPin,OUTPUT); pinMode(echoPin,INPUT); Serial.begin(9600); Serial.begin(9600); pinMode(7,OUTPUT); } void loop() { value=analogRead(ldr);//Reads the Value of LDR(light). Serial.println("LDR value is :");//Prints the value of LDR to Serial Monitor. Serial.println(value); if(value<300) { digitalWrite(7,HIGH);//Makes the LED glow in Dark. } else { digitalWrite(7,LOW);//Turns the LED OFF in Light. } digitalWrite(trigPin,LOW); delayMicroseconds(2); digitalWrite(trigPin,HIGH); delayMicroseconds(10); digitalWrite(trigPin,LOW); tmeduration=pulseIn(echoPin,HIGH); distance=(0.034*tmeduration)/2; if(distance<=20){ myservo.write(90); } else { myservo.write(0);} Serial.print("distance:"); Serial.println(distance); delay(1); }
A Small Clip of How My Toll Gate Circuit Works
In the, Video you could see how when I was moving my bike the distance sensor sensed the movement and told the servo motor to turn a 90 degree, and after my bike left the distance sensor sensed, that the bike was no longer there so it told the servo motor to go back to it's position which was turn another 90 degrees on the opposite side.
A Small Clip of How My Night Light Circuit Work
In this clip, you can see how the LED turn's on when my hand covers the photoresistor, but when I open my hand the LED turn's off, that how the light light circuit would work.