Teaching Research and Publishings Speaking Engagements Professional Development About Me

EV3 Programming Resources

EV3 Gate Project

Step 1: Setup

In groups, choose one laptop to be used for coding and a second laptop for research. Close all other laptops.

Download and install Visual Studio Code and the LEGO MINDSTORMS EV3 MicroPython extension.

Connect to the local wifi:

Step 2: Buld the Parking Gate

The instructions are available here:

Parking Gate Bulding Instructions

Connect the sensors and motors using the two cables:

Step 3: Build the Car

The instructions are available here:

Car Bulding Instructions

The remote will not actually be used in this project, you can leave the remote turned off.

Step 4: Code the Parking Gate

Start a new project. Open up main.py and use this code as a starting point:

#!/usr/bin/env pybricks-micropython

from pybricks import ev3brick as brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                             InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                             SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase

import time

# Start the program with a beep

# Define which motors and sensors are connected
motor = Motor(Port.A)
distanceSensor = InfraredSensor(Port.S1)

# Reset the position of the motor

# Display the current motor position
print("Current Motor Position: "+str(motor.angle()))

# Move the motor one direction
motor.run_target( 100, -45, Stop.HOLD, False )

# Wait three seconds

# Move the motor the other direction
motor.run_target( 100, 0, Stop.HOLD, False )

# Create a loop
while True:

# Wait five seconds

# Make a beep

# Display the current distance
print("Current Distance: "+str(distanceSensor.distance())) 

# Output instructions to stop this code
print("Press the stop button to end this script")

Read the starting code line by line and all the comments. As a group strive to understand every line of code.

Your bin will have two names, the LEGO Brick will use the name on the red tape. Use Visual Studio Code to the LEGO Brick:

Push F5 on a PC or FN+F5 on a Mac to test your code.

That's it! The rest is up to you. Program the gate to open when the car parks in front of the infared sensor.

Note: You may want to remove the gate bar when testing, it will keep hitting rest of the structure.

Step 5: Submitting

Submit your main.py file and a list of group members that were present in Blackboard.