switch interface to AVR

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi

i want to interface some switches to the AVR...

i came out to something like this (the Resistance value is 4.7 k,and VCC=5V,) for a pushbutton, and a normal close switch, all i need is the led should be on if switch is pushed, i can manage with change in the logic at GPIO,

but the normal closed switch circuit would be dissipating lots of energy... can some one give me better circuits...

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why use external pull-ups? Use the pull-ups inside the AVR with normally open switches that connect to ground.

(BTW do not be tempted to connect to external interrupt pins)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Why use external pull-ups?

I always use external pull-ups when switch (or other binary source) isn't on the same board.
In my devices usually controller is placed near some medium power circuits with relays and triacs and I don't like too many noise on inputs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

in my circuit , ihave controller , relays triacs and inputs on the same board....and

Quote:
(BTW do not be tempted to connect to external interrupt pins)

do you mean that i should never use external pullups
on PD0, and PD1 of atmega8, or is it just when i am using them as interrupt pins(that is interrupts are enabled)

ok then how should i connect the normal close switch.... i need that each led should get on when the switch is pressed!
how would i achieve that?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sherazi wrote:
in my circuit , ihave controller , relays triacs and inputs on the same board....and
Quote:
(BTW do not be tempted to connect to external interrupt pins)

do you mean that i should never use external pullups
on PD0, and PD1 of atmega8, or is it just when i am using them as interrupt pins(that is interrupts are enabled)
I think Cliff is trying to say that ordinary push button switches "bounce" and will generate multiple interrupts.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well i want that these switches should also make led on.... is it possible that internal pull ups be used and LEDs also work...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can add a transistor that turns the led on and off. Otherwise the forward voltage of the LED will prevent you from registering that a button has been pushed.

I've made a (very ugly) drawing with two leds, one is lit when the button is pushed, the other one is opposite.

Here, you could easily scrap the external pull-up.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you really do want to put the LED and the switch in the same circuit like that, put the LED in series with the pullup resistor, and use a normally open switch to ground. The LED and resistor will still keep the input pin of the CPU high when the switch is open, and closing the switch will light the LED as well as send a low to the CPU.
If you have some spare I/O pins, perhaps a better way would be to put the LED and the switch on different pins, and have the software light the LED whenever it detects an input from the switch. Doing it that way has the advantage that when the LED lights it's confirming that the CPU has read the switch properly, instead of just that the switch has closed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
perhaps a better way would be to put the LED and the switch on different pins

Easier, but not necessary if one doesn't have a lot of "spare" I/O pins.

I have one app the has a bunch of LEDs and Normally Open Push Button Switches all on shared pins, (1 LED and 1 switch per pin). At 20 MHz the time to switch the port to input, read the switches, and switch back to output is not visually noticeable. The micro debounces the switches, and does a PMW on the LEDs, so they actually have three states: Off, On, and Dim. When the "Master Power" for this module is on, all of the LEDs glow dimly to make it easier for the operator to see exactly which one of the row of LEDs they are pressing, day or night. (They also use several different colored LEDs, but that is another component of the user interface, again to improve useability and decrease operator error).

Micros are very fast, Human interfaces are very slow. You are only limited by your ingenuity and creativity.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks all of you for responces....

i have no problem with push to make switches.. i am doing with them well,
what i need now is push to break and normally closed switches...

i dont have any spare pins and i wish i dont use transistors ...

can some one guide me for that,
normal close.jpg

Quote:
If you really do want to put the LED and the switch in the same circuit like that, put the LED in series with the pullup resistor, and use a normally open switch to ground.
i am doing the same for the push to make, what about push to break?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're going through quite a lot of pain here. Why not simply replace the switches?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cant replace...i have to interface photo sensors which acts as normaly closed switch... and i have to go with it....how would you going to interface a switch to avr and a led that glows when switch is presed, switch is normal close..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, the circuit below will give you a "low" while the switch is closed and a "high" when the switch is pressed and "breaks".

R11 can be selected to be zero ohms if you are not concerned about the current drawn through R9 and R11.

By choosing R9 and R10 to be equal at say 150 ohms, your red LED will have about 10 mA and the "high" will be about 3.5 volts.

Cheers,

Ross

Attachment(s): 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
R11 can be selected to be zero ohms
How will the led work then? :roll:

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John,

Sherazi changed his specification to be ...

Quote:
led that glows when switch is presed, switch is normal close

The LED if off UNTIL the switch is pushed.

Cheers,

Ross

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Clever!! Who needs a micro for that. :)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks alot rOSs...
i have a question... what is the range of logic 1 and logic 0 for avr...

as in data sheet min HIGH input is 0.7*vcc and max low input is 0.3*vcc.. that gives 3.5 and 1.5 respectively... if i use 150 ohms for r9 and r10, i get 3.45 for closed switch and 2.5 for open switch.... would it be working with avr?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know how you got those values.

If R11 is zero ohms, the LOW will be zero volts (a short circuit to ground). If R11 is 22 ohms, it will be approx 0.6 volts.

Yes the high is as you say. You can increase it by increasing the value of R10. 220 ohms will give you about 3.7 volts.

Cheers,

Ross

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry i had a wrong simulation....
this circuit is really nice ... thanks alot

what should be the value of r11 to get best result

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sherazi wrote:
sorry i had a wrong simulation....
this circuit is really nice ... thanks alot

what should be the value of r11 to get best result

What is your definition of best?

If you have a zero ohms value, the current will be highest through R9, R11 and the closed switch but the LOW signal will be zero.

If R11 is higher, the current through R9, R11 and the closed switch will be less, but the LOW signal will increase (Ohm's law).

So you decide what gives you the "best result".

Cheers,

Ross

Ross McKenzie ValuSoft Melbourne Australia