In this post, I will describe how to build a receiver controlled switch. This can be used to turn on and off various accessories on your aircraft using your transmitter. These are available off the shelf – for example this switch from Banggood or the Turnigy receiver controlled switch from HobbyKing. However, if you are like me and enjoy the DIY aspect of this hobby, you may want to attempt building one of these yourself.

This is what you need:

• AtTiny85 Microcontroller
• Any programmer for the AtTiny – you can use a USBasp, or an Arduino set up as an ISP programmer. (BTW, you really should have an Arduino – they are very cheap and super useful for stuff like flashing ESCs)
• An LM7805 linear voltage regulator, or any other 5V source on your quad you can tap off to power the AtTiny.
• Any NPN power transistor. I used the TIP31C, which can theoretically handle a collector-emitter current of 3A. Note that the actual figure will be lower as the AtTiny85 cannot supply enough current to saturate the transistor at such a high load (explained later).  I guess this design can be modified to use a MOSFET as well but I am not completely sure how that would done. I think it would require a logic level MOSFET and an appropriate resistor on the gate to handle the inrush current from the gate capacitance.
• A current limiting resistor for the base (explained in the next section).
##### Choosing a base resistor

The value of this resistor will depend on the transistor you choose to use. Some excellent resources for calculating the base resistor value can be found here and here. Basically the resistance needs to be high enough to prevent too much current from flowing from the AtTiny into the base of the transistor as this can damage the output pin, transistor or both. However, the resistance must also be low enough to allow enough current to flow to drive the transistor into saturation (a fully ‘on’ state). The required base current can be found by dividing the estimated current you will be switching by the transistor’s DC current gain hFE.

For example, suppose I want to switch a current of 1A. The required base current is thus 1/hfe . hFE or ‘beta’ for the transistor can be found in the datasheet.

For the TIP31C, the datasheet says 25. Let us try calculating the current using this figure. Thus the required current is 1/25 = 40mA. This is well within the TIP31C’s max base current of 1A. However, 40mA is the absolute maximum that the AtTiny can put out so it is probably not a good idea to run it like this.

So let us try a reverse approach. Assuming a draw of 25 mA from the Attiny, we will be able to switch a load of 25 x hFE = 25 x 25 = 625 mA. This is a worst case scenario, but is still sufficient for a metre or so of LED strips. So now the required base resistor can be found by Ohm’s law. R = V/I = 5/0.025 = 200Ω. The nearest standard value is 220Ω and should work just fine. Note that when I tried this circuit, I used a 1K resistor and it still worked. However, I ended up doing a rebuild of my quad and found that this added extra complexity and so I just mounted a regular switch on the bottom.

The schematic below should work but I have not got to test it myself.

And here is the code:

```/* 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

}
}
```