Go Down

Topic: Reading Voltage from my body? (Read 967 times) previous topic - next topic

wretrop

Apr 27, 2013, 05:34 am Last Edit: Apr 27, 2013, 06:43 am by wretrop Reason: 1
Hi all!

First off, I'm completely new to Arduino, electronics, and the forum so this might be a simple answer...

Goal:
I'm trying to build a circuit with a tilt switch in it.  When the switch is closed, I want the arduino to recognize it and turn on an LED.

Problem:
The circuit works, sort of.  For awhile the LED was flashing for no apparent reason with the tilt switch in the open position.  I disconnected the tilt switch section from the circuit completely and the LED would still flash.  I discovered that if *I* grabbed a wire connected to a ground pin the flashing would stop and the tilt switch would operate somewhat normally.  I say somewhat because it takes a few seconds for the arduino the recognize that the switch is open again when I tip it back.

EDIT:  Oh also, if I bring my hand closer to the LED while not touching a ground wire, the flashing intensifies.  If I move away from the LED, it calms down and stops.

Question:
What's going on?  Is the arduino so sensitive that it's reading voltage from my body?  I'm assuming that I'm doing something wrong here...

Set Up:
5V -> 3300? Pull up Resistor -> Tilt Switch -> Pin 12

Pin 4 -> 2200? Pull up Resistor -> Tiny lil green LED -> Ground

EDIT: Schematic Image Attached


Code:

#define led 4
int input = 12;
int count = 0;
int val = 0;

void setup () {

 Serial.begin(9600);
 pinMode(led,OUTPUT);
 pinMode(input, INPUT);

}


void loop() {

 val = digitalRead(input);



if (val == HIGH) {

 digitalWrite(led, HIGH);
 Serial.println(val);

}
else {
 
 digitalWrite(led, LOW);
 Serial.println(val);

}

}

sreedevk

Can you upload the schematic so that it would be much clear??`

wretrop


JimboZA

Those aren't pull-ups, those are series resistors. That happens to be right for the LED (edit: although you might like to re-think the value), but you need to wire the switch something like this.

HTH....
No PMs for help please. Not active on this forum any more.

fungus

You need this in "setup()":

Code: [Select]

  pinMode(input, INPUT);
  digitalWrite(input, HIGH);


No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

MarkT

This is a common issue reported here - input PINs float if not connected to some definite potential, which
is why pull-up or pull-down resistors (built-in or external) are required for interfacing to any mechanical
switch.
[ I won't respond to messages, use the forum please ]

Zapro

You are aware that you can do away without the Arduino ? There is no reason to have a microcontroller turn on an LED, the tilt switch can do that directly...

// Per.

Go Up