This is simple illustration how to build easy PWM LED control with IQRF TR module and a few other components.
This device is powered from 12V/6A DC power supply and can power up to 5m of LED strip. This device can be controlled via RF, buttons or potentiometer. RF controling is compatible with remote control device RC-04 wih low battery signalizing – fast 3 time LED blinking.
It’s recomended to connect potentiometer via short shield cable.
Schematics:
Code example:
// *********************************************************************
// * PWM-LED_B *
// * v1.01 *
// * DPS v1.02 *
// *********************************************************************
/*
press SW2 and SW1 to save actual PWM value from potentiometer to
EEPROM and next start with SW1 to setting PWM value
User define time to automatic off LEDs - TimeToOff, comment to disable
*/
// *********************************************************************
#include "../includes/template-basic.h" // System header files
// *********************************************************************
#define TR52D
#define ADC_filter 10 // potentiometer sensitivity - 1-15
// 1 ... maximal sensitivity
#define TimeToOff 14400 // 4h define automatic-off time in
// seconds 1 - 65536
// comment to disable
#define SW1 _C6_IN // button S1 - on
#define SW2 _C7_IN // button S2 - off
#define PWM PORTC.6 // PWM output on pin C5
// *********************************************************************
interrupt userIntRoutine(void);
// *********************************************************************
void InitHW(void);
void RFControl(void);
void Battery(void);
void ADControl(void);
void ButtonControl(void);
void InitPWM(void);
uns8 ReadADC(void);
void setPWM(uns8 hodnota);
void TimeControl(void); // auto turn off after user defined time
// *********************************************************************
uns8 i;
uns8 ADC_value; // old value of potentiometer
bit ADC_enable;
bit ADC_control; // 1 ... control via ADC
// 0 ... control via other - RF, button
uns8 ADC_actual; // actual value of potentiometer
uns8 PWM_value;
uns8 PWM_save; // saved PWM value to eePROM on position 0
bit batteryError; // 0 ... battery OK
// 1 ... battery error
uns8 time; // time counter
uns16 timerOff;
bit TimeControlEnable;
// *********************************************************************
void APPLICATION()
{
InitHW(); // initialization hardware
InitPWM(); // Initialization PWM output
pulseLEDG();
waitDelay(10);
ADC_value = ReadADC(); // read position of potentiometer
while (!SW1 && !SW2); // after reset
waitDelay(25);
while(1)
{
clrwdt();
if(checkRF(5)) RFControl(); // control via RF
Battery(); // signalizing battery error
ADControl(); // control via potentiometer
ButtonControl(); // control via button
// TR-52DA LED control:
if (CCPR3L == PWM_value && CCPR3L != 0)
_LEDG = 1;
else
_LEDG = 0;
}
}
Links:
Hi, can you tell me why do you use potentiometer? how they works?
expert
Hi, you can use this device without potentiometer, you can easy comment ADControl() function in main program to disable it. If you can use potentiometer, it’s not volume control :D, but it’s control of LED intensity.
and can you tell me on whitch freq it works? is possible to use it as driver for motor? thx a lot
Yes, it’s possible, it works with 2ms period.