New Products Flash Sale
Thread Tools
Old May 27, 2015, 03:26 AM
SK1701 is offline
Find More Posts by SK1701
Registered User
SK1701's Avatar
India, KA, Bengaluru
Joined Jan 2015
25 Posts
Idea
Attiny85 RC switch

Hello everyone. I have built a prototype of an RC switch for the LED strips on my quadcopter. It uses a 2 position switch on a spare channel of my receiver to turn the lights on and off using an Attiny85-20PU and TIP31C transistor. My schematic diagram is attached along with my code. I am facing a bit of a problem. I am able to switch the lights on but not off. I do recall reading something about how the Attiny can't supply a real ground to the transistor base if they are running of the same power supply. How do I fix this issue? Do I need a current limiting resistor on the base or a base-emitter pulldown resistor? What values would work?
SK1701 is offline Find More Posts by SK1701
Reply With Quote
Sign up now
to remove ads between posts
Old May 27, 2015, 06:32 AM
Ernst38 is offline
Find More Posts by Ernst38
Registered User
Joined Jan 2007
8 Posts
You need a current limiting resistor from pin 2 to the base of the transistor (1-2 kOhm)
Also you could try a resistor from base to ground, to ensure that the transistor turns off
Ernst38 is offline Find More Posts by Ernst38
Reply With Quote
Old May 27, 2015, 07:18 AM
phil_g is offline
Find More Posts by phil_g
Who let the dogs out?
phil_g's Avatar
Pontefract, Yorkshire, UK
Joined Jul 2007
1,218 Posts
Just an observation, your compare values are very close. Since a switched channel usually changes from 1000uS to 2000uS (ie one extreme of servo travel to the other) or with some systems (eg Spektrum) 1100uS to 1900uS, you would normally switch on at say 1700uS and off at say 1300uS. In your sketch, values of 1000 and 1100 are both very close to one end of travel - particularly with Spektrum where one value (1000) is outside the normal range and the other (1100) is right on the brink of the lowest pulse width.

You need some current limiting into the base of the transistor, say 1k. There should be no need for a pull down as the ATtiny active low is well below 0.6v
Without the resistor the ATtiny output is almost shorted to neg and it is possible that the lack of a limiting resistor may have damaged the internal circuitry behind pin 2.

Cheers
Phil
phil_g is offline Find More Posts by phil_g
Last edited by phil_g; May 27, 2015 at 07:32 AM.
Reply With Quote
Old May 27, 2015, 07:49 AM
SK1701 is offline
Find More Posts by SK1701
Registered User
SK1701's Avatar
India, KA, Bengaluru
Joined Jan 2015
25 Posts
Thanks. I will try modifying my code. I will also try adding the current limiting resistor. I thought it was unnecessary as the TIP31C can handle a base current of 1 Amp but now I realise the Attiny may also have needed the resistor. Also I was using the following sketch to test my receiver output:

int ch1;

void setup() {

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

}

