
There are barriers between a railroad train and a pedestrian or car crossing.
In this project we will realize a system that simulate the operation of automatic barriers for railways trains.
We will design this system using:
two ultrasonic sensors hc-sr04 for the detection of the arrival of the train.
two servomotors to lower or raise the barriers
HC-SR04 sensor
Motor driver GPIO card
test plate
connecting wires
toy train
To do the assembly, we connected:
the VCC pin to the 3.3V pin of the Micro:bit
the Trig pin to the P12 pin of the Micro:bit
the ECHO pin to pin P13 of the Micro:bit
the GND pin to the GND pin of the Micro:bit
For the second sound sensor HC-SR04:
the VCC pin to the 3.3V pin of the Micro:bit
the Trig pin to pin P14 of the Micro:bit
the ECHO pin to the P15 pin of the Micro:bit
the GND pin to the GND pin of the Micro:bit
For the first servomotor:
red wire: power supply wire to be connected to the 5V terminal of the GPIO card
brown wire: wire to connect to the GND pin of the Micro:bit
Yellow: Positioning signal wire connected to Micro: bit pin S1
For the second servomotor:
red wire: power supply wire to be connected to the 5V terminal of the GPIO card
brown wire: wire to connect to the GND pin of the Micro:bit
Yellow: Positioning signal wire connected to Micro:bit pin S2
For LEDs:
the terminals (-) of the LEDs to GND of the Microbit
the (+) terminal of the first red LED at P0 of Microbit
the (+) terminal of the first green LED at P1 of Microbit
the (+) terminal of the first red LED to P2 of Microbit
the (+) terminal of the first green LED at P8 of Microbit
Here is the makecode program which allows you to:
calculate the distance between the HC-SR04 sensor and the detected object
raise or lower barriers
turn LEDs on or off