FIKRI IBRAHIM N

Blog tentang Robotik, Fisika, Fisika Instrumentasi, Elektronika, Komputasi dll.

Search

Saturday, June 30, 2018

AUTOMATIC PARKING SYSTEM USING ARDUINO MICROCONTROLLER


Purpose :

1. Programming HC-SR04 using arduino software
2. Apply HC-SR04 for automatic gate

1.1 Basic Theory
1.1.1 Arduino Uno

Arduino is an open-source single-board micro controller, derived from Wiring platform, designed to ease the use of electronics in various fields. The hardware has an Atmel AVR processor and the software has a C language programming language that has been simplified using simple functions so that any novice can learn it quite easily. Here are some types of arduino:

Figure 1.1 types of Arduino


Excess Arduino
• No need for chip programmer device because in it already there is a bootloader that will handle the program upload from computer.
• Already have a means of USB communication, so that Laptop users who do not have serial port / RS323 can use it.
• The programming language is relatively easy because the Arduino software comes with a fairly complete set of libraries.
• Has a ready-made module (shield) that can be plugged into the Arduino board. For example shield GPS, Ethernet, SD Card, etc.


1.1.2 HC-SR04 Sensor (Distance Sensor)

HC-SR04 sensor is a type of ultrasonic sensor is a sensor that serves to convert the physical quantity (sound) into electrical quantities and vice versa. The sensor is commonly referred to as a proximity sensor because it can detect the presence of objects nearby without physical contact.
The way the sensor works is based on the principle of the reflection of a sound wave so that it can be used to interpret the existence (distance) of an object with a certain frequency. Here is an ultrasonic sensor image:
Figure 1.2 Ultrasonic sensor of type HC-SR04

1.1.3 Servo
Servo motor is a device or rotary actuator (motor) designed with a closed-loop feedback control system (servo), so it can be set-up or set to determine and ensure the angular position of the motor output shaft.
This is a picture of one servo:


Figure 1.3 servo small type torque 180

1.2 Materials and Components



Tools and materials
Amount / size
Arduino Uno
1 Piece
Servo
1 Piece
HC-SRO4
1 Piece
Jumper cable
10 Piece
LED
1 Piece
Hider Male
1 Piece
Here is a list of the materials and components needed to create Automatic Parking System Using Arduino Microcontroller robots that work automatically:

Table 1.1 List of materials and robotic components Automatic Parking System Using Arduino


1.3 Program Design and Automated parking system set

Table 1.2 Specification of HC-SR04 Distance Sensor
Power Suplpy
+5V DC
The power flow
15 mA
Effective angle
<15 Degree
Distance reading
2 cm – 400 cm
Angle measurement
30 Degree

Table 1.3 Pin on Sensor
Name
Information
VCC
Power source (5V)
Trig
The sonar signal booster of the sensor
Echo
Sonar signal bounce capture
GND
Ground

Here are the steps of making the program and circuit of Automatic Parking System using Arduino Microcontroller

1. Arrange the robotic circuit Automatic Parking System using Arduino Microcontroller using HC-SR04 sensor as shown below:

Figure 1.4 Robotic circuit Automatic Parking System using Arduino Microcontroller


2. Connect the Arduino to the computer using the USB cable.
3. Open arduino software, then type the program to set the servo angle

==> The servo program determines the start and end angles

#include <Servo.h>  
char buffer[10];  
Servo servo1;    

void setup()  
{  
       //position of servo pin
        Servo1.attach(9);   
       
        Serial.begin(9600); 
        Serial.flush(); 
       // initial condition of servo
        servo1.write(175);   
        
       Serial.println("STARTING..."); 
}  
  void loop()  
{  
        if (Serial.available() > 0) {  
                int index=0; 
                delay(1000);  
                int numChar = Serial.available();  
                if (numChar>10) { 
                numChar=10; 
                } 
                while (numChar--) { 
                         
                   buffer[index++] = Serial.read(); 
                } 
                splitString(buffer);  
        } 

void splitString(char* data) { 
        Serial.print("Data entered: "); 
        Serial.println(data); 
        char* parameter; 
        parameter = strtok (data, " ,");  
        while (parameter != NULL) {  
                setServo(parameter);  
                parameter = strtok (NULL, " ,");  
        }                 
        for (int x=0; x<9; x++) { 
                buffer[x]='\0'; 
        } 
        Serial.flush(); 

void setServo(char* data) { 
        if ((data[0] == 'A') || (data[0] == 'a')) { 
        // String to long integer
                int firstVal = strtol(data+1, NULL, 10); 
        // Constrain values
                firstVal = constrain(firstVal,0,180); 
                servo1.write(firstVal);
                delay(1000); 
                Serial.print("Servo1 is set to: "); 
                Serial.println(firstVal); 
        }  
}  

4. after finding the appropriate angle, then type the program below




==> Robotic Automatic Parking System With Arduino Microcontroller

#include <Servo.h>
//definition of input-output pin of ultrasonic signal
const int trigPin = 12;
const int echoPin = 13;
const int penghalang = 10;
Servo pintu;
long duration;
int led=10;

void setup() 
{
  Serial.begin(9600);
  pintu.attach(9);
   pintu.write(160);
  pinMode(led, OUTPUT); 
}
void loop() 
{
  int jarak = trig();
  Serial.println(jarak);
  if (jarak<penghalang) 
  {
  pintu.write(55);
  digitalWrite(led,LOW); 
  delay(3000);
   for(int pos = 55; pos < 160; pos += 1)  
  {  
    // in steps of 1 degree 
    pintu.write(pos);              
    delay(22);                       
  } 
  digitalWrite(led,HIGH);  
  }

}

long trig()
{
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
  return duration / 29 / 2;
}


5. Select the Board and Serial PORT you are using in the Tools menu.
6. Press the Verify button (check mark) below the file menu.
7. If the message "Done Compiling" indicates that there is no problem with the program we type.
8. Next press the Upload button (arrow to right →) located on the right Verify button until the message "Done Uploading" appears.





No comments:

Post a Comment