กลับไปหน้ารวมไฟล์
rgb-led-with-3-function-dipswitch-2b8bcc-en.md

Project Concept

The RGB LED with 3-function DIP Switch project allows you to switch between multiple lighting patterns and colors locally, without needing to re-upload code. By using a 3-position DIP switch, we can represent up to 8 different states (2^3), providing a versatile way to control color outputs.

Hardware Configuration

  • RGB LED: As with most RGB projects, the red, green, and blue pins are connected to PWM-enabled digital pins (e.g., 9, 10, 11) with 220-ohm current-limiting resistors.
  • DIP Switch: The three pins of the switch are connected to digital input pins (e.g., 5, 6, 7) using internal or external pull-up resistors. Each switch position determines a specific logic state (HIGH / LOW) for that pin.

Logic and Control

The Arduino code reads the states of the three DIP switch pins using digitalRead(). Based on the combination of these three inputs, the code uses if...else or switch statements to call different color functions. For example:

  • Switch 1 ON: Red light.
  • Switch 2 ON: Green light.
  • Switch 1 & 2 ON: Yellow (Red + Green).
  • All Switches OFF: Turn off the LED.

Code Sample Logic

int sw1 = digitalRead(5);
int sw2 = digitalRead(6);
int sw3 = digitalRead(7);

if (sw1 == HIGH && sw2 == LOW && sw3 == LOW) {
  setColor(255, 0, 0); // Red
} else if (sw1 == LOW && sw2 == HIGH && sw3 == LOW) {
  setColor(0, 255, 0); // Green
}

Versatility

This hardware-based selection method is great for projects requiring quick, manual configuration, such as setting modes for a mood lamp, a sign, or an indicator light on a larger prototype.

ข้อมูล Frontmatter ดั้งเดิม

title: "RGB LED with 3 function dipswitch"
description: "Control RGB LED patterns using a 3-pin DIP switch."
author: "sathyaraj00"
category: "Lights & LEDs"
tags:
  - "rgb"
  - "dipswitch"
  - "arduino"
views: 1843
likes: 0
price: 435
difficulty: "Intermediate"
components:
  - "1x Arduino UNO"
  - "1x RGB LED (generic)"
  - "1x DIP Switch, 3 Position"
  - "3x Resistor 220 ohm"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "2b..."
encryptedPayload: "U2FsdGVkX1/..."
seoDescription: "Use a 3-pin DIP switch to toggle through different RGB LED lighting functions on your Arduino."
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/rgb-led-with-3-function-dipswitch-2b8bcc_cover.jpg"
lang: "en"