CxD Archive
Code: Robotics
Code: Robotics
  • Code Introduction
  • TUTORIALS
    • A. Meet Your Robot
      • A-1 Circuit Board
      • A-2 Motors and Wheels
      • A-3 Other Components
    • B. Hello World Test
      • B-1 Arduino Code Editor
      • B-2 New App Template
      • B-3 Global Variable
      • B-4 Setup Function
      • B-5 Loop Function
      • B-6 Upload App to Robot
      • B-7 Add Sound
      • B-8 Use Button
    • C. Driving and Turning
      • C-1 Driving
      • C-2 Turns (Pivoting)
      • C-3 Test Wheel Encoders
      • C-4 Drive for Specific Distance
      • C-5 Pivot By Specific Angle
      • C-6 Drive Straight Continuously
    • D. Detect Objects in Path
      • D-1 Test Mechanical Bumpers
      • D-2 Detect Collisions
      • D-3 Test Ultrasonic Sensor
      • D-4 Avoid Collisions
    • E. Detect Lines on Surface
      • E-1 Test IR Line Sensors
      • E-2 Follow Line
      • E-3 Avoid Line
      • E-4 Count Lines Crossed
      • E-5 Follow and Count Lines
    • F. Detect Other Conditions
      • F-1 Detect Surface Drop-Off
      • F-2 Test Accelerometer
      • F-3 Detect If Upside-Down
      • F-4 Detect If Bumped
  • REFERENCES
    • Arduino Language
    • Arduino Code Editor
      • Create New App
      • Save and Rename App
      • Include RedBot Library
      • Verify App Code
      • Upload App to Robot
      • Download Copy of App
      • Use Serial Monitor to View Data
      • Robot Demo App Template
    • Physical Inputs
      • Push Button (D12)
      • Mechanical Bumpers
      • IR Line Sensors
      • Wheel Encoders
      • Accelerometer
      • Ultrasonic Sensor *
    • Physical Outputs
      • LED Light (D13)
      • Speaker (Buzzer)
      • Motors
    • Robot Behaviors
      • Producing Alerts
      • Driving
      • Turning
      • Detecting Objects
      • Detecting Lines
      • Detecting Other Conditions
    • Navigation Modes
      • Distance Navigation
      • Line Counting Navigation
      • Line Following + Counting Navigation
      • Autonomous Navigation
  • LINKS
    • Robotics Project Guidebook
    • Arduino Create Web Editor
    • Arduino Language Reference
    • RedBot Experiment Guide
  • ELEGOO Experiments
    • Getting the Arduino IDE
    • Starting with the `techCar` Template
    • Template Code for techCar.ino
    • Template Experiments
    • Reinstall the Original Remote App Functionality, If Needed
Powered by GitBook
On this page
  • How to Code LED
  • Declare Variable for LED
  • Set Pin Mode for LED
  • Turn LED On and Off
Export as PDF
  1. REFERENCES
  2. Physical Outputs

LED Light (D13)

PreviousPhysical OutputsNextSpeaker (Buzzer)

Last updated 6 years ago

The RedBot mainboard has a built-in green LED light that can be controlled by your program. The LED is hardwired to pin D13 on the RedBot mainboard and is located near the center-right of the mainboard.

The LED can be used to (usually in combination with sound from the speaker).

How to Code LED

To use the LED light in your robot app, you will need to:

  1. Declare a global variable to store the LED's pin number

  2. Set the pin mode for the LED

  3. Use the digitalWrite() method to turn the LED on and off

Declare Variable for LED

You'll need to create a global variable to store the pin number of the LED, which is connected to pin D13. Add this code statement before the setup() function:

int LED = 13;

Set Pin Mode for LED

You'll need to set the pin mode for the LED. Add this code statement within the setup() function:

pinMode(LED, OUTPUT);

Turn LED On and Off

The digitalWrite() method can be used to send an "on" or "off" signal to the LED by using a value of either HIGH or LOW:

  • HIGH will turn on the LED

  • LOW will turn off the LED

After turning on the LED, you will typically use the delay() method to add a waiting period (in milliseconds) before turning off the LED.

For example, the following code will turn on the LED for 0.5 seconds and then turn it off:

digitalWrite(LED, HIGH); // turn on
delay(500); // wait 0.5 seconds
digitalWrite(LED, LOW); // turn off

You can code your own sequence of digitalWrite() and delay() statements to make the LED turn on and off in different patterns (e.g., double blink, slow blink, fast blink, etc.)

provide alerts or feedback