Older projects

Well, there are always some minor projects going on (mostly in my head), but few worth to mention are listed here:

Rep.KlockaRGB – This was made for my buddies at work, formerly called ‘Reparationverkstad klocka RGB’, freely translated as Mainentace workshop clock RGB. It’s purpose is to light up a RGB-strip inside a very big wall clock, in different colors at certain timestamp like coffee breaks, lunch and so on. The project was a bit design overkill with EEPROM saved timestamps, battery backupped RTC (real time clock), that is capable for running for years even without powered up from mains. Also it has Bluetooth connection to adjust the time and memory and it can switch in and out to daylight saving zone.

it runs on Arduino Nano (compatible), RTC DS3231, Bluetooth HC-05 and 3x IRF540 mosfet as power stage.




Rotary light – This one isn’t really Arduino, but who cares. It’s one fun project I made at summer 2016¬†with a PIC.
It works by dialing number from 0 to 9, where 0 is off and 9 has maximum power. Every other number between has of course the corresponding power setting.
Runs on 12F683, MOSFET-transistor and 2 x 4W white led chips.


Edit: 2017-10-05 – Added source code and schematics

Edit: 2017-11-15 – Changed the PWM-frequenzy from 250 to 25,000 Hz.

Here is the source code in C for the PIC.
it is very easy to port to Arduino if you want to use that instead. Arduino has ‘analogWrite(PIN, pwm)’ function that can be used.
Comments are under/after the respective function.

sbit Puls at GP0_bit;
sbit Rotary at GP1_bit;
// These 2 are for pin initialization - use 'PinMode' for Arduino,
// 2 digtal inputs and 1 PWM output needed.
int pwmvalues[10] = {0, 26, 51, 77, 102, 128, 153, 179, 216, 255}  ; 
// The PWM values are in the array, each digit has it own hardcoded brightness
// Edit the values if needed. 0=0% and 255=100% brightness.
int counttimes, stateb;


void main() { 
// For Arduino this is the 'void setup()'
// Note that these are only needed for the PIC, 
// for Arduino you only need the 2 variables: counttimes and stateb set to 0.
// and add some PIN definitions
  ANSEL = 0;            // All I/O pins are configured as digital
  CMCON0 = 7;           // Disable Comparators
  TRISIO.B2 = 0;        // Set GP2 (pin 5) as output
  TRISIO.B1 = 1;        // Set GP1 as input
  TRISIO.B0 = 1;        // Set GP0 as input
  PWM1_Init(25000);       // Set 25kHz frequency 
                  // ( EDIT: The 25kHz frequency ensures that the light is not flickering.)
  PWM1_set_duty(0);     // Set 0% duty cycle
  PWM1_START();         // Start the PWM

                        
  counttimes = 0;
  stateb = 0;
  // keep these for Arduino

  while (1) { // For Arduino this is the 'void loop()'


    if (Rotary) { // check if the Rotary input goes high
      delay_ms(150);
      counttimes = 0;
      while (Rotary) { // While the Rotary input is high...

        if (!Puls){ // Everytime the Puls input goes low
          delay_ms(50);
          stateb = 1;

          if (Puls && stateb) { 
            stateb = 0;
            PWM1_SET_DUTY(pwmvalues[counttimes]); 
            // set the PWM output from pulses (pulse count = index of the array)
            // For Arduino use: analogWrite(PIN#, pwmvalues[counttimes]);
            counttimes++;
          }
        }
      }
    }

    Delay_ms(50);

  }
}

The schematics:
(You can eliminate the optocoupler 4N35 and replace it with any common NPN transistor like 2N3904 or BC548 etc. See the previous post above for updated LED-driver.)
The rotary dial is from Swedish LM Ericsson Dialog phone (with zero before #1). Wire colors are matched for this dial.

NOTE: Use 1K resistor on R4, to ensure that the gate voltage drops down enough.¬†(I’ll update the PDF later on…)

View Fullscreen