Digital push-button

Guest #3681673
Rate this post
• ▲ useful
▼ not useful
Dear μController community,

I am a complete beginner in the field so my question might seem a bit 
naive.
In short I need to implement a circuit switch that will change state 
(ON/OFF) every time a short pulse is sent (trigger). In effect it is a 
digital push-button. For instance on a first trigger the circuit open, 
on the 2nd will close..etc..

Do you have any simple solution to this? Is it something easy to 
implement with a μcontroller? I am currently looking for the simplest, 
least time consuming solution so if there is another way other than 
programming ICs please let me know.

Sincerely,
Konstantinos
Guest #3681684
Rate this post
• ▲ useful
▼ not useful
If the circuit does always have power,
than a simple flip flop does
1
  +-----------+  CD4011
2
  |           |                 
3
  |       +---)----------------+
4
  |       |   |                |
5
  |       +--|>o--10k--+--|>o--+-- on/off
6
  | +         |        |       |  
7
Battery       |        |       1M
8
  | -         |        |   _   | 
9
  |           |        +--o o--+ 
10
  |           |                | 
11
  |           |              100nF
12
  |           |                |
13
  +-----------+----------------+

If you loose power, there are specialized
single bit non volatile state saver memory chips like
FM1105B, FM1106, FM1107, FM1110, FM1114 (RamTrom FERAM)

Of course you can program it also into a small micro controller
that has an EEPROM to save state during power loss.
For the Arduino programming environment
1
char key=0, lastkey=0, savedkey;
2
const char inputpin = 1;
3
const char outputpin = 2;
4

5
void setup()
6
{
7
    pinMode(inputpin,INPUT); 
8
}
9

10
void loop()
11
{
12
  while(1)
13
  {
14
    key=digitalRead(inputpin);
15
    if(key==1&&lastkey==0)
16
    {
17
      savedkey=EEPROM.read(11);
18
      savedkey=1savedkey;
19
      EEPROM.write(11, savedkey);
20
      digitalWrite(outputpin,savedkey)
21
    }
22
    lastkey=key;
23
    delay(10);
24
  }
25
}
So this is rather simple.

Reply

A question of your own? This thread is over 12 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.