# Simple Transistor Switch

24,285

34

2

Published

## Introduction: Simple Transistor Switch

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.

## Step 1: Cutting

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.

## Step 2: Measuring

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.

## Step 3: Soldering

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.

## Step 4: A Little Bit More...

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/

## Recommendations

• ### 3D CAM and CNC Class

606 Enrolled

• ### Clocks Contest

We have a be nice policy.
Please be positive and constructive.

## 2 Comments

In some flexible cords (i.e. lamp cords) one side has ridges while the other is smooth. In AC circuits, the ridges correspond to neutral and the smooth to phase. I would think that a company making a standardized item like this would want to reduce rework as much as possible and there might be a marking of some kind identifying the wires after tying.

I believe your picture is wrong. the transistor base goes to the arduino pin and the emitter to your VCC and the collector would be VCC as well and not ground.