element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Experimenting with Flyback Transformers
  • Challenges & Projects
  • Design Challenges
  • Experimenting with Flyback Transformers
  • More
  • Cancel
Experimenting with Flyback Transformers
Blog Blog 5 - Magic Light Box: Building The Prototype
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experimenting with Flyback Transformers to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: javagoza
  • Date Created: 23 Jan 2024 11:13 PM Date Created
  • Views 928 views
  • Likes 12 likes
  • Comments 2 comments
  • arduino uno
  • EXPERIMENTING WITH FLYBACK TRANSFORMERS
  • bourns
Related
Recommended

Blog 5 - Magic Light Box: Building The Prototype

javagoza
javagoza
23 Jan 2024
Blog 5 - Magic Light Box: Building The Prototype

Disclaimer: The content presented in this blog showcases the results of conducted experiments. The schematics provided depict the components used in these experiments. The experimentation involved a commercial LED bulb with its own regulator, solely for the purpose of demonstrating the circuit's capabilities for LED dimming. There is no guarantee that it will function under different conditions. Please read the information in the comments section regarding potential issues with this design.

Table of Contents

  • Crafting the Magic Lightbox Prototype: From Concept to Foam Board Reality
  • Magic Lightbox High Level Design
  • Magic Lightbox Dimmable LED Driver Prototype Schematics
  • Magic Lightbox Use Cases
  • Magic Lightbox Test Mockup Construction
  • Unit Testing the Lightbox. It Turns On and Lights Up.
  • Manual dimmer. Changing the duty cycle with a rotary encoder
  • Prototype Firmware for the Magic Lightbox
  • Testing Prototype Firmware for the Magic Lightbox. Simulation mode
  • Magic Lightbox Blog Series

Crafting the Magic Lightbox Prototype: From Concept to Foam Board Reality

As we reach the culmination of our adventure, it's time to bring the Magic Lightbox to life with our first prototype. In this blog, we'll consolidate all our learnings to design the prototype schematic and embark on the construction of our first model using foam board.

image

Magic Lightbox High Level Design

The Magic Lightbox system comprises:

  • A chassis
  • Two LED Lamps
  • One Arduino microcontroller 
  • One microcontroller with camera sensor
  • Adjustable Switched Mode Flyback Converter Using Analog-to-Digital Current Feedback

Magic Lightbox High-Level Circuit Diagram

image

Explanation of the Diagram:

PID Controller: The PID controller regulates a closed-loop system to reach the desired output state. It consists of three elements providing Proportional, Integral, and Derivative actions. The PID controller calculates the difference between actual and desired current, adjusting based on current error, past errors, and future error predictions.

PWM Controller: Pulse Width Modulation (PWM) modifies the duty cycle of a periodic signal, controlling the energy stored in the Flyback transformer.

Flyback Converter: A DC-to-DC converter with galvanic isolation between input and output. When activated, the primary coil connects to the power source, increasing magnetic flux in the core. The secondary voltage is negative, keeping the diode blocked. Power to the load comes from the output capacitor. When the switch is open, energy stored in the core transfers to the LEDs and the output capacitor.

Current Probe: Measures current without direct series connection. Converts current to voltage for measurement using an analog-to-digital converter.

Computer Vision Controller: Analyzes image contrast and suggests a target current value for the PID controller.

Camera: Captures light, converting it into an electrical signal processed to form a digital image.

Magic Lightbox Dimmable LED Driver Prototype Schematics

This the electronic circuit governing our dimmable LED panel.

Magic Lightbox Prototype 1

Let's delve into its key sections:

image

Section 1: Arduino R4 PWM Signal Generation

At the heart of the system is an Arduino R4 responsible for generating the PWM signal that regulates the MOSFET's on-off cycles. This PWM signal is intentionally inverted, passing through an inverter to safeguard the Arduino's output PIN, which supports a limited current of 8 mA. There is a pull-up resistor for when the Arduino output port is in an unstable or undefined state.

image

Section 2: NPN Inverter and Totem-Pole MOSFET Driver

The inverted PWM signal flows into an NPN Transistor inverter. The output goes to new stage comprising two complementary transistors (NPN-PNP pair) in a totem-pole configuration. This setup provides the required current and voltage for the MOSFET switching.

image

Section 3: MOSFET Protection with Voltage Clamp

Ensuring the MOSFET's longevity and reliability, a protective voltage clamp is implemented. This feature shields the MOSFET from potential voltage spikes that could arise during operation. The clamp consists of a fast diode and a Zener diode, effectively limiting voltage peaks and safeguarding the MOSFET against damage.

