DIY RC switch for my quad lights

Started by SK1701, January 07, 2015, 05:43:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

parichya.gautam

Passion > Financial Constraints

To Contact:
FB: https://www.facebook.com/parichya
Mob: 8375066843
Mail:
-------------------------------------------------------
My Products On Sale Catalogue: ( !!! LOWEST PRICE GUARANTEE ON ALL ITEMS !!! ) https://app.box.com/s/84m5t5ljrwat54rmrldjg74dtie28g44
-------------------------------------
Product Request Form: https://docs.google.com/forms/d/1-OccRCaAQux8hxpuTw_xI4k3Ll9QW9JyOr0XDijzPXA/viewform?us

sooraj.palakkad

solder two wires between strip and your power distribution board - check the polarity, and get rid of all connectors .
RC Hobbyist and an Aerial Cinematographer..

parichya.gautam

i dont have a power distribution board :P
Passion > Financial Constraints

To Contact:
FB: https://www.facebook.com/parichya
Mob: 8375066843
Mail:
-------------------------------------------------------
My Products On Sale Catalogue: ( !!! LOWEST PRICE GUARANTEE ON ALL ITEMS !!! ) https://app.box.com/s/84m5t5ljrwat54rmrldjg74dtie28g44
-------------------------------------
Product Request Form: https://docs.google.com/forms/d/1-OccRCaAQux8hxpuTw_xI4k3Ll9QW9JyOr0XDijzPXA/viewform?us

sooraj.palakkad

RC Hobbyist and an Aerial Cinematographer..

parichya.gautam

Passion > Financial Constraints

To Contact:
FB: https://www.facebook.com/parichya
Mob: 8375066843
Mail:
-------------------------------------------------------
My Products On Sale Catalogue: ( !!! LOWEST PRICE GUARANTEE ON ALL ITEMS !!! ) https://app.box.com/s/84m5t5ljrwat54rmrldjg74dtie28g44
-------------------------------------
Product Request Form: https://docs.google.com/forms/d/1-OccRCaAQux8hxpuTw_xI4k3Ll9QW9JyOr0XDijzPXA/viewform?us

AnjanBabu

I made a very similar RC switch for switching the FPV on/off on my mini quad using a N-channel MOSFET (STP60NF06) and a SoIC ATtiny45 programmed on Arduino.
I'll post a picture of it tomorrow.

The code is very simple actually, only about 10 lines and 996 Bytes compiled, it'll work on any ATtiny you can get your hands on.

1. Read PWM from Rx using pulseIn()
2. Create a condition to check switch position from the PWM
3. Signal the MOSFET accordingly

You can get my code from here-- https://www.dropbox.com/s/eufdd6pk42nnple/RC_Switch_ATtiny45_.zip?dl=0

:thumbsup:
Mechatronics engineer . Hopeless realist

anjanbabu.wordpress.com

SK1701

I am resurrecting this old thread because I have finally got around to building the actual switch. Here is my schematic:


And this is my code:
Quote
/* This is the code for an RC light switch for my quadcopter */
unsigned long ch1;

void setup() {
  pinMode(4, INPUT); // Set our input pins as such
  pinMode(3, OUTPUT);
}

void loop() {
 
  ch1 = pulseIn(4, HIGH, 25000); // Read the pulse width of the channel

  if (ch1 > 1100) {         //assigned to a 2 position switch
    digitalWrite (3, HIGH); // turn on the lights
  }
  if (ch1 < 1000) {
    digitalWrite (3, LOW);  // turn off the lights

  }
}

For some weird reason I am only able to turn the lights on but not off. Does anybody know why? Do I need to connect a resistor between the Attiny pin and the transistor base? Or should it go between the base and emitter to sink any current leakage to ground? I need some help please.

AnjanBabu

The transistor might need a pull-down, try adding the resistor.

Additionally, you could replace the transistor with a MOSFET. I use a STP6NF06 with an ATtiny45, it can handle up to ~10A cont. at 12v without a heating much.
Mechatronics engineer . Hopeless realist

anjanbabu.wordpress.com

SK1701

Thank you sir. By pull down you mean the base emitter-resistor right? What do you think would be a decent value to start with? I can also try a MOSFET. I didn't have any at home so I used a power BJT (TIP31C) which is more than sufficient for my needs.