void loop() {

ch1 = pulseIn(5, HIGH, 25000);

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

Even with the values of 1000 and 1100, it was successfully able to identify when the switch was on or off. I am using a 9XR with a FrSky DJT module and D8R receiver BTW.
SK1701 is offline Find More Posts by SK1701
Reply With Quote
Old May 27, 2015, 09:01 AM
SK1701 is offline
Find More Posts by SK1701
Registered User
SK1701's Avatar
India, KA, Bengaluru
Joined Jan 2015
25 Posts
Tried adding a 1K current limiting resistor and 10K pulldown. I also tried changing the values in my code. I even replaced the Attiny. No good. The lights will switch on but not off. I need help
SK1701 is offline Find More Posts by SK1701
Reply With Quote
Old May 27, 2015, 09:16 AM
phil_g is offline
Find More Posts by phil_g
Who let the dogs out?
phil_g's Avatar
Pontefract, Yorkshire, UK
Joined Jul 2007
1,218 Posts
You've changed pins - does the sketch tally with the wiring?
phil_g is offline Find More Posts by phil_g
Reply With Quote
Old May 27, 2015, 09:19 AM
SK1701 is offline
Find More Posts by SK1701
Registered User
SK1701's Avatar
India, KA, Bengaluru
Joined Jan 2015
25 Posts
Oh no the previous sketch was just to test my receiver output with an Arduino Uno. The sketch tallies with the wiring. The turning on is flawless, I am just not able to turn the lights off.
SK1701 is offline Find More Posts by SK1701
Reply With Quote
Old May 27, 2015, 09:57 AM
Ernst38 is offline
Find More Posts by Ernst38
Registered User
Joined Jan 2007
8 Posts
You could try connecting a LED with 330 ohm resistor instead of the transistor to check your sketch
Ernst38 is offline Find More Posts by Ernst38
Reply With Quote
Old May 27, 2015, 10:01 AM
phil_g is offline
Find More Posts by phil_g
Who let the dogs out?
phil_g's Avatar
Pontefract, Yorkshire, UK
Joined Jul 2007
1,218 Posts
Do you have a logic probe to check the actual state of PB3? or a 5v LED, or a normal LED with a resistor ? or even a voltmeter - just to check what the pin is doing

Edit: 'Jinx' !!! http://en.wikipedia.org/wiki/Jinx_(children%27s_game)


Otherwise, its not a pin mapping problem is it? depends on how the 85 has been defined to the Arduino environment
phil_g is offline Find More Posts by phil_g
Last edited by phil_g; May 27, 2015 at 10:11 AM.
Reply With Quote
Old May 27, 2015, 10:02 AM
SK1701 is offline
Find More Posts by SK1701
Registered User
SK1701's Avatar
India, KA, Bengaluru
Joined Jan 2015
25 Posts
I did test this sketch with the built in LED on my Uno's pin 13 and it worked fine.
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.
SK1701 is offline Find More Posts by SK1701
Reply With Quote
Old May 27, 2015, 10:06 AM
SK1701 is offline
Find More Posts by SK1701
Registered User
SK1701's Avatar
India, KA, Bengaluru
Joined Jan 2015
25 Posts
Quote:
Originally Posted by phil_g View Post
Just a thought - which 85 core are you using, your drawing & your sketch show physical pin numbers rather than the 'arduino mapped' pin numbers
I'm not sure what you mean by Attiny core? Could you please explain what that is?
My schematic shows the physical pin numbers but I am using the pins numbers as described here. The physical pin 2 is Pin 3 in my sketch and the physical pin 3 is pin 4 in my sketch.
SK1701 is offline Find More Posts by SK1701
Reply With Quote
Old May 27, 2015, 10:07 AM
SK1701 is offline
Find More Posts by SK1701
Registered User
SK1701's Avatar
India, KA, Bengaluru
Joined Jan 2015
25 Posts
Oh OK, I got what the core is. I am using the one mentioned in the HighLowTech tutorial I posted the link to above.
EDIT: I also thought I ought to mention. If I upload a basic blink sketch using the Attiny pin 3 (physical pin 2) it works just fine. It can blink the lights on my quad on and off.
SK1701 is offline Find More Posts by SK1701
Last edited by SK1701; May 27, 2015 at 10:11 AM. Reason: Need to add more info
Reply With Quote
Old May 27, 2015, 10:11 AM
Ernst38 is offline
Find More Posts by Ernst38
Registered User
Joined Jan 2007
8 Posts
The tiny core means the collection of files that is need to program the tiny's.
I use this, which among other things have a working serial, so you can get serial output to debug your code.

https://code.google.com/p/arduino-tiny/

edit:

I just tried your code on a ATtiny85, it works as expected.

Code:
int ch1; 
byte led=4;
byte ch_pin=3;

void setup() {
  pinMode(ch_pin,INPUT);
  pinMode(led,OUTPUT);
}

void loop() {
  ch1 = pulseIn(ch_pin, HIGH, 25000); 
  if (ch1 > 1600) {
    digitalWrite(led,HIGH);
  }
  else {
    digitalWrite(led,LOW);
  }

}
Ernst38 is offline Find More Posts by Ernst38
Last edited by Ernst38; May 27, 2015 at 10:52 AM.
Reply With Quote
Old May 27, 2015, 01:23 PM
prefabu is offline
Find More Posts by prefabu
Registered User
Kansas City
Joined Dec 2009
462 Posts
Have you tried using a different transistor like a 2N2222? The one you're using potentially has a rather low current gain, and it's possible that your base current requirements are too great if you're driving a lot of lights. Just a random thought.
prefabu is offline Find More Posts by prefabu
Reply With Quote
Old May 27, 2015, 02:09 PM
srnet is online now
Find More Posts by srnet
Stuart
srnet's Avatar
UK, Cardiff
Joined Dec 2008
3,502 Posts
Quote:
Originally Posted by prefabu View Post
Have you tried using a different transistor like a 2N2222? The one you're using potentially has a rather low current gain, and it's possible that your base current requirements are too great if you're driving a lot of lights. Just a random thought.
Multimeters for measuring voltage are rather useful for testing for this ...........
srnet is online now Find More Posts by srnet
Reply With Quote


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Yippee! NEW 3in1! 3way Video switch, RC Shutter, High current switch for FPV & AP kristaps_r FPV Equipment 481 May 18, 2015 01:24 PM
Yippee! NEW 3 IN 1 RC Shutter, 3 Video switch, High current switch for AP & FPV kristaps_r Aerial Photography 2 Dec 04, 2012 02:40 PM
Build Log Universal 3-way cheap RC switch (video switch). mifau FPV Talk 19 Sep 04, 2012 06:23 PM
Discussion Creating a Better and more reliable Power Switch for our RC receiver switch. lazy-b DIY Electronics 15 Aug 12, 2008 02:06 AM