Noob question

Hey people :slight_smile:

I just got my arduino starter pack yesterday, and i'm just testing this out, a very simple idea, a light switch.

int switchstate = 1;
int ledPin = 13;
int speaker = 7;
int listener = 8;
void setup() {
pinMode(speaker, OUTPUT);
pinMode(listener, INPUT);
digitalWrite(speaker, HIGH);
}
void loop() {

switchstate = digitalRead(listener);
if (switchstate == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

So I have a wire going out of speaker and into listener, with a switch on the wire. Flick the switch on, and the voltage from speaker should go through the wire into listener, listener returns HIGH, light comes on.

But for some reason, the light remains on forever, regardless of switch position. I can even remove the cables and it still stays on!

So my question is, whats goin on? :3

You left the input pin floating.

Search for "pull-up" resistors to understand how to fix it.

aaahh, so LOW actually does mean "low", and not "off" or "false". Gawtcha :slight_smile: Now off to the electronics store to buy some resistors!

I specifically said to search for pull-up because the Arduino (ATmega chip) has built in pull-up resistors. Re-read the pinmode() reference page to understand how to turn them on.

Hi.

I would recommend something like the oomlout kit tutorials (same as the Sparkfun (and Adafruit?) kit tutorials).

http://www.oomlout.com/a/products/ardx/

Once through the tutorial, I will bet that things make a bit more sense :wink:

magicaxis:
aaahh, so LOW actually does mean "low", and not "off" or "false". Gawtcha :slight_smile: Now off to the electronics store to buy some resistors!

My first mistake ever too. But I did it with a 7408 AND TTL package and two switches, not an entire microcontroller.

aaahh, so LOW actually does mean "low", and not "off" or "false". Gawtcha Now off to the electronics store to buy some resistors!

Resistors are nice, but definitely an OpAmp...