Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Netherlands
Asked — Edited

Adc Switch

Hello everyone.

I have a question. I had salvaged this neat little micro switch that came out of a
webcam. I have placed that inside the casing underneath the casing's button, so
that I can press this button and have it run somekind of script.

The problem is that now that the switch is in and hooked up to an ADC port, I find
out that this switch is normally closed and breaks the circuit when pressed in. I have the groundwire of the switch hooked up on ground, and the (+) wire is hooked
to the signal. So when pressed, it breaks the circuit and the value of the adc port will read 0. if i want it to trigger a script when pressed in, it would have to trigger
that script when the value of the ADC port reads 0.

But as the ADC port is reading itself, it sends out signals ranging from 0 - full and anywhere in between. Which means that it will frequently bump into the 0 value regardless of wether i press this switch or not. And so the script will keep on triggering over and over by itself..

The only solution i can think of is to put in somekind of delay. That it will trigger only
when it reads the value 0 for longer then a second. But I have a hard time putting this in code, maybe I'm missing something or maybe I lack the insight to come up
with logical routines to make this happen. If someone has an idea, I would very much
appreciate it. :)

Thanks!

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
PRO
Synthiam
#1  
I think what you experiencing is static feedback. The switch is most likely normally open, but you are seeing voltages because of static. Switches should be grounded with a resistor, which is called a pull-Down resistor. Or switches should be pulled up with a pull up resistor.

Essentially they are the same thing but only matters in the direction of the switches polarity. For example, if your switch is connected to +5 and signal, you'll expect +5 when the switch is pushes. That means you'll want a pull down resistor between signal and gnd.

What that resistor does is complete the circuit with resistance. That prevents static electricity from affecting the signal. If the circuit is open (floating) then the circuit will only close with some form of connectivity, which exists in the air.

A way to see this for yourself is to disconnect everything from your adc ports. Now add an adc graph and run your fingers near the ports. Touch them too. And you will see higher than expected voltages.

It's a little surprising to see +5 Dc current from your fingers! And that's actually an interesting conversation on its own. Because voltage is an important measurement but not complete without amperage. And you can generate hundred of volts from static electricity on your body at an almost unmeasurable amperage. That's how electrical circuits can be damaged by static.

We underestimate the relationship between the two measurements of electricity. Much like how many auto enthusiasts underestimate the relationship of torque and horsepower. The advantage to auto enthusiasts is gear boxes can be used to substitute one for the other. We don't have that ability to do the same with electricity very easily.

Okay so that went off topic a bit, but I think you'll get what I mean when you try my example.

So there is a chance your switch is normally closed, but it's rare. Either way you will need a resistor somewhere:)
Netherlands
#2  
Hey, that's interesting! That opens up possibilties. As you can see I'm totally new in the world of
electronics. I started reading up on pull up and pull down resistors when I read this and I realise that
they are probably very common. Maybe I should be embarrased for not knowing this for myself already haha. But anyway, I do know now. Thanks for your answer, I think I understand now.

Allhough..I dont mean to ask your time to go over basic electronics 101 and forgive me if I am but
as I understand it, a resistor introduces resistance to the current which is proportional to the voltage applied to the resistor..A circuit without resistance would short out that circuit due to
heat building up and destroying the circuit, right? I have the tendancy to think that a circuit without
resistance would balance out the current in the circuit and thus would ultimatly not allow a current to flow at all..maybe I'm confusing myself?

Anyway, because the voltage and current is not regulated by some sort of resistance, it clearly
introduces static. So to prevent that i should use a pull up or pull down resistor. I find that theres
various ways of using those setups. If I connect the switch between the +5 and signal connection of the adc port only, leaving out the ground, and placing a resistor on the +5 lead before the switch,
would I then be in business? or would it be better to connect the outgoing lead after the switch to
the ground connection of the adc port aswel? is a ground connection required?

Thanks for your answer, without it I would've probably chucked the switch and soldered a different
one together only to run into the same problem.:P
Netherlands
#3  
Holy heck, never mind that last question. I think I got it now, the switch goes on the +5. i should place a resistor either before the switch or after it, leading to both ground and signal, correct?

Does the same apply to leds being hooked up directly to a digital port? Because I have noticed excessive flickering of the leds when animating a light pulse or something. Would placing a resistor
in there reduce that flickering too?
#4  
Hey, OKIDAY!

don't most of those micro switchs have three pins and one pair from the middle is Normally Open and the other pair Normally closed? You might just have to move the wire to the other pin.

Mel
Netherlands
#5  
Hi MovieMaker!

Actually this switch had only 2 pins for as far as i can see. and 2 wires, 1 black and 1 brown coming
out that were originally soldered to the board of the webcam. Maybe those other pins had been
removed by the factory when it was placed on the webcam. I have used the pull down resistor idea
as DJ suggested and it works like a dream. Thanks for your help though!:P
#6  
MEL that wont make a difference ,like DJ said is right ,the pin will be floating unless you have a pull up or pull down ,norm open or closed you need one ,like about 10k

okiday
digital output to led is mostly protected dont use one there ,the flickering you see might be noise comming in from motors or sonars ,or not setting the output right,try another digital pin if still happens then there is noise getting in to the board from a sensor or motors
just test is only hook up the led circuit only,another could be is to much current draw on the digital output pin,most you can have is 40 ma,if you look at the microcontroller data sheet.
second on using a switch on adc output wont work you will ruin the the pin,switches are made mostly for digital input pins ONLY
analog input pin with a switch (not really a good idea) you can use a 10k pull up to 5 volts on output connection and other side of switch to gnd then you get 5 volts switch open and switch closed 0 volts,one reason why a switch on analog input not a great idea,the analog to digital converter inside the micro, switches too fast, you are going from 5 volts to gnd ,might cause a spike (reset on micro )
any analog sensor and anything with analog output goes slowly from 0-5 or 5-0

here is info on using analog input with a switch
The Atmega datasheet also cautions against switching analog pins in close temporal proximity to making A/D readings,This can cause electrical noise and introduce jitter in the analog system