Simple Transistor Switch
by contrechoc in Circuits > Wearables
27213 Views, 38 Favorites, 0 Comments
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.
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
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.
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
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.
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
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.
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...
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/
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/