Gatekeeper Challenge Mission Banner - Image 1
Mission Mode 3

The Gatekeeper's Challenge: Servo Control

STORY

In a newly developed subdivision, a group of young engineering students notice long queues and wasted energy in the manual car gate system. They decide to design a sustainable automated car entrance system using servo motors and TRIOE.

30:00 / 30:00
Automated Gate Challenge

Gate System Status

GATE
SERVO
LED
Mission Icon

Mission Objectives

0/8

Build a motion detection gate that opens when motion is detected, then closes automatically!

Define pin variables: buttonPin=2, ledPin=13, servoPin=9
Connect Servo Motor using gateServo.attach(servoPin)
Setup Button (buttonPin) and LED (ledPin) using pinMode
Read Button with digitalRead(buttonPin)
Move Servo to Open (90°) and Close (0°)
Control LED using digitalWrite(ledPin, value) and Serial messages
Select TRIOE ESP32S3 Dev Module
Select COM7 Port
Code Editor Icon

Loading...
Arduino Reference Icon

Arduino Reference

Servo Motor Commands

#include <Servo.h>

Include Servo library for servo motor control

Servo gateServo;

Create servo object to control servo motor

gateServo.attach(servoPin)

Attach servo to specified pin (usually pin 9)

gateServo.write(angle)

Move servo to specific angle (0-180 degrees)

Button & Digital Input

pinMode(2, INPUT_PULLUP)

Set button pin with internal pull-up resistor

digitalRead(2)

Read button state (HIGH when not pressed, LOW when pressed)

Functions & Movement

for (int pos = 0; pos <= 90; pos++)

Loop to move servo from 0 to 90 degrees

delay(100)

Small delay for smooth servo movement

Serial Monitor Icon

Serial Monitor

Press "Verify Code" to compile and check your sketch.
© 2024 TRIOE. All Rights Reserved.