barrera automatica con sensor de movimiento

Arduino automatic barrier with motion sensor

Welcome to a new Arduino project. In this tutorial, you will learn how to build a small automatic barrier with Arduino that is activated by a motion sensor. We will also cover the materials used, the wiring diagram, and the code needed to control the barrier with the sensor.

Materials used in the project

Below you can find the materials used to build our automatic Arduino barrier together with a brief description of each one. If you want to make the project yourself, you can click the images to go to a website where you can buy the parts.

Arduino Uno board: it is the brain of the project and controls every part of it through the code you will find below.

Servo motors: 5V motors with a gearbox that allow precise position control and a high amount of torque for their size.

A board with interconnected holes (pins) that we use to make all the project connections.

Motion sensor: it works by measuring passive infrared radiation. Any object emits heat in the infrared spectrum, and the sensor uses that principle to detect changes in radiation.

Ice cream sticks: we use these sticks as the structure to shape the barrier.

Arduino starter kit
Arduino starter kit
Arduino Uno board
Arduino Uno board
Motion sensor
Motion sensor
Arduino servo motors
Arduino servo motors
Ice cream sticks
Ice cream sticks

WE DEVELOP YOUR IDEA

Need help with a project?

RobotUNO project consulting
  • Prototyping and MVPs
  • Arduino and ESP32
  • PCB design
  • 3D part design
  • Bluetooth connectivity
  • Feasibility study
  • Cost optimization
  • Technical consulting
  • Internet of Things
  • Patent supbyt
Learn more

Step-by-step project video

If you want a much more detailed walkthrough of how to build this project from start to finish, including a code explanation, the video below covers everything in a more visual and easier-to-follow way. And remember, if you enjoy this kind of content, do not forget to subscribe.

Arduino wiring diagram for the automatic barrier with a motion sensor

One of the most important parts of assembling the barrier with the motion sensor is connecting the different elements correctly. To avoid assembly mistakes or incorrect connections, here is the wiring diagram used in this project. With this wiring, you can use the code at the end of the post without making any modifications.

esquema proyecto3 1

Arduino code for the automatic barrier with a motion sensor

Below you can find the code developed specifically for this project. The pins used in the code are the same ones shown in the wiring diagram above.

If you want a more detailed explanation of the different parts of the code used to program both the barrier and the motion sensor, I recommend watching the video linked above.

If you still do not have Arduino installed and have questions about how to use or install the development environment used for Arduino, here is a link to how to download the Arduino IDE.

//Canal de YouTube -> Robot UNO
//Barrera automática con sensor de movimmiento

#include <Servo.h>
Servo servomotor;
int valor;
int PINSERVO = 9;
int PULSOMIN = 1000;
int PULSOMAX = 2000; 

void setup() {
  pinMode(7,INPUT);
  pinMode(8,OUTPUT);
  digitalWrite(8,LOW);
  servomotor.attach(PINSERVO,PULSOMIN,PULSOMAX);
}

void loop() {
  valor = digitalRead(7);
  digitalWrite(8,valor);
  if(valor == HIGH){
  servomotor.write(180);    
  }
  if(valor == LOW){
    servomotor.write(0);
  }
}

Frequently asked questions

Which motion sensor does this automatic barrier use?

This project uses a PIR sensor that detects human presence or movement in front of the barrier to activate it automatically.

Which Arduino models are compatible with it?

It is designed for the Arduino Uno, but you can easily adapt it to other models such as the Arduino Nano or Mega.

What happens when the sensor detects movement?

The barrier opens automatically using a servo motor, allowing passage, and then closes again after a few seconds.

Do I need to install external libraries for it to work?

No. This project uses basic Arduino IDE functions, which makes it easy to implement without complex setup.