atharvkumar06
Published

Automatic tollbooth

This is an automatic tollbooth. It opens when it detects something in front of it.

IntermediateFull instructions provided2,996
Automatic tollbooth

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Lidar sensor
×1
Arduino sensor shield
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1

Story

Read more

Schematics

circuit diagram

This is a diagram of the circuit. I was not able to find any website which allowed me to add a lidar sensor and hence I removed it. You can connect the power of the lidar to the power on the breadboard, the ground of the lidar to the ground on the breadboard and the RX(green wire) and TX(white wire) to the ports that you have given in the code. If you have any other lidar sensor, you can google connections for that specific lidar and follow the steps.

Code

Code for automatic tollbooth

C/C++
Down below is the code for the automatic tollbooth. If you are having any troubles, please comment down below and I'll be happy to help.
#include <SoftwareSerial.h> //header file of software serial port
#include <Servo.h>
SoftwareSerial Serial1(2, 3); //green:RX, white:TX in order
Servo myservo;
void setup()
{
  Serial.begin(9600); //set bit rate of serial port connecting Arduino with computer
  Serial1.begin(115200); //set bit rate of serial port connecting LiDAR with Arduino
  myservo.attach(8);
  myservo.write(0);
}

bool open;

void loop()
{
  int d = distance();
  if (d < 30)
  {
    myservo.write(70); // if the distance is lesser than 20, then open the tollbooth
    open = true;

  }
  else if (open == true) {
    delay(1500);
    myservo.write(0);
    open = false;
  }

}

// calculating the distance
int distance()
{
  int uart[9];
  const int HEADER = 0x59;

  if (Serial1.available())
  {
    if (Serial1.read() == HEADER)
    {
      uart[0] = HEADER;
      if (Serial1.read() == HEADER)
      {
        uart[1] = HEADER;
        for (int i = 2; i < 9; i++)
        { //save data in array
          uart[i] = Serial1.read();
        }
        int check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];
        if (uart[8] == (check & 0xff))
        {
          int dist = uart[2] + uart[3] * 256; //calculate distance value

          return dist;
        }
      }
    }
  }
}

Credits

atharvkumar06

atharvkumar06

1 project • 2 followers

Comments