Devices & Components
1
Arduino® UNO™ Q 2GB
1
RGB LED Module (DIYables) v2
Software & Tools
Arduino IDE
Project description
Code
arduino-uno-q-rgb-led.ino
cpp
Full code from the newbiely.com tutorial
1#define PIN_RED 9 2#define PIN_GREEN 6 3#define PIN_BLUE 3 4 5pinMode(PIN_RED, OUTPUT); 6pinMode(PIN_GREEN, OUTPUT); 7pinMode(PIN_BLUE, OUTPUT); 8 9analogWrite(PIN_RED, 0); 10analogWrite(PIN_GREEN, 151); 11analogWrite(PIN_BLUE, 157);
arduino-uno-q-rgb-led-2.ino
cpp
Full code from the newbiely.com tutorial
1/* 2 * This Arduino UNO Q code was developed by newbiely.com 3 * 4 * This Arduino UNO Q code is made available for public use without any restriction 5 * 6 * For comprehensive instructions and wiring diagrams, please visit: 7 * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rgb-led 8 */ 9 10#define PIN_RED 9 // The Arduino UNO Q pin connected to the LED's red pin 11#define PIN_GREEN 6 // The Arduino UNO Q pin connected to the LED's green pin 12#define PIN_BLUE 3 // The Arduino UNO Q pin connected to the LED's blue pin 13 14void setup() { 15 pinMode(PIN_RED, OUTPUT); // Set red LED pin as an output 16 pinMode(PIN_GREEN, OUTPUT); // Set green LED pin as an output 17 pinMode(PIN_BLUE, OUTPUT); // Set blue LED pin as an output 18} 19 20void loop() { 21 // Set RGB LED to teal color #00C9CC (R = 0, G = 201, B = 204) 22 analogWrite(PIN_RED, 0); 23 analogWrite(PIN_GREEN, 201); 24 analogWrite(PIN_BLUE, 204); 25 delay(1000); // Maintain color for 1 second 26 27 // Set RGB LED to salmon pink #F7788A (R = 247, G = 120, B = 138) 28 analogWrite(PIN_RED, 247); 29 analogWrite(PIN_GREEN, 120); 30 analogWrite(PIN_BLUE, 138); 31 delay(1000); // Maintain color for 1 second 32 33 // Set RGB LED to Google green #34A853 (R = 52, G = 168, B = 83) 34 analogWrite(PIN_RED, 52); 35 analogWrite(PIN_GREEN, 168); 36 analogWrite(PIN_BLUE, 83); 37 delay(1000); // Maintain color for 1 second 38}
arduino-uno-q-rgb-led-5.py
python
Full code from the newbiely.com tutorial
1""" 2This Arduino UNO Q script was developed by newbiely.com 3This Arduino UNO Q script is made available for public use without any restriction 4For comprehensive instructions and wiring diagrams, please visit: 5https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rgb-led 6""" 7 8from arduino.app_utils import * 9import time 10 11COLORS = [ 12 (0, 201, 204, "Teal"), 13 (247, 120, 138, "Salmon pink"), 14 (52, 168, 83, "Green"), 15 (255, 0, 0, "Red"), 16 (0, 0, 255, "Blue"), 17 (255, 255, 0, "Yellow"), 18 (128, 0, 128, "Purple"), 19] 20 21def loop(): 22 for r, g, b, name in COLORS: 23 print(f"Setting color: {name} (R={r}, G={g}, B={b})") 24 Bridge.call("set_color", r, g, b) 25 time.sleep(2) 26 27 print("Turning off RGB LED") 28 Bridge.call("turn_off") 29 time.sleep(2) 30 31App.run(user_loop=loop)
arduino-uno-q-rgb-led-3.ino
cpp
Full code from the newbiely.com tutorial
1/* 2 * This Arduino UNO Q code was developed by newbiely.com 3 * 4 * This Arduino UNO Q code is made available for public use without any restriction 5 * 6 * For comprehensive instructions and wiring diagrams, please visit: 7 * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rgb-led 8 */ 9 10#define PIN_RED 9 // The Arduino UNO Q pin connected to the LED's red pin 11#define PIN_GREEN 6 // The Arduino UNO Q pin connected to the LED's green pin 12#define PIN_BLUE 3 // The Arduino UNO Q pin connected to the LED's blue pin 13 14void setup() { 15 pinMode(PIN_RED, OUTPUT); // Set RED LED pin as an output 16 pinMode(PIN_GREEN, OUTPUT); // Set GREEN LED pin as an output 17 pinMode(PIN_BLUE, OUTPUT); // Set BLUE LED pin as an output 18} 19 20void loop() { 21 setColor(0, 201, 204); // teal #00C9CC 22 delay(1000); 23 24 setColor(247, 120, 138); // salmon pink #F7788A 25 delay(1000); 26 27 setColor(52, 168, 83); // Google green #34A853 28 delay(1000); 29} 30 31void setColor(int R, int G, int B) { 32 analogWrite(PIN_RED, R); // Write RED value to RED LED 33 analogWrite(PIN_GREEN, G); // Write GREEN value to GREEN LED 34 analogWrite(PIN_BLUE, B); // Write BLUE value to BLUE LED 35}
arduino-uno-q-rgb-led-6.py
python
Full code from the newbiely.com tutorial
1""" 2This Arduino UNO Q script was developed by newbiely.com 3This Arduino UNO Q script is made available for public use without any restriction 4For comprehensive instructions and wiring diagrams, please visit: 5https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rgb-led 6""" 7 8from arduino.app_utils import * 9import requests 10import time 11 12BOT_TOKEN = "YOUR_BOT_TOKEN" 13API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}" 14last_update_id = 0 15 16def send_message(chat_id, text): 17 requests.post(f"{API_URL}/sendMessage", json={"chat_id": chat_id, "text": text}) 18 19def get_updates(): 20 global last_update_id 21 resp = requests.get(f"{API_URL}/getUpdates", params={"offset": last_update_id + 1, "timeout": 5}) 22 return resp.json().get("result", []) 23 24def loop(): 25 global last_update_id 26 updates = get_updates() 27 for update in updates: 28 last_update_id = update["update_id"] 29 msg = update.get("message", {}) 30 chat_id = msg.get("chat", {}).get("id") 31 text = msg.get("text", "").strip() 32 33 if text.startswith("/color "): 34 parts = text.split() 35 try: 36 r = int(parts[1]) 37 g = int(parts[2]) 38 b = int(parts[3]) 39 if all(0 <= v <= 255 for v in (r, g, b)): 40 Bridge.call("set_color", r, g, b) 41 send_message(chat_id, f"Color set to R={r}, G={g}, B={b}") 42 else: 43 send_message(chat_id, "Each value must be between 0 and 255") 44 except (ValueError, IndexError): 45 send_message(chat_id, "Usage: /color <R> <G> <B>\nExample: /color 255 0 0") 46 elif text == "/off": 47 Bridge.call("turn_off") 48 send_message(chat_id, "RGB LED turned off") 49 else: 50 send_message(chat_id, "Commands:\n/color <R> <G> <B> — set RGB color\n/off — turn LED off\n\nExamples:\n/color 255 0 0\n/color 0 201 204") 51 time.sleep(1) 52 53App.run(user_loop=loop)
arduino-uno-q-rgb-led-4.ino
cpp
Full code from the newbiely.com tutorial
1/* 2 * This Arduino UNO Q code was developed by newbiely.com 3 * 4 * This Arduino UNO Q code is made available for public use without any restriction 5 * 6 * For comprehensive instructions and wiring diagrams, please visit: 7 * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rgb-led 8 */ 9 10#include "Arduino_RouterBridge.h" 11 12#define PIN_RED 9 13#define PIN_GREEN 6 14#define PIN_BLUE 3 15 16void setColor(int R, int G, int B) { 17 analogWrite(PIN_RED, R); 18 analogWrite(PIN_GREEN, G); 19 analogWrite(PIN_BLUE, B); 20 Monitor.println("Color set to R=" + String(R) + " G=" + String(G) + " B=" + String(B)); 21} 22 23void set_color(int R, int G, int B) { 24 setColor(R, G, B); 25} 26 27void turn_off() { 28 setColor(0, 0, 0); 29 Monitor.println("RGB LED off"); 30} 31 32void setup() { 33 pinMode(PIN_RED, OUTPUT); 34 pinMode(PIN_GREEN, OUTPUT); 35 pinMode(PIN_BLUE, OUTPUT); 36 Bridge.begin(); 37 Monitor.begin(); 38 Bridge.provide_safe("set_color", set_color); 39 Bridge.provide_safe("turn_off", turn_off); 40 Monitor.println("RGB LED Bridge ready"); 41} 42 43void loop() {}
Comments
Only logged in users can leave comments