I want to use pwm to control relay

Here is the deal: i have a source of pwm ranging from 1200-1800 and i want to use an arduino nano to convert that into a signal. But i am a noob at coding :frowning: i want to control a relay with the pwm signal so its off at <1200 and on at >1800. Can someone pleaseeee give me code?
Relay i have- 5V 1 Channel Relay Board Module Optocoupler LED For Arduino PIC ARM AVR`H2 | eBay

1200 to 1800 what?
Normally, PWM would be quantified as a percentage duty cycle.

Have you looked at pulseIn?

What is "1200 - 1800"? I've only spent 50 years with electronics and I don't get it.
Give You code? You make the code and we assist if it needs adjusting.

Maybe he means hertz?

But that wouldn't simply be PWM, would it?

PWM is specified by frequency and duty cycle. If you are just interested in frequency you can measure that also.

assuming that some of the words are confusing.
and assuming that you do mean frequency, it is not hard.

basically PWM is typically a set frequency and what is changed is the duty cycle.
for instance if you have a pulse rate of 100 and the the pulse is 50% duty cycle.

to help us understand,please post a link to where you are getting the signal. please be specific as to the make and model, etc.

No clue.

i dont know how to put this but its like a square stretching in the x axis.... what is that called? And guys please bare with me i am not good with this stuff if you want to respond, respond nicely or ignore (not you, toddl1962)

Please be kind or just ignore...

Is the period (the time between two matching edges) fixed?
If so, what is the period?
If not, how does it vary?

There’s a few concepts mixed up here…
as pointed out, if the need is to measure input frequency, that’s a project of its own.

Controlling a relay with PWM is unusual, but quite realistic… often done to reduce static power consumption. The strategy is overcome friction of the “pull in” by using 100% duty cycle, then to fall back after some milliseconds (to perhaps 30% PWM) to ‘hold’ the relay armature in.

I doubt this what you were planning, but it’s the best I can suggest.

Another possibility is an analog input (1200-1800) range, that might be used to trigger the relay, but you need to tell us a lot more.

Sorry but You are not using usual therminology normaly used. Therefore we have a hard time to understand You.
Please do some encyclopedia search about PWM, frequency and so on. Then explain to us.

Frequency is how many pulses per second.

PWM is like 100 pulses a second but some of each pulse is high some of each pulse is low.

It might help if you tell us wbat generates the pulses.

It is a guesss but it seems it is hard to put into words.

Tell us what the thing is used for.
Or post a link to it.
Or where you bought it.

Sounds like maybe the control signal for a hobby servo, typically positive pulses of 1000 to 2000 microseconds and about 20 milliseconds apart.

If I am right about the signal, easily enough done.

void loop()
{
   unsigned long duration = pulseIn(InputPin, HIGH, 30000);
  if (duration != 0 && duration <1200)
    digitalWrite(RelayPin, HIGH); // Turn relay off

  if (duration != 0 && duration > 1800)
    digitalWrite(RelayPin, LOW); // Turn relay on
}
1 Like

Maybe the time stamp 9:13 of this video will help? Reading PWM Receiver Signal Using Arduino - YouTube

Yes yes yes!! Exeactly!

But what pin does the signal input, and output....?

I think it's decide by you because you make it...

The input and output pins?