Unofficial Nextion/TJC User Forum

Zero Cross dimming

Hello, i want to dimm a 230V Lamp with the Nextion Slider and a Arduino Mega.
The Hmi file is ready.
Does anybody made a Arduino code for such a projekt?
Thanks

No way to dim an f*ing 230v lamp with a MEGA.

Perhaps yes… Nextion slider -> Mega PWM -> optocoupler -> Power management IC with integrated zero-cross detection -> Triac

Thanks
i have a AC dimmer module from robotdyn. Now i need the Arduino Mega code to control it with the nextion slider, PWM and zerocross Signal. Maybe somebody from you made such a projekt allready?

Did you see that robotdyn has a library for the Mega on GitHub which handles all the zero crossing stuff through a pin 2 interrupt and has lots of examples? With that, you’d only have to extend the code a little to get the slider value from the Nextion periodically and to translate it into a control value.

1 Like

There are many examles but to integrate a h0 slider is to complicated for me.
i think i must search for a manufacture code.

to integrate a h0 slider is to complicated

It’s not.

  • On your nextion:

    • Set h0.minval to 0
    • Set h0.maxval to 100
    • h0 Touch Release Eevent:
      prints h0.val,1
      And if you want to display the current value lets say on n0:
      n0.val=h0.val

    Done. Each time you move the slider the Arduino receives the slider position as value from 0-100.

  • Now for the Arduino: Take the serial example you find under the link above.

    • Remove all serial prints. We don’t want to send any data from the Arduino to the Nextion.
    • Replace the void loop() content by this:
      if (USE_SERIAL.available())
      {
        int val = USE_SERIAL.read();
        dimmer.setPower(val);
      }
      

    Done.

That’s a total of 4 (!) code lines you have to write. I hope the task doesn’t look that complicated anymore. :wink: I mean, you bought a Nextion Touch Screen and an Arduino Mega. Both are devices that are not ready to use but need programming. Therefore, IMHO you should be willing to play a bit with it on your own, and gather at least some basic experience on how to program them.

Oh, and another tip for the future: asking for ready-to-use solutions in a forum rarely works. Most people are here because they want to help each other. Helping and doing someone else’s work are two completely different things. Ask specific questions, and show what you’ve already tried or researched. F.ex. I’m pretty sure there are plenty of example codes out there that show you how to read a slider or any other Nextion component from an Arduino. They probably work a bit different than my example but aren’t complicated either.

Kind regards,
Max

1 Like

Thanks for your solution. I added the line “prints h0.val,1”
to the touch move event, so the dimmer works exakt to the sliding.


This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).