Num Pad plus Soundsensor


I have following setup.

with a 4x4 number pad i want to start different if loops. If 1 than start 1, etc.
And I want to combine that with a soundsensor. So if i press 1, start 1 and wait for the soundsensor.

if (key =='1') {
   int (sensorData == 1) {
   if (LEDstatus==false) {
   else {

If i do not use the num Pad the toggle between 1 and 0 on the LCD display works. With the Num pad it won't.

Can you help me out?
Thanks in advance,


Start by posting a complete program and using code tags rather than quote tags when you do

I noticed this in the snippet you posted

int (sensorData == 1)

What are you trying to do and what does it actually do I wonder ?

= is used for assignment of values
== is used for comparison on values

Why are the brackets there ?


thanks for your reply.

Here is the code

#include <LiquidCrystal.h> // includes the LiquidCrystal Library 
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7) 

#include <Keypad.h>

const byte ROWS = 3; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {

byte rowPins[ROWS] = {3, 8, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {11,12,13}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

boolean LEDStatus=false;
int Sensor = 10;

void setup() { 
 pinMode(Sensor, INPUT);


void loop() { 

char key = keypad.getKey();
    // just print the pressed key
   if (key){
   if (key =='4'){

    int SensorData=digitalRead(Sensor); 

SO what happens when you run the code that is different from what you want to happen ?

I note that you are changing the value of a variable named LEDStatus and testing its value but you appear to have no LED

Have you tried adding some Serial.print()s to the program so that you can tell which parts are being executed and the value of pertinent variables at important points such as just before testing their value ?


i want it to stay in the if loop and toogle there between on and of. In this case it does it once. But i want it to react to the sensor until I press a different number in the keypad. Imagine it like choosing between different programs.

thanks. Jules

i want it to stay in the if loop

There is no such thing as an if loop. Unless the test is put in say a while loop then the test and dependant actions will occur only once

Suggestion :

Move the sensor reading code to a function, let's call it readSensor() and call it if the user entry is 4. OK so far. The trick is to check whether the number entered has changed since the last time through loop(). If there is no entry to read or the number entered has not changed since last time then call readSensor() again. If/when a different number is entered the program will not call readSensor() and you can make it do something else

ok thanks. i will give it a try.