RGB LED Indicates Servo Motor Position

by rayankiwan63 in Circuits > Arduino

777 Views, 0 Favorites, 0 Comments

RGB LED Indicates Servo Motor Position

RGB LED INDICATES SERVO POSTION (2).png

Hello all, in this project I will show you how to build RGB led set servo position

INTRO

In this video, i will show you how to make arduino RGB led indicates servo motor position. Also, i will test the output using tinkercad .

Components Needed

Arduino uno

RGB led

Servo motor

3 resistor 220

Arduino Code

// C++ code
//
#include <Servo.h>


Servo gol;
long distance;
int red = 4;
int green = 2;
int blue = 3;


void setup() {
  gol.attach(8);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
}


void loop() {
  distance = 60;
  top_open();
  delay(2000);
  distance = 22;
  top_open();
  delay(2000);
  distance = 15;
  top_open();
  delay(2000);
}


void top_open() {
  if(distance > 30) {
    gol.write(150);
    digitalWrite(red, HIGH);
    digitalWrite(green, LOW);
    digitalWrite(blue, LOW);
  }
  else if(distance < 25 && distance > 20) {
    gol.write(90);
    digitalWrite(red, LOW);
    digitalWrite(green, HIGH);
    digitalWrite(blue, LOW);
  }
  else if(distance <20 ) {
     gol.write(45);
    digitalWrite(red, LOW);
    digitalWrite(green, LOW);
    digitalWrite(blue, HIGH);
}
}

Tinkercad Simulation

Output Results

RGB led indicates servo motor position using arduino uno and tinkercad simulation