Simple Transistor Switch

by contrechoc in Circuits > Wearables

27107 Views, 38 Favorites, 0 Comments

Simple Transistor Switch

tr1.jpg
This is a simple but very basic challenge. Related to the water switch instructable:

https://www.instructables.com/id/Water-switch/

Components
Buy a cheap (less than 2 euro's) LED Christmas thing, just having 20 LED's, connected to a nice battery casing.
(The advantage is that you don't have to solder the LED's.)

We will use a transistor BC547 (15 cents) and a resistor, 5K 10 cents.

The LED's will be on using the switch on the casing.

Challenge:
Make this go on and off using a transistor and the Arduino.

Cutting

tr0.jpg
tr2.jpg
tr3.jpg
tr5.jpg
tr4.jpg
Step 1.
Cut one of the two wires going to the LED's.
Because of the knot we cannot be sure which wire we have cut.

Measuring

tr6.jpg
tr7.jpg
Step 2:
Measure using a simple Multimeter if the wire is coming from the GND or the 5V.
This decided the direction for the transistor.

Looking at the image you can see which side of the transistor to connect to the wire.

Soldering

tr8.jpg
tr9.jpg
Step 3:
Solder the resistor to the base, the middle leg of the transistor and connect this to PIN 13 of the Arduino

Then with the standard Arduino BLINK script you can test the working.

A Little Bit More...

ir-1.jpg
Step 4:

Make this working in AVR Gcc. Why? Well, then you can take the atmega328 as a stand alone chip, and you can reuse your Arduino for other projects. The atmega328 is about 7 euro's and the Arduino is 30 euro's. And also, the stand alone chip is much smaller!

We have to do the PIN's differently in C: (different from the Arduino script.)

First set the output:
#define PB5 5
DDRB |=(1<<PB5);//output pin for relay or transistor
PORTB &= ~_BV(PB5);

Then setting, or un-setting it:
//say hello to the world
PORTB |=(1<<PB5);
delay_ms(333);
PORTB &= ~_BV(PB5);
delay_ms(333);
PORTB |=(1<<PB5);
delay_ms(333);
PORTB &= ~_BV(PB5);

Even if you are fiddling on the Arduino, you can use this AVR C code, because the Arduino is script is based on c.

I used this method for a standalone atmega328 chip in my infra red vest, see this instructable:
https://www.instructables.com/id/Infra-Red-Vest-Code/