Hello guys, i found this site very helpful to my project, i hope someone can help me regarding my project.

I'm creating a code for lighting 3 bulbs using a relay module(4 channel) and 3 push buttons, but couldn't make it work.

After I press the first pushbutton I want light1 to be energized for 20s, Then after i press button2, light2 will be energized for 30s, After i press button3, light3 will be energized for 40s.

I hope someone can help me creating a code for this project. Thanks.

I Think the example "doing several things at once" might help your project.

But you might want to explain what you're planning on doing with 230v.

I would make sure your hardware is connected properly first. For example, to connect your 4 relay module properly, it needs to have the jumper removed. There'll be 3 pins exposed here. Then you'll need to connect a separate DC power supply to the JD-VCC terminal and GND terminal. The only connections to the Arduino is IN1, IN2, IN3, IN4, VCC. There is no GND connection to your Arduino. There is no GND connection to your Arduino. Did I say that already?

Anyways, a diagram or description of your connections would be helpful.

I think the code of that is similar to toggling a led,

Buti dont know how to work that with 3 lush button and 3 led

Suggestion: Start simply and get the code right first. Instead of connecting the relay module, simply connect leds (with series resitors) to the same pins. Write some test code to latch one of the leds for a certain amount of time. Then expand from there. Here is an example

// Latch example (not optimised)
// button wired between pin and ground. LOW when pressed.

byte relayPin1 = 13 ;
byte buttonPin1 = 10 ;
unsigned long buttonPressTimeMs1 = 0 ;

void setup() {
  pinMode( relayPin1, OUTPUT ) ;
  pinMode( buttonPin1, INPUT_PULLUP ) ;   

void loop() {
  if ( digitalRead( buttonPin1 ) == LOW ) {
    buttonPressTimeMs1 = millis() ;
    digitalWrite( relayPin1, HIGH ) ;
  if ( millis() - buttonPressTimeMs1 > 12000UL ) {   // 12 seconds
    digitalWrite( relayPin1, LOW ) ;