Phone

    00852-6915 1330

ATMEGA328P-PU Based Switch Light Controller [FAQ]

  • Contents

Description

The weather in the past two days has suddenly cooled down, and I forgot to install a switch on the bedside, and I don’t want to get out of bed to turn off the light because of the cold. At this time, it would be nice to have an intelligent control switch.

This blog introduces a smart switch controller based on  ATMEGA328P-PU. The controller, without changing the existing switches and circuits, can automatically turn off the lights after a power failure. At the same time, the wireless control light switch function can also be realized through the Bluetooth module, and the light can be turned on and off while lying down, and there is no need to get out of bed.

 ATMEGA328P

ATMEGA328P-PU

Catalog

Description

I Introduction

II ATmega328P-PU Based System Priciple

III ATmega328P-PU Based System Hardware Design

3.1 Central control module

3.2 Light detection circuit

3.3 Bluetooth module

IV ATmega328P-PU Based Structure Design

V ATmega328P-PU Based System Software Design

VI Conclusion

Component Datasheet

FAQ

Ordering & Quantity

I Introduction

The smart switch light controller based on ATmega328P-PU introduced in this blog consists of the following modules:

  • Light Detection Module: Perceive the change of indoor light intensity;
  • Bluetooth Module: control and realize automatic light switch;
  • Steering Gear and Mechanical Linkage Mechanism: It can also automatically turn off the lights.

The controller uses the organic combination of mechatronics, which is reliable and easy to control.

II ATmega328P-PU Based System Priciple

The intelligent switch light controller system is mainly composed of light detection module, Bluetooth module, steering gear, and  Arduino control system. The system control process is as follows:

  1. The light detection module perceives the environment from bright to dark;
  2. The light detection module sends the sensed information to the Arduino;
  3. Arduino turns off the lighting equipment by controlling the steering gear according to this information;
  4. Or, to complete the operation of turning off the lights, you can also directly control it through the mobile phone APP Bluetooth.

The system principle diagram of the intelligent switch light controller is shown in Figure 1.

system schematic diagram

 

Figure 1. System schematic diagram

III ATmega328P-PU Based System Hardware Design

3.1 Central control module

The most widely used microcontrollers for the central control module are  AVR  and 51 microcontrollers. From the perspective of function and upgrade potential, the AVR 8-bit microcontroller ATMEGA328P-PU was selected as the central control module.

So, what are the advantages of the ATMEGA328P-PU control module? Why choose it?

ATMEGA328P-PU, as a central control module, has flexible I/O port resources and powerful functions. It not only has low power consumption but is reliable, and can meet the needs of subsequent equipment updates.

Figure 2 shows the minimum system diagram of ATMEGA328P.

ATMEGA328P minimum system

 

Figure 2. ATMEGA328P minimum system

3.2 Light detection circuit

Here, the light detection circuit is a four-wire system. The AO port is an analog signal output port, which converts the external light intensity into a continuous output voltage value.

When the brightness of the light changes, how does the DO port act as a digital signal output port?

  • When the ambient light brightness does not reach the set threshold, the DO terminal outputs a high level;
  • When the brightness of the ambient light exceeds the set threshold, the DO terminal outputs a low level.

Because the signal output by the circuit is stable and reliable, the controller selects the digital signal output by the DO port as the input signal of the control module. In this way, the sensitivity and reliability of the system can be improved.

Illumination detection circuit diagram is shown in Figure 3.

Illumination detection circuit diagram

 

Figure 3. Illumination detection circuit diagram

3.3 Bluetooth module

This blog uses the HC-05 master-slave integrated Bluetooth module. Its circuit diagram is shown as in Fig. 4.

Bluetooth detection circuit

Bluetooth detection circuit

Bluetooth detection circuit

Bluetooth detection circuit

Figure 4. Bluetooth detection circuit

The module adopts CSR mainstream Bluetooth chip, Bluetooth V2.0 protocol standard, and can work with 3.3V low voltage. It is cheap, small in size, stable in signal, low in power, and can be used in conjunction with mobile APP to realize wireless control of the system.

In this design, Bluetooth only acts as a slave, receiving instructions from the mobile phone.

IV ATmega328P-PU Based Structure Design

Take the dormitory as an example to design the controller for the switch (as shown in Figure 5).

 

Figure 5. Power switch

After measurement, when the switch is in the equilibrium position, that is, between the closed and open positions, if the light-off position is pressed more than 2mm, the button will turn off the power. When the light-on position is pressed down more than 2mm, the button will turn on the power.

We can design a link mechanism connected with the steering gear to make:

When the steering gear rotates to 180°, the connecting rod position is the highest;

When the steering gear rotates to 0°, the connecting rod position is lowest.

Then, set the initial position of the steering gear to 90°, so that the button is at the value of the balance position.

At this time, coincide the middle position of the "T"-shaped fixing bracket with the middle position of the button. In addition, in order to facilitate the realization of functions, the central position can be set as a chute.

Figure 6 shows the design and installation.

Figure 7 shows that the controller is designed as a rectangular box.

Figure 8 shows the layout of each module.

Figure 9 shows the physical object and installation diagram of the smart switch controller.

 

Figure 6. Design and installation drawing of connecting rod part

 

 

Figure 7. Overall view of the controller

 

 

Figure 8. Schematic diagram of each module installation

 

 

Figure 9. Physical image of smart switch controller

 

V ATmega328P-PU Based System Software Design

The software part completes the processing of the signals received by the light detection module and the Bluetooth module and then controls the mechanical structure to switch the lights.