image

Section 4: Bourns BA60951CS Flyback Transformer 

The Bourns BA60951CS Flyback Transformer takes center stage. This transformer stores energy as magnetic flux when the MOSFET switches to the "on" position and subsequently releases that energy to the transformer's secondary circuit when it switches to "off".

image

Section 5: Secondary Diode

On the secondary side, a fast diode plays a pivotal role. This diode prevents the flow of current when the MOSFET switch is in the "on" position but permits it when the MOSFET switch transitions to "off." At this moment, the primary inductance, charged during the "on" cycle, acts as a generator, contributing to a continuous flow of energy. An RC snubber network protects the diode.

image

Section 6: Secondary: Filter Capacitor

On the secondary side, a filtering capacitor charges and acts as an "electricity pump" for the load. 

image

Section 7:LED Driver and Load

The load consists of 12 LEDs grouped into 4 sets of three LEDs, all controlled by an LED Driver. The LED driver is a CL6807 LED driver.

image

Section 8: Current Sensing Probe

In this section, a dedicated current sensing probe plays a crucial role. It generates a voltage signal that mirrors the magnitude of the current flowing through the secondary circuit to the load. The generated voltage from the current sensing probe is integrated into one of the channels of the Arduino R4's 14-bit analog-to-digital converter (ADC). This high-resolution converter provide the measurement of the current signal, providing the Arduino with data for real-time monitoring and control. 

image

Section 9: Simulation with Rotary Encoder

This segment introduces a rotary encoder, serving as a valuable tool for simulating incremental and decremental signals corresponding to the desired setpoint for the PID controller. The encoder's rotation allows for dynamic adjustments, mimicking the real-world scenarios the system is designed to encounter during operation.

Magic Lightbox Use Cases

The Magic Lightbox serves as a versatile tool for various applications, with its primary focus being on the photography of small electronic components. Its equipped with two softbox-style LED lights on the sides of the cube. The open top allows for additional overhead lighting, and the front opening accommodates the camera.

image

image

Magic Lightbox Test Mockup Construction

The prototype of the Magic Lightbox is crafted using white foam board, with the interior forming a cube measuring 10x10x10 cm.

image

Prototype Material:

Material: White foam board
Internal Dimensions: 10x10x10 cm (Cube)
Lighting Specifications:

  • LED Lights: Two LED lights are integrated, each capable of emitting up to 200 lumens.
  • LED Power Rating: 2W per LED
  • LED Current: Rated at 248 mA

image

Unit Testing the Lightbox. It Turns On and Lights Up.

Before integrating the complete Magic Lightbox system, a preliminary unit test connecting the two lamps directly to a power source, bypassing our control circuit. This preliminary test allows us to ensure that each lamp unit operates as expected before incorporating them into the complete Magic Lightbox system.

image

Manual dimmer. Changing the duty cycle with a rotary encoder

In the testing phase, the prototype incorporates a rotary encoder as an input device to simulate the increment and decrement signals that would be sent by the contrast sensor.

 Rotary Encoder Module

image

// This example checks the state of the rotary encoder using interrupts and in the loop() function.
// The current position and direction is printed on output when changed.
// Credits to Matthias Hertel, http://www.mathertel.de

// Hardware setup:
// Attach a rotary encoder with output pins to
// * D4 and D5 
// Swap the pins when direction is detected wrong.
// The common contact should be attached to ground.
//

#include <Arduino.h>
#include <RotaryEncoder.h>

#define PIN_IN1 D4
#define PIN_IN2 D5

// A pointer to the dynamic created rotary encoder instance.
// This will be done in setup()
RotaryEncoder *encoder = nullptr;

void checkPosition()
{
  encoder->tick(); // just call tick() to check the state.
}

void setup()
{
  Serial.begin(9600);
  while (!Serial)
    ;
  Serial.println("InterruptRotator example for the RotaryEncoder library.");

  // setup the rotary encoder functionality
  // use FOUR3 mode when PIN_IN1, PIN_IN2 signals are always HIGH in latch position.
   encoder = new RotaryEncoder(PIN_IN1, PIN_IN2, RotaryEncoder::LatchMode::FOUR3);

  // register interrupt routine
  attachInterrupt(digitalPinToInterrupt(PIN_IN1), checkPosition, CHANGE);
  attachInterrupt(digitalPinToInterrupt(PIN_IN2), checkPosition, CHANGE);
} // setup()


