Microcontroller Example for Detecting Ambient Light and Controlling Lighting

Publisher:chunliLatest update time:2012-07-23 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

A previous Design Idea (Reference 1) used an LED as a transducer to measure ambient light intensity and provide illumination. This Design Idea uses the same principles, but only has an LED, two resistors, an IC, and a 0.1mF bypass capacitor. No additional components are required when the circuit is used to provide ambient light feedback. Although the circuit in Figure 1 requires only a few components, it still has considerable flexibility because the microprocessor software controls the brightness of the LED and its relationship to the ambient light level. For night-time lighting applications, one mode can illuminate the LED when the ambient light decreases. Conversely, for power-saving adjustment of the LCD backlight in a portable device, a second mode can illuminate the LED when the ambient light level increases.

Table 1 shows the sample code for this design example, which can be downloaded and provides 64 levels of PWM (pulse width modulation) intensity control for the brightness of the LED in both modes. When used, a multifunction pin of the microprocessor drives the LED with a PWM waveform for hundreds of milliseconds. After the last cycle of the waveform, the software switches the microprocessor pin to input mode and connects the LED to the microprocessor's internal 16-bit S-ΔADC. Ambient light generates a voltage on the LED, which is measured by the ADC and the microprocessor calculates the PWM waveform parameters for the next series of illumination cycles. Because the cycle rate has a high repetition rate, any visible flicker on the LED is eliminated.

The entire circuit consists of an LED, a microprocessor, two resistors and a capacitor.

In the table, when the software and the ambient light level determine that the LED should be turned off for an extended interval, the CPU enters a low power state for 250 ms. During this sleep mode and the hundreds of microseconds while the ADC conversions are being made, the circuit consumes only about 20 mA, making it ideal for battery-powered systems.

At startup, the microprocessor stores the initial voltage produced by an LED and uses this value to convert the PWM level. Shading the LED or moving the circuit to a dark area instantly increases the brightness of the LED, which is controlled in small steps by the 64 PWM levels in the table. The ADC input impedance of the MSP430F2013 is about 200 kΩ. When driving this impedance, the LED occupying the footprint of a 0805 surface mount package only produces a few tens of millivolts. However, the MSP430F2013's 16-bit ADC has enough resolution to resolve the LED voltage to ensure good performance under normal room light intensity.

Sample Code

Additionally, the MSP430F2013 contains a four-stage PGA (programmable gain amplifier) ​​that provides gains of 1, 4, 8, and 16, further amplifying the tiny output voltage of the LED. The circuit also uses the microprocessor's on-chip low-frequency clock oscillator, allowing low-power operation without an external crystal. The final circuit has only six components, including a battery. It is worth noting that the code can be executed on the Texas Instruments eZ430 demonstration board without hardware modification, because the board contains an LED connected to port P1.0.

Reference address:Microcontroller Example for Detecting Ambient Light and Controlling Lighting

Previous article:Infrared remote control mouse
Next article:Single Line Technique for Driving Bar Graph Displays from Microcontroller I/O Ports

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号