Figure 10 shows the system software flow chart.

The light detection module (the schematic diagram of the light detection module is shown in Figure 11) is used to detect changes in the brightness and darkness of the surrounding environment.

  • When the surrounding environment is always in a light state, the light detection circuit  will continuously send a low-level signal "0" to the central control module;
  • When the surrounding environment has been in a dark state, the light detection circuit will continuously send a high-level signal "1" to the central control module.
  • When the surrounding environment changes from no light to light (judging the daybreak), in this case, the system does not act.
  • When the surrounding environment changes from light to no light (judged as a moment of power failure), the light detection circuit will start to send a high-level signal "1" to the central control module.

At the moment of transition, the central control module will control the system to execute a work cycle. After turning off the light, the system will automatically reset and wait for the next change from light to no light.

Because the port memory of the central control module is limited, the light detection circuit continuously transmits data to the port. This will cause the central control module to restart in a short time due to exhaustion of memory, making the system unstable and unreliable.

Therefore, a port clearing function is specially written when compiling the system to ensure that the expired data sent by the light detection circuit is cleared in time. Thereby improving the stability and reliability of the system.

 

Figure 10. System software flow chart

 

After talking about the light detection module, how does the Bluetooth module process the received signal to control the switch? We can use mobile phone APP and Bluetooth module to control the system to turn on and off the lights through wireless transmission.

When the mobile phone sends the command character "A" to the central control module through the Bluetooth module, the system will execute a cycle of turning off the lights, and then automatically reset;

In the same way, when the mobile phone sends the command character "B" to the central control module through the Bluetooth module, the system executes a light-on command for a working cycle, and then automatically resets.

 

Figure 11. Schematic diagram of the light module

 

VI Conclusion

The smart switch light controller discussed in this blog has significant advantages:

* Do not change the circuit of the original push-type power switch. Therefore, it is not only safe, but also easy to disassemble and assemble;

* Turn on and off the lights via Bluetooth wireless control. Therefore, it has strong operability;

* After completing the switch lamp work cycle, realize automatic reset. In addition, while realizing automation, we can also move our fingers to easily switch lights on the bed;

* ATmega328P-PU has great development potential. The reason for using it is to meet the needs of expanding functions in the future. such as:

    • Cooperate with WIFI module: can realize ultra-remote control;
    • Cooperate with timer: it can realize the function of turning on the lights at a time.

In summary, the intelligent switch light controller based on ATmega328P-PU we introduced is simple and reasonable in structure, easy to install, safe, convenient and efficient to operate.

With the smart switch light controller of ATmega328P-PU, when we lazily lie on the bed and play with the mobile phone, we use the mobile phone to control the light switch. At night, we are afraid that we forget to turn off the lights when we fall asleep, and we don’t need to get out of bed. It can also automatically turn off the lights when it gets dark.


Component Datasheet

ATMEGA328P Datasheet


FAQ

  • What is meant by ATMEGA328P?

ATMEGA328P is high performance, low power controller from Microchip. ATMEGA328P is an 8-bit microcontroller based on AVR RISC architecture. It is the most popular of all AVR controllers as it is used in ARDUINO boards.

  • What is the difference between ATMEGA328 and ATMEGA328P?

ATMEGA328P and ATMEGA328 are the same every sense architecturally.
ATMEGA328P just consumes lower power than ATMEGA328, which means that the 328P is manufactured in a finer process than the 328.

  • Why ATMEGA328 is used in Arduino?

The ATMEGA328/P is a low-power CMOS 8-bit microcontroller based on the AVR® enhanced RISC (reduced instruction set computer) architecture. In Order to maximize performance and parallelism, the AVR uses Harvard architecture – with separate memories and buses for program and data.

  • How do you code ATMEGA328P?

  • Is ATMEGA328P a microcontroller?

The ATMEGA328 is a single-chip microcontroller created by Atmel in the megaAVR family (later Microchip Technology acquired Atmel in 2016). It has a modified Harvard architecture 8-bit RISC processor core.

  • Can the ATMEGA328P microcontroller be used without the Arduino board?

Yes. You can use ATMega328P without arduino board. ... You can use arduino board with the IC. Program the IC and then take it out and use it in your circuit. You will have to use 16MHZ Oscillator with capacitors.

  • How do I program Atmega328P without bootloader?

Programming AVR With Arduino As ISP Without Bootloader and External Crystal
Step 1: Things You Need. ...
Step 2: Upload ArduinoISP Code on Arduino Board. ...
Step 3: Open Command Prompt (in Windows OS) ...
Step 4: Required Downloads.. ...
Step 5: Installation of WinAVR (only Help for Windows OS Is Covered for Now)

Kynix

Kynix was founded in 2008, specializing in the electronic components distribution business. We adhere to honesty and ethics as our business philosophy and have gradually established an excellent reputation and credibility in our international business. With the accurate quotation, excellent credit, reasonable price, reliable quality, fast delivery, and authentic service, we have won the praise of the majority of customers.

Join our mailing list!

Be the first to know about new products, special offers, and more.

Leave a Reply

We'd love to hear from you! Feel free to share your thoughts and comments below. Rest assured, your email address will remain private.

Name *
Email *
Captcha *
Rating:

Kynix

  • How to purchase

  • Order
  • Search & Inquiry
  • Shipping & Tracking
  • Payment Methods
  • Contact Us

  • Tel: 00852-6915 1330
  • Email: info@kynix.com
  • Follow Us

authentication

Kynix

© 2008-2026 kynix.com all rights reserved.