Basic switch but input is not stable

Hi,

I am a NEWBIE so please forgive me.

I have this code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int inPin = 7; // the number of the input pin
int outPin = 10; // the number of the output pin

void setup()
{
lcd.begin(16,2);
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
}

void loop(){

lcd.setCursor(1,1);

if (digitalRead(inPin)==HIGH)
{
digitalWrite(outPin,HIGH);
lcd.print(“High”);
}
if (digitalRead(inPin==LOW))
{
digitalWrite(outPin,LOW);
lcd.print("Low ");
}
delay(200);
}

But the output is flashing high/ low. The circuit is as basic as I can make it. I can’t see any reason for this flashing to occur. It also did it with out the LCD and only an LED. When the button is pressed it states high but takes a lot longer than 200 milliseconds to turn back off an than flash again. I used the LCD to see if the input is stable but I can’t really tell. The LED flashes at about the 200 ms speed.

Help Please.

The board is an OSEPP Mega.

20170202_133306 (640x480).jpg

pinMode(inPin, INPUT); Change to: pinMode(inPin, INPUT_PULLUP);

Show us a good schematic of your circuit. Show us a good image of your wiring.

.

I think the problem is sensitivity! When I unplug the input from the switch and plug it directly to the + it stays HIGH. If I disconnect it, it flickers and is sensitive to my finger pressence. When I connect it to GND is stays LOW.

Did you try INPUT_PULLUP ?

Show us a good schematic of your circuit. Show us a good image of your wiring.

When people try to help, you should listen, and tell us what differences you get.

.

The INPUT_PULLUP would not have any effect in your circuit.
Pressing the switch would mahe the input pin HIGH. Releasing the switch would float the input pin,
so it would still be high (pulled up).
Using the INPUT_PULLUP you have to change the switchwiring from the +5v. to gnd.
In that way the input pin would be HIGH with switch released, and LOW with switch pressed.

.

If you refuse to use INPUT_PULLUP and change your connection method, you need an external pull-down resistor. The way you have it connected at the moment it is still floating when the switch is open.

Thank-you guys.

I wondered why. I will try the input_pullup. Sorry for the late response. I am stuck at work right now.

Cheers,

kzinty: Thank-you guys.

I wondered why. I will try the input_pullup. Sorry for the late response. I am stuck at work right now.

Cheers,

Read these: http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

http://www.gammon.com.au/forum/?id=11955

.