Himadri Roy

For pull down commonly used resistor is 10K
And the pulldown resistor is on the Base of the Transistor.  :thumbsup:
For once you have tasted flight you will walk the earth with eyes skywards for there you have been and there you will long to return
- Leonardo Da Vinci

https://www.youtube.com/himadrifpv

SK1701

Thank you. I will try the 10K. The pulldown resistor goes from the base to the emitter right? The resistor connected to the base is usually to limit the current from the microcontroller (not an issue for me, the TIP31C can take 1A on the base)

Himadri Roy

Nope the resistor from the the base goes to ground

EDIT- yes you can connect the emitter and base with a 10K resistor that will also do!  :thumbsup:
For once you have tasted flight you will walk the earth with eyes skywards for there you have been and there you will long to return
- Leonardo Da Vinci

https://www.youtube.com/himadrifpv

SK1701

That is the same thing since my emitter is connected to the main ground. This transistor is NPN so I am using it as a low-side switch.

SK1701

UPDATE: Adding a 10K pulldown resistor from the base to ground did not make a difference

SK1701

I have added a 1K current limiting resistor on the base. No difference even if I use a different Attiny.
I have also conducted some further troubleshooting with my multimeter. When I first power up my circuit, the potential difference between the Attiny pin 3 and ground is 0. When I switch on the lights from my Tx, this goes to 4.95V. But when I switch the lights back off again, the voltage still stays at this level. This means that the Attiny pin is not going low. What could the cause be? This is an AtTiny85-20PU from BangGood flashed with 8MHz bootloader.

Himadri Roy

SK did you try out some simple trouble shooting like are those values in the if condition are correct?(do those values show up on the Serial when the switches are flicked in your desired position?)
For once you have tasted flight you will walk the earth with eyes skywards for there you have been and there you will long to return
- Leonardo Da Vinci

https://www.youtube.com/himadrifpv

SK1701

I have not yet figured out how to use Serial with my Attiny yet since the standard Serial commands give an error message. I did use this similar code snippet on my Arduino Uno:
Quoteint ch1;

void setup() {

  pinMode(5, INPUT);
  Serial.begin(9600);

}

void loop() {

  ch1 = pulseIn(5, HIGH, 25000);

  if (ch1 > 1700) {
    Serial.println("Left Switch: Engaged");
  }
  if (ch1 < 1300) {
    Serial.println("Left Switch: Disengaged");
    delay(1000);
  }
}

This snippet worked and the Serial Monitor said Engaged when the switch was on and Disengaged when it was off. I was also able to use my original RC lights code to turn on and off the pin 13 LED of my Uno.

SK1701

At last I got it working thanks to some help at RCGroups here. It was a software bug and all I needed to do was change my second if statement (if (ch1 < 1300)) to an else statement. This is because this condition was not being triggered. Here is my working code:

Quote
/* This is the code for an RC light switch for my quadcopter */
unsigned long ch1;

void setup() {
  pinMode(4, INPUT); // Set our input pins as such
  pinMode(3, OUTPUT);
}

void loop() {
 
  ch1 = pulseIn(4, HIGH, 25000); // Read the pulse width of the channel

  if (ch1 > 1700) {         //assigned to a 2 position switch
    digitalWrite (3, HIGH); // turn on the lights
  }
  else {
    digitalWrite (3, LOW);  // turn off the lights

  }
}

I will post a working video soon.

akhilzid

Good Project, here is the much better optimized code  :hatsoff:
Quote
#define InputPIN 4
#define OutputPIN 3

void setup() {
 pinMode(InputPIN, INPUT);
 pinMode(OutputPIN, OUTPUT);
}

void loop() {
 digitalWrite (OutputPIN,(pulseIn(InputPIN, HIGH, 2200) > 1500)? HIGH : LOW);
}

SK1701

Optimised indeed! Thanks a lot Sir. This code looks much neater (though it is only 16 bytes less). My code was uglier because it was a mashup of other sources and not really self-written. Now I know who to contact for any Arduino related help  :hatsoff:

akhilzid


SK1701

Here is a short clip of the switch in action. Yes, I know it is a bad video, it is just to show the switch working: