Using the Nano PWM output to controle RC Rotating light

Hi,

I'm trying to control my RC rotating light from my Nano.

The light are supplied with gnd and 5v+ and the PWM signal is connected to D5.
The light is the following:

There are 4 modes on the light, (3 flashing and off).
If I connect the light to my RC reciever, I can switch through the modes using an high/low switch. So setting the PWM signal from low to high, changes the mode.

I'm trying with the followin code:

int pwm1 = 5;
bool _flashOn = false;

void setup()
{
  // put your setup code here, to run once:
  pinMode(pwm1, OUTPUT);
  digitalWrite(pwm1, LOW);
  Serial.begin(9600);
}

void loop()
{
  val = digitalRead(input1);
  if (!_flashOn)
  {
    flashOn();
  }
}

void flashOn()
{
  int pos = 1;
  Serial.println("Flash on");

  for (pos = 0; pos <= flashOnPulse; pos += 1)
  { 
    digitalWrite(pwm1, HIGH);
    delay(500);
    digitalWrite(pwm1, LOW);
    delay(500);
    Serial.println("PWM on");
  }

  _flashOn = true;
}

But nothing happens...
I should go from low to high, two times.

I'm wondering if it could be the hz of the output that's the problem?
As per my goggling the standard RC equipment is running af 50hz PWM..

From your description and picture it sounds like the light is controlled by an RC servo channel. Try controlling it using the Servo library rather than the standard PWM output

why not use analogWrite() and use one of the PWM pins?

That did the trick..

Using this, to trigger the mode selector:

myservo.writeMicroseconds(2000);
delay(20);
myservo.writeMicroseconds(1000);

I am glad that you got it working using the Servo library. The clues were all there in your original post

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