Solid state relay and mosfet triggering using Arduino Mega

Why this code only actuates for the relay (pin 8) not for the Mosfet switch at pin 2. can you help me with the error.

int relayPin = 8;// set pin 8 for relay output
int injectorPin = 2;

void setup() {
pinMode(injectorPin, OUTPUT); // set pin 2 as injector
pinMode(relayPin, OUTPUT); // for relay
}

void loop() {
digitalWrite(injectorPin, HIGH); // turn on second light
delay(5); // wait for 3 milliseconds
digitalWrite(injectorPin, LOW); // turn off second light
delay(5000); // wait for 1 hr before starting again

// Turn the relay switch ON
digitalWrite(relayPin, HIGH);// set relay pin to HIGH
delay(90000);

// Turn the relay switch OFF (Robjax.com source code for YouTube Videos)
//digitalWrite(relayPin, LOW);// set relay pin to LOW
delay(300000);

}

I moved your topic to an appropriate forum category @sridharsahoo366.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Which MOSFET are You using? It must be a logic level N channel MOSFET.

digitalWrite(injectorPin, HIGH); // turn on second light
delay(5); // wait for 3 milliseconds
digitalWrite(injectorPin, LOW); // turn off second light

You turn the output on for 5 ms.
What is the MOSFET driving?
Can you see 5ms?

You need to realise that using delay function stops your whole code for that time, nothing happens.
So.

delay(90000);

Is a 90 second STOP in your code.

Tom... :smiley: :+1: :coffee: :australia:

This code works well for injector operation. This is a 5ms injector actuation. However, it does not actuate when combined with relay code.

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

What are you using to power your project?

So the code works if the relay code is not included?

What model Arduino are you using?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

That is 5 minutes + delay(90000) is 1.5 minutes.
So the injector will only turn every 6.5 minutes.
Is that what you wanted?

Yes, The code works fine for individual glow plug and Injector operation. However, does not operate the MOSFET when combined.

No, I want the relay to operate for 90 sec, then turn off...
then 5ms operation of injector.. I dont bother about turn off, i dont require continuous operation.

Then remove the delay(300000);

Try this:

int relayPin = 8;// set pin 8 for relay output
int injectorPin = 2;

void setup() {
pinMode(injectorPin, OUTPUT); // set pin 2 as injector
pinMode(relayPin, OUTPUT); // for relay

//START

digitalWrite(relayPin, HIGH);// Relay ON
delay(90000); // Wait 90
digitalWrite(relayPin, LOW);// Relay OFF

digitalWrite(injectorPin, HIGH); // Injector ON
delay(5); // wait for 5 milliseconds
digitalWrite(injectorPin, LOW); // Injector OFF

// DONE
}

void loop() 
{
}

Thanks it worked. However, the injector actuates once the relay stops. Can we write such a way that injector will actuate while relay is on.
Just after 60 sec of relay, injector MOSFET will on.

Thanks in advance

HI,
So you want.

  1. Start ALL OFF.
  2. Relay ON. (Time zero)
  3. After 60s injector does a 5ms activation.
  4. After 90s Relay OFF.

It can be done with delays, but you will have to look at the IDE example "Blink without delay" to make a truly efficient code.

Tom... :smiley: :+1: :coffee: :australia:

like this:

int relayPin = 8;// set pin 8 for relay output
int injectorPin = 2;

void setup() {
pinMode(injectorPin, OUTPUT); // set pin 2 as injector
pinMode(relayPin, OUTPUT); // for relay

//START

digitalWrite(relayPin, HIGH);// Relay ON
delay(60000); // Wait 60
digitalWrite(injectorPin, HIGH); // Injector ON
delay(5); // wait for 5 milliseconds
digitalWrite(injectorPin, LOW); // Injector OFF
delay(30000); // Wait 30
digitalWrite(relayPin, LOW);// Relay OFF

// DONE
}

void loop() 
{
}

I think your MOSFET module is wired wrong.
Controlled Device x Input voltage .

Check it out in the image.

Also check the datasheet if the MOSFET it uses, (D4184), is a logic level MOSFET.

"D4184 pdf, D4184 Description, D4184 Datasheet, D4184 view ::: ALLDATASHEET :::

image

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.