Pascal Cotret
Published © GPL3+

Wireless-controlled RGB LED

Can we control the color of a RGB LED without any wire?

BeginnerShowcase (no instructions)30 minutes3,560
Wireless-controlled RGB LED

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×2
NRF24L01
×2
Breadboard (generic)
Breadboard (generic)
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
USB-A to B Cable
USB-A to B Cable
×2
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing

Schematic

Code

Transmitter code

Arduino
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>

/*
This sketch sends a string to a corresponding Arduino with nrf24.
*/

int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;


void setup(){
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);}
void loop(){
  msg[0]= analogRead(A0)
    radio.write(msg, sizeof(msg)); 
    radio.powerDown();
    delay(1000);
    radio.powerUp();
  
  }
  }

Receiver code

Arduino
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>

/*
This sketch receives strings from sending unit via nrf24 
and prints them out via serial.  The sketch waits until
it receives a specific value (2 in this case), then it 
prints the complete message and clears the message buffer.
*/

int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;



int valPot=0; //variable qui va stocker la tension lue. On l'initialise  0.
int ledRouge=7;
int ledBleu=5;
int ledVert=3;// pin de connexion de la LED

void setup(){
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  
  pinMode(ledRouge,OUTPUT);
  pinMode(ledBleu,OUTPUT); 
  pinMode(ledVert,OUTPUT); 
}
void loop(){
  if (radio.available()){
    radio.read(msg, sizeof(msg)); 
    Serial.println(msg[0]);
    valPot=msg[0];
    analogWrite(ledRouge,valPot);
    analogWrite(ledBleu,255-valPot);
    analogWrite(ledVert,130+valPot);
    delay(10);
  
  }
  else {
    //Serial.println("albiche\n");
  }
}

Credits

Alban Germain & Zahra Sekkat

Posted by Pascal Cotret

Comments