Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Yun Jin Yonggledel임동교
Published © GPL3+

Innovation Lab #15 Servo Motor_RGB LED

Bongilcheon High School_Innovation Lab Project.

BeginnerProtip15 minutes9,319
Innovation Lab #15 Servo Motor_RGB LED

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Arduino Servo Motor
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Servo Motor_ RGB LED

Servo Motor_ RGB LED

Code

Servo Motor_ RGB LED

Arduino
Servo Motor Turn_ RGB LED Color Change
#include <Servo.h>

Servo gol;
long distance;
int red = 3;
int green = 5;
int blue = 6;

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

void loop() {
  distance = 100;
  top_open();
  delay(2000);
  distance = 20;
  top_open();
  delay(2000);
}

void top_open() {
  if(distance < 30) {
    gol.write(90);
    digitalWrite(red, HIGH);
    digitalWrite(green, LOW);
    digitalWrite(blue, LOW);
  }
  else {
    gol.write(0);
    digitalWrite(red, LOW);
    digitalWrite(green, HIGH);
    digitalWrite(blue, LOW);
  }
}

Credits

Yun Jin Yong
6 projects • 10 followers
gledel
100 projects • 115 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"
임동교
0 projects • 12 followers

Comments