// Read the current position of the encoder and print out when changed.
void loop()
{
  static int pos = 0;

  encoder->tick(); // just call tick() to check the state.

  int newPos = encoder->getPosition();
  if (pos != newPos) {
    Serial.print("pos:");
    Serial.print(newPos);
    Serial.print(" dir:");
    Serial.println((int)(encoder->getDirection()));
    pos = newPos;
  } // if
} // loop ()

Prototype Firmware for the Magic Lightbox

For the prototype model of the Magic Lightbox, the firmware orchestrates the control and interaction between various components.

Here's an overview of the whole firmware functionalities:

PWM signal for MOSFET Control:

The firmware on the Arduino R4 governs the overall control system. It generates the PWM signals to regulate the MOSFET, managing the LED intensity based on the desired luminosity.

PID Controller Integration:

Incorporates a PID controller within the Arduino firmware. Ensures precise regulation of LED brightness by continuously adjusting the duty cycle based on the feedback from the contrast sensor.

Contrast Sensor Communication:

Manages communication with the contrast sensor module. Retrieves feedback on the contrast level of the scene to dynamically adjust the LED brightness.

Softstart Algorithm:

Implements a softstart algorithm to gradually increase the LED intensity, preventing sudden spikes that may impact the system.

Encoder Input Handling:

Integrates the input from the rotary encoder for simulation purposes. Mimics the signals expected from the contrast sensor, allowing comprehensive testing and validation.

ADC for Current Measurement:

Utilizes the Analog-to-Digital Converter (ADC) to measure the current in the secondary circuit, providing valuable data for system monitoring.

Simulation Mode:

Enables a simulation mode using the rotary encoder to replicate scenarios without the actual contrast sensor.

Testing Prototype Firmware for the Magic Lightbox. Simulation mode

#include "pwm.h"
#include "math.h"

#include <Arduino.h>
#include <RotaryEncoder.h>

// PWM PERIOD FOR A 100 kHz frequency, 10 us
#define PWM_PERIOD_USEC 10 
// Arduino output port for the PWM signal
#define PWM_SIGNAL_PIN D3
// Encoders PINS
#define PIN_IN1 D4
#define PIN_IN2 D5

#define PWM_SOFTSTART_TARGET_DUTY_PCTE 15.0
#define PWM_TIME_BETWEEN_TRANSITIONS_MS 10

const int analogInPin = A1;  // Analog input pin that the current sensor is attached to
float sensorValue = 0.0;  // value read from the pot
float actualPercentage = 0.0;

PwmOut pwm(PWM_SIGNAL_PIN);

#define PIN_IN1 D4
#define PIN_IN2 D5

// A pointer to the dynamic created rotary encoder instance.
// This will be done in setup()
RotaryEncoder *encoder = nullptr;


/**
* PRE: Given the Duty cycle in percentage 0.0 to 100.0
* for the inverted pwm signal High off, Low on.
* POS: Sets the pwm duty cycle for the inverted 
* pwm signal. High off, Low on.
*/
bool invertedPwmPerc(float invert_duty_cycle_pcte) {
  if (invert_duty_cycle_pcte > 100.0) {
    invert_duty_cycle_pcte = 100.0;
  }
  if (invert_duty_cycle_pcte < 0.0) {
    invert_duty_cycle_pcte = 0.0;
  }
  return pwm.pulse_perc(100.0 - invert_duty_cycle_pcte);
}

/**
* PRE: Given the initial duty cycle in percentage 0.0 to 100.0,
* the target duty cycle in percentage 0.0 to 100.0 for the PWM signal
* and the dalay between steps
* POS: Performs a soft transition between the two duty cycles
*/
bool pwmSoftTransition(float initial_duty_cycle, float target_duty_cycle, float time_steps_ms) {
  float pcte_increments;

  if (target_duty_cycle > initial_duty_cycle) {
    pcte_increments = .1;
  } else {
    pcte_increments = -.1;
  }

  int steps_delay = (int)(abs(target_duty_cycle- initial_duty_cycle) / .1);

  float percentage = initial_duty_cycle;
  for (int i = 0; i < steps_delay; ++i) {
    percentage += pcte_increments;
    bool success = invertedPwmPerc(percentage);
    if (!success) {
      return false;
    }
    actualPercentage = percentage;
    delay(time_steps_ms);
  }
  return true;

}

/**
* PRE: Given the target duty cycle in percentage 0.0 to 100.0 for the PWM signal
* and the delay between steps in ms
* POST: Performs a soft start till reaching the target duty cycle
*/
bool pwmSoftStart(float target_duty_cycle, float time_steps_ms) {
    return pwmSoftTransition(0.0, target_duty_cycle, time_steps_ms);
}

