Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pulse turns on an LED circuit and another turns it off

Status
Not open for further replies.

ash1412

Member level 3
Joined
Nov 30, 2009
Messages
65
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,693
Hi All,

I am looking for simple circuit based on transistor for a push switch(momentary) that when I push it once it closes a switch and keeps it closed until I pulse it again. One pulse turns on an LED circuit and another turns it off.

Thanks in Advance
 

Look: **broken link removed**

I don't want to hotlink their PDF for various reasons; In the first paragraph on the page I have linked the words "Figure 1" which was a working link to a PDF which contained a circuit which seemed reasonable (regarding your task) to a fellow who has been drinking (me).
 

To be honest, this problem is best solved with digital electronics, because their circuit uses 4 transistors and a lot of discretes. I once did it using
an ATTINY13V (I think) which was good because it is only 8-pin SOIC, and then (depending on if you have a high power load) a MOSFET+RELAY or
a couple of MOSFETS (and resistors of course). For driving just an LED you wouldn't need relay/FETs.
The processor runs a simple switch debounce program. It could also perform auto-power-off, etc.
The code is here, it is quite inefficient, I didn't even use processor sleep, but I was in a hurry to get something out the door.
(I think it was compiled with IAR compiler).


/********************************


ATTINY13 or ATTINY13v
VDD is pin 8, GND is pin 4
Lamp output is pin 5 (high=lamp on, low=lamp off)
Suitable driver is PIP3105-P (Input pin connects to
pin 5, Source connects to GND, and Drain connects to lamp).
Switch is connected between pin 6 and GND.
When shorted to ground, the lamp is turned on (i.e. lamp
pin goes high).
Pin 7 (general purpose output) also does the same thing,
(maybe invert the output in a later code version).


Programming:
C:\c_root\Electronics\switchproject\code\Release\Exe>c:\WinAVR\bin\avrdude.exe
-c avrisp2 -p t13 -P com6 -U flash:w:switchproject_project.hex

*********************************/


#include <iotiny13.h>
#include <intrinsics.h>
#include <avr_macros.h>
#include <stdio.h>


// Port B
#define LAMP 0x01
#define BUTTON 0x02
#define GENOUT 0x04

// inputs
#define SWITCH_ON (PINB & BUTTON) == 0
#define SWITCH_OFF (PINB & BUTTON) != 0

// outputs
#define LAMP_ON PORTB |= LAMP
#define LAMP_OFF PORTB &= ~LAMP

#define GENOUT_ON PORTB |= GENOUT
#define GENOUT_OFF PORTB &= ~GENOUT

// global vars
char changed;

// delay in hundreths of a sec
void
delay_cs(int v)
{
int i;
for (i=0; i<v; v++)
{
__delay_cycles(187);
}
}



int
main( void )
{

int state;

// initialise
PORTB=0;
DDRB=0x05; // LAMP pin is output as well as GENOUT, the rest of port B is inputs
PORTB=0x3a; // enable pull-ups on all input pins
LAMP_OFF;
GENOUT_OFF;
// end of initialisation
changed=0;
state=0; // assume switch is off


while(1)
{
// Check if we need to turn the lamp on
if ((SWITCH_ON) && state==0) // is the light just switched on now?
{
__delay_cycles(1000); // wait a bit for contact bounce allowance
if (SWITCH_ON) // no contact bounce
{
LAMP_ON;
GENOUT_ON;
state=1;
}
}

// Check if we need to turn the lamp off
if ((SWITCH_OFF) && state==1) // is the light just switched off now?
{
__delay_cycles(1000); // wait a bit for contact bounce allowance
if (SWITCH_OFF) // no contact bounce
{
LAMP_OFF;
GENOUT_OFF;
state=0;
}
}


} // end while







return 0;
}
 

This is not an analog, but a digital circuit question. What you want is the electronic equivalent of a toggle switch, known as flip-flop.

You'd need one that provides an inverted Q (data) output, which you connect directly back to the D input. Then you use the switch (+maybe a few filter components to prevent multiple pulses per switch action) to produce a clock pulse. Each time you push the switch the flip-flop's output toggles between logic high & logic low. For the filtering on that switch input: Google for "debounce circuit" or "debounce switch".

Depending on supply voltage, you could use for example a CMOS 4013, a 74HC74 or 74HC75. Use SMD components if you want it small. If a few mA's is enough, you could drive a LED directly with one of the outputs. Also there exist logic IC's with a single gate, maybe also types with a single flip-flop?

Using discrete transistors for this is doing it the hard way when a simple/cheap/easy solution exists. Using a microcontroller for the above is overkill - even if that controller is cheap (and more work since you need to program the controller before use).
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top