element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Achievement Levels
    • Benefits of Membership
    • Feedback and Support
    • Members Area
    • Personal Blogs
    • What's New on element14
  • Learn
    Learn
    • eBooks
    • Learning Center
    • Learning Groups
    • STEM Academy
    • Webinars, Training and Events
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Arduino Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Project Groups
    • Raspberry Pi Projects
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Or 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
Photonics
  • Challenges & Projects
  • Project14
  • Photonics
  • More
  • Cancel
Photonics
Blog Simple light flicker meter
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Photonics requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: kk99
  • Date Created: 8 Mar 2020 4:44 PM Date Created
  • Views 3267 views
  • Likes 18 likes
  • Comments 11 comments
  • esp32
  • light
  • led
  • photonicsch
  • flicker
  • m5stick
Related
Recommended

Simple light flicker meter

kk99
kk99
8 Mar 2020

image

The basic idea was to create a simple device which allow to compare the quality of light sources e.g. LED bulbs. I have used TSL250R IC containing photodiode and operational amplifier with configured feedback loop. This IC is optical sensor which output voltage is proportional to light intensitivity. I have put this sensor inside to M5Stick case and connected directly to ESP32 module. Output from sensor is connected to GPIO with number 35. Below there are images with mounted sensor:

image

image

Output data is sampled by ADC which is triggered by hardware timer of ESP32 board.

After sampling there is calculated FFT. After that there is obtained frequency for maximum peak.

Additionally there is displayed a plot with input data, so we could see amplitude of input signal.

All data are presented on OLED display.

Below there is diagram with flow:

 

image

Program was written in C with usage of ArduinoFFT and U8g2 libraries. Below there is source:

#include <Arduino.h>
#include <U8g2lib.h>
#include <arduinoFFT.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif

U8G2_SH1107_64X128_F_4W_HW_SPI u8g2(U8G2_R1, /* cs=*/ 14, /* dc=*/ 27, /* reset=*/ 33);

arduinoFFT FFT = arduinoFFT();
hw_timer_t *timer = NULL;
bool getSample;
const byte maxSamples = 128;
const word samplingFrequency = 2000;
double vReal[maxSamples];
double vImag[maxSamples];

void timerInterrupt() {
  if (!getSample) {
    getSample = true;
  }
}

void setup() {
  u8g2.begin();
  u8g2.setFont(u8g2_font_5x7_tr);
  analogReadResolution(12);
  getSample = false;
  timer = timerBegin(0, 80, true);
  timerAttachInterrupt(timer, &timerInterrupt, true);
  timerAlarmWrite(timer, 1000000/samplingFrequency, true);
  timerAlarmEnable(timer);
}

void loop() {
  word adcData[maxSamples];
  byte sampleCount = 0;
  bool adcDataReady = false;
  do {
    if (getSample && !adcDataReady) {
      adcData[sampleCount] = analogRead(35);
      sampleCount++;
      if (sampleCount >= maxSamples) {
        adcDataReady = true;
        sampleCount = 0;
      } else {
        getSample = false;
      }
    }

    if (adcDataReady) {
      char displayText[16];
      for (byte i = 0; i < maxSamples; i++) {
        vReal[i] = double(adcData[i]);
        vImag[i] = 0;
      }
      FFT.Windowing(vReal, maxSamples, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
      FFT.Compute(vReal, vImag, maxSamples, FFT_FORWARD);
      FFT.ComplexToMagnitude(vReal, vImag, maxSamples);
      word peak = FFT.MajorPeak(vReal, maxSamples, samplingFrequency);
      adcDataReady = false;
      getSample = false;
      u8g2.clearBuffer();
      snprintf (displayText, 8, "%dHz", peak);
      u8g2.drawStr(65, 10, displayText);
      word r = 1 << 12;
      r = r / 54;
      for (byte i = 0; i < maxSamples; i++) {
        u8g2.drawPixel(i, 54-(adcData[i] / r));
      }
      u8g2.sendBuffer();
      delay(100);
    }
  } while (true);
}

 

Below there is short video presentation. We could see here a two different LED light sources with different flicker (high and low).

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

More details about light flicker in LED lamps you could find in this document:

LED flicker

 

The interesting improvement could be added measurement of light spectrum with additional sensor.

Attachments:
lightFlickerMeter.zip
  • Sign in to reply

Top Comments

  • genebren
    genebren over 3 years ago +5
    Awesome project. I worked in the lighting industry for a while and we did a lot of testing on our Zigbee mesh light controllers (and the attached luminaries, with their own driver/controller) to measure…
  • three-phase
    three-phase over 3 years ago +4
    Interesting project and works really well. I never really thought of LEDs have any flicker to their light output. Kind regards.
  • dougw
    dougw over 3 years ago +3
    Very nice project. What would it show for a fluorescent bulb?
  • peterw1956
    peterw1956 over 3 years ago

    Thanks kk99. Finally got a sensor! Now I just need to figure out how to get the board out of the case.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • kk99
    kk99 over 3 years ago in reply to peterw1956

    You could use TSL257 or any similar light to voltage converter.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • peterw1956
    peterw1956 over 3 years ago

    II am in Australia and finding it difficult to source the TSL250R ic. Is there an alternative that would be suitable please?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • kk99
    kk99 over 3 years ago in reply to shabaz

    This board is called M5StickC and it is available here:
    https://m5stack.com/products/stick
    But I do not know if it is still supported by UIFlow etc.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 3 years ago

    Cool project! It functions very well.

    What's the ESP module? I've not seen one with that connector and LiPo capability.

    • Cancel
    • Vote Up +3 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 © 2023 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