Button Board Freezing

I installed a project that required the 'Wire', 'SoftwareSerial' and 'Adafruit_ADS1X15' libraries.
Now when I do even the simplest of pushbutton turn LED on tasks it freezes the board until I release the button.
Using both UNO R3 & Mega 2560
What could possibly cause this?

I'd take a wild guess and say "your code" :wink: but you didn't post it for anyone to see, so who knows?

Perhaps a mis-use of delay().

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.

It's not the code.
I was just using a basic on/off program to test the boards...

int ledPin = 13; // choose the pin for the LED
int touchPad = 2; // Connect Touch sensor on Digital Pin 2
int inputPin = 3; // Connect sensor to input pin 3
Serial.begin(9600);
void setup() {
pinMode(ledPin, OUTPUT); // set LED as output
pinMode(inputPin, INPUT); // set pushbutton as input
pinMode(touchPad, INPUT); //Set touch sensor pin to input mode
}
void loop(){
int val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
}
if(digitalRead(touchPad)==HIGH) { //Read Touch sensor signal
digitalWrite(ledPin, HIGH); // if Touch sensor is HIGH, then turn on 
  }else{
    digitalWrite(ledPin, LOW); // if Touch sensor is LOW, then turn off the led
  }
delay(100);
  Serial.print(val);
}

so zeros print while no button pushed and as soon as I push the button the serial print freezes and there is no change of state.

It's certainly not the code you posted, since it doesn't even compile.

One possible reason that it does not behave as expected is that Serial.begin() should be inside setup().

Not behind a PC to test.

... which is why I said it won't compile as posted.

sketch_jul09b:4:1: error: 'Serial' does not name a type
 Serial.begin(9600);
 ^~~~~~
exit status 1
'Serial' does not name a type

When I fixed your uncompilable code by moving Serial.begin() it works for me. However, all my button boards are wired with the button from pin to ground and I therefore use input pullup in pinMode(). Then it shows 1's while the button is not pressed, and changes to 0 when pressed, as expected in my active low case.

Your code and expectations @newbcoder require that you have a pull down resistor on the pin- do you? If not, you need one. But it's easier to use the internal pullup as explained above.

Sorry people, my bad, early morning, yes, I forgot to put a pull up resistor on the board.

Read the previous post again

Hi, @newbcoder
Can you please post your working code?
Can we please have a circuit diagram?
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

These two will supply answers to anyone else looking at this threat.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.