I suspect the world would be better if that percentage were even greater.
Making a simple RC switch…
Over the last couple of years, I’ve spent a little bit of time making fixed wing aircraft from Dollar Tree foam. The results have been interesting and fun, but I’ve found that the need to find relatively large areas to fly means that it’s harder to go fly than I would like. On the other hand, multicopters require relatively less area, and I suspect I could do some test flights almost anywhere. So, over the last few months I’ve begun to accumulate the necessary parts to put one together. As this project continues, I’ll write up some more.
But one of the things I thought about today in between World Cup matches was putting some LED lights on the quadcopter. Besides just looking cool, they are especially useful on quadcopters because they allow you to see the orientation of the quadcopter more easily.
My RC mentor Mark Harrison has some notes about he wired up LEDs on his quadcopter. The basic idea is to get some LED strips, and then power them from a brushed ESC (like this one for $4.95) driven by a spare channel on the RC receiver. It’s a pretty good way to go.
But I wondered if I could do better. I’ve made a Christmas hat with LEDs before, driven by an Atmel ATTiny13, surely I could homebrew something…
So here’s where my thought is: I want to create a small pc board with just a few components. It will be powered from the receiver, and will read the servo control channel, and will use an Atmel ATTiny85 (I have a dozen on hand that I got from Tayda Electronics for about about $1.12 each, and they have 8K of memory, plenty for this application). At it’s simplest, we want the program to configure one pin as an input, and one pin as an output. The servo control signal looks like this:
The pulse will be somewhere between 1ms and 2ms long. The ATTiny just needs to monitor the channel, and if the pulse is longer than 1.5ms, it will set the output high, otherwise set the output low. And that is pretty easy.
In the past, I’ve used avr-gcc to program these tiny chips. For the ATTiny13 with just 1k of flash, that’s pretty understandable. But it turns out that with a bit of work, you can use the Arduino environment to program the ATTiny85s. This website gives most of the details. It’s pretty easy, and I got my MacBook all configured in just a few minutes. Then, I entered and compiled this (as yet untested) code:
[sourcecode lang=”cpp”]
/*
* I thought I would dummy up a simple RC controlled switch using
* an Atmel ATTINY85 processor, but code it all in the Arduino
* environment. The idea is to use pulseIn() to read the data signal
* from the RC receiver, and threshold it, setting an output pin
* if the pulse length is > 1500 ms, and clearing it if less.
* Very simple. It should be able to be powered directly from the
* receiver, and if we had some kind of FET we can switch large loads
* (like a strip of LEDS).
*/
int inputPin = 0 ;
int outputPin = 1 ;
void
setup()
{
pinMode(inputPin, INPUT) ;
pinMode(outputPin, OUTPUT) ;
// if we never get a pulse, we want to make sure the
// ourput stays switched off.
digitalWrite(outputPin, LOW) ;
}
void
loop()
{
digitalWrite(outputPin,
pulseIn(inputPin, HIGH) > 1500 ? HIGH : LOW) ;
}
[/sourcecode]
Couldn’t be much easier. If you hooked up an led with a current limiting resistor to pin 1, you can test this (I’ll put up some video once I get it going). To power a larger 12v string (like this red LED string I got for $8.90 for 5m from Amazon) you’ll use that output to power a FET to switch the much larger current, but that’s dead simple too. I can probably run the ATTiny off its internal oscillator at just 1Mhz.
But as cheap as that is, it’s probably not worth the cost of home brewing one.
But of course, you don’t need to stop with this stupid application. You have a total of five or six pins, so you can easily control multiple strings. You can also implement more sophisticated controls: instead of just using an on/off signal, you can look for short switch flips versus long switch flips, and change into different blinking modes. A short flip might make the landing lights blink. A long one turns them on steady. You could even use the ATTiny to drive RGB addressable LEDS (check out this Instructable for details). Different flips might turn on different colors, or switch between Larson scanner modes… blinking… the skies the limit.
I’ll let you know when I get more of this done.
Comment from rcwingman
Time 4/3/2015 at 10:14 am
cool stuff.
thanks for the tut man.
This is what i came up with.
what do you think?
int led = 9;
int inputPin = 11 ;
int outputPin1 = 13 ;
int ledstatus;
int licht;
void setup(){
pinMode(led, OUTPUT);
Serial.begin(9600);
delay(10);
pinMode(inputPin, INPUT) ;
pinMode(outputPin1, OUTPUT) ;
digitalWrite(outputPin1, LOW) ;
}
void loop()
{
ersteschalterstellung();
zweiteschalterstellung();
}
void ersteschalterstellung(){
int schalterstellung1 = 1000;
int wert;
wert = digitalRead(outputPin1);
digitalWrite(outputPin1,
pulseIn(inputPin, HIGH) > schalterstellung1 ? HIGH : LOW) ;
Serial.println(wert);
while (wert == 1){
blinklicht();
wert–;
}
}
void zweiteschalterstellung(){
int schalterstellung2 = 1500;
int wert;
wert = digitalRead(outputPin1);
digitalWrite(outputPin1,
pulseIn(inputPin, HIGH) > schalterstellung2 ? HIGH : LOW) ;
Serial.println(wert);
while (wert == 1){
blinklicht();
wert–;
}
}
void blinklicht(){
int pulsedauer = 3;
int pause = 50;
delay(10);
while(ledstatus = 0){
//Serial.println(ledstatus);
ledstatus–;
delay(pulsedauer);
analogWrite(led, ledstatus);
}
analogWrite(led, 255);
delay(pause);
analogWrite(led, 0);
delay(pause);
analogWrite(led, 255);
delay(pause);
analogWrite(led, 0);
}