void setUpPWMSignal() {
  pwm.begin(PWM_PERIOD_USEC, 0.0);
  pwmSoftStart(PWM_SOFTSTART_TARGET_DUTY_PCTE, PWM_TIME_BETWEEN_TRANSITIONS_MS);
}

void setUpADCForCurrentSensor() {
  analogReadResolution(14); //change to 14-bit resolution
}


void checkPosition()
{
  encoder->tick(); // just call tick() to check the state.
}

void setup()
{
  Serial.begin(9600);
  while (!Serial)
    ;
  Serial.println("InterruptRotator example for the RotaryEncoder library.");

  // setup the rotary encoder functionality
  // use FOUR3 mode when PIN_IN1, PIN_IN2 signals are always HIGH in latch position.
   encoder = new RotaryEncoder(PIN_IN1, PIN_IN2, RotaryEncoder::LatchMode::FOUR3);

  // register interrupt routine
  attachInterrupt(digitalPinToInterrupt(PIN_IN1), checkPosition, CHANGE);
  attachInterrupt(digitalPinToInterrupt(PIN_IN2), checkPosition, CHANGE);

  setUpADCForCurrentSensor();

  setUpPWMSignal();
} // setup()


// Read the current position of the encoder and print out when changed.
void loop()
{
  static int pos = 0;

  encoder->tick(); // just call tick() to check the state.

   int newPos = encoder->getPosition();


    if (pos != newPos) {
    
    if ((int)(encoder->getDirection()) == 1) {
      if (actualPercentage < 45) {
        pwmSoftTransition(actualPercentage, actualPercentage + 1, PWM_TIME_BETWEEN_TRANSITIONS_MS);
      }

    } else if (actualPercentage > 0 ){
        pwmSoftTransition(actualPercentage, actualPercentage - 1, PWM_TIME_BETWEEN_TRANSITIONS_MS);
    };
    pos = newPos;
  } 

      // read the analog in value:
  float sensorValueOld = sensorValue;
  sensorValue = 0.0;
  
  sensorValue += analogRead(analogInPin);
    // wait 2 milliseconds before the next loop for the analog-to-digital
    // converter to settle after the last reading:
     delay(2);
  
  
} // loop ()

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Magic Lightbox Blog Series

  •  Blog 1 - Magic Lightbox: Smart LED Dimmer Flyback Driver Project Introduction. 
  •  Blog 2 - Magic Lightbox: Understanding Flyback Transformers. How to characterize them. 
  •  Blog 3 - Magic Lightbox: Understanding Flyback Converters. 
  •  Blog 4 - Magic Light Box: DC/DC Flyback Converter Testbench and LED Dimmer Driver 
  •  Blog 5 - Magic Light Box: Building The Prototype 
  •  Final - Magic Lightbox: Project Summary 


  • Sign in to reply

Top Comments

  • jc2048
    jc2048 over 1 year ago +1
    In the schematic in your blog, the load is an LED driver (buck switcher) that is controlling a string of LEDs. Normally, that switcher would be trying to regulate the current through the LEDs. Your control…
  • javagoza
    javagoza over 1 year ago in reply to jc2048

    Thanks for the comments and warnings jc2048 , they are very welcome, I have added a disclaimer at the beginning of the blog in case I did not make the objective of the design clear.

    All your advice is very accurate and you are right, the lack of time led me to prioritize what to show.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jc2048
    jc2048 over 1 year ago

    In the schematic in your blog, the load is an LED driver (buck switcher) that is controlling a string of LEDs. Normally, that switcher would be trying to regulate the current through the LEDs. Your control loop is finding supply voltages for it where it doesn't function properly but has the switch on enabling current flow through the LEDs (suggests it's probably a self-oscillating hysteretic part). Whilst that is working for you, it is messy and it confused me as to what you were trying to show me. Personally, I'd have started with a resistive load (resistance similar to the dynamic resistance of the LEDs at the operating current) and then moved to a simple string of LEDs when I knew that the control loop was functioning and controlling the current properly.

    If anyone tries to replicate what you've done, there's also a "gotcha" built in. Consider what happens if your control loop is set to a higher current than the buck converter works to. Your loop will raise the voltage on C13 in the expectation that the current will increase, but it won't because the buck converter will reduce its duty cycle to compensate. Your loop will again up the voltage, and so on. With the LED controller functioning, there is no 'right' voltage for C13. So, make sure you have some mechanism to limit the voltage before something gets damaged.

    Ideally, I'd have liked to have seen more on the loop control and how it responded dynamically, but I can see that you ran out of time after an extensive and demanding design challenge, so not to worry.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube