# Why won't this code work

**URL:** <https://forum.arduino.cc/t/why-wont-this-code-work/1337927>\
**Category:** Programming\
**Created:** [January 1, 2025, 7:01pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927 "2025-01-01T19:01:03Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![cammycam32112](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cammycam32112/32/1126429_2.png) [@cammycam32112](https://forum.arduino.cc/u/cammycam32112)\
**Post date:** [January 1, 2025, 7:01pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/1 "2025-01-01T19:01:04Z")

</div>

```arduino
type or paste code here

```

#include \<Wire.h\>  
#include   
#include \<Servo.h\>  
#include \<EEPROM.h\>  
#include

int Button = 10; //Push Button  
const byte numRows = 4; //number of rows on the keypad  
const byte numCols = 4; //number of columns on the keypad

char keymap[numRows][numCols] =

{ '1', '2', '3', 'A' },  
{'4', '5', '6', 'B'),  
{'7', '8', '9', 'C'),  
{'\*', '0', '#', 'D'}  
};

char keypressed; //Where the keys are stored it changes very often  
char code[] = { '1', '2', '3', '4' }; //The default code, you can change it or make it a 'n' dig

char checkl[sizeof(code)]; //Where the new key is stored

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 1, 2025, 7:04pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/2 "2025-01-01T19:04:14Z")

</div>

Welcome to the forum

Your topic has been moved to the Programming category of the forum

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 1, 2025, 7:05pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/3 "2025-01-01T19:05:03Z")

</div>

Please post a complete sketch, using code tags when you do, and describe the problems that you have with it

---

<div class="post-metadata">

**Author:** ![cammycam32112](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cammycam32112/32/1126429_2.png) [@cammycam32112](https://forum.arduino.cc/u/cammycam32112)\
**Post date:** [January 1, 2025, 7:08pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/4 "2025-01-01T19:08:42Z")

</div>

how do I do that

---

<div class="post-metadata">

**Author:** ![cammycam32112](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cammycam32112/32/1126429_2.png) [@cammycam32112](https://forum.arduino.cc/u/cammycam32112)\
**Post date:** [January 1, 2025, 7:11pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/5 "2025-01-01T19:11:30Z")

</div>

```arduino
#include <Wire.h>
#include <Keypad.h>
#include <Servo.h>
#include <EEPROM.h>
#include <LiquidCrystal I2C.h>

int Button = 10; //Push Button
const byte numRows = 4; //number of rows on the keypad
const byte numCols = 4; //number of columns on the keypad

char keymap[numRows][numCols] =

  { '1', '2', '3', 'A' },
{'4', '5', '6', 'B'),
 {'7', '8', '9', 'C'),
 {'*', '0', '#', 'D'}
 };

  char keypressed; //Where the keys are stored it changes very often
  char code[] = { '1', '2', '3', '4' }; //The default code, you can change it or make it a 'n' dig

  char checkl[sizeof(code)]; //Where the new key is stored

```

---

<div class="post-metadata">

**Author:** ![cammycam32112](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cammycam32112/32/1126429_2.png) [@cammycam32112](https://forum.arduino.cc/u/cammycam32112)\
**Post date:** [January 1, 2025, 7:14pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/6 "2025-01-01T19:14:04Z")

</div>

In the second line of the code, it says #include \<Keypad.h\> and when I try to upload it it says Compilation error: Keypad.h: No such file or directory

---

<div class="post-metadata">

**Author:** ![cammycam32112](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cammycam32112/32/1126429_2.png) [@cammycam32112](https://forum.arduino.cc/u/cammycam32112)\
**Post date:** [January 1, 2025, 7:15pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/7 "2025-01-01T19:15:00Z")

</div>

```arduino
#include <Wire.h>
#include <Keypad.h>
#include <Servo.h>
#include <EEPROM.h>
#include <LiquidCrystal I2C.h>

int Button = 10; //Push Button
const byte numRows = 4; //number of rows on the keypad
const byte numCols = 4; //number of columns on the keypad

char keymap[numRows][numCols] =

  { '1', '2', '3', 'A' },
{'4', '5', '6', 'B'),
 {'7', '8', '9', 'C'),
 {'*', '0', '#', 'D'}
 };

  char keypressed; //Where the keys are stored it changes very often
  char code[] = { '1', '2', '3', '4' }; //The default code, you can change it or make it a 'n' dig

  char checkl[sizeof(code)]; //Where the new key is stored

```

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [January 1, 2025, 7:16pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/8 "2025-01-01T19:16:44Z")

</div>

Please post the complete code as already requested.

---

<div class="post-metadata">

**Author:** ![cammycam32112](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cammycam32112/32/1126429_2.png) [@cammycam32112](https://forum.arduino.cc/u/cammycam32112)\
**Post date:** [January 1, 2025, 7:19pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/9 "2025-01-01T19:19:32Z")

</div>

that is the complete code

---

<div class="post-metadata">

**Author:** ![van\_der\_decken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/van_der_decken/32/1006976_2.png) [@van\_der\_decken](https://forum.arduino.cc/u/van_der_decken)\
**Post date:** [January 1, 2025, 7:22pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/10 "2025-01-01T19:22:59Z")

</div>

No `setup()` function, no `loop()` function; no, sorry, that is not a complete sketch. All you have is includes and declarations, no actual code.

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [January 1, 2025, 7:23pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/11 "2025-01-01T19:23:24Z")

</div>

> [@cammycam32112](#):
>
> that is the complete code

It's incomplete. It wouldn't compile even without the library problem. No `setup()` function. No `loop()` function.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 1, 2025, 7:23pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/12 "2025-01-01T19:23:31Z")

</div>

> [@cammycam32112](#):
>
> Compilation error: Keypad.h: No such file or directory

Have you installed the Keypad library and, if so, please post the full path to where it is located on your PC

---

<div class="post-metadata">

**Author:** ![cammycam32112](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cammycam32112/32/1126429_2.png) [@cammycam32112](https://forum.arduino.cc/u/cammycam32112)\
**Post date:** [January 1, 2025, 7:23pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/13 "2025-01-01T19:23:37Z")

</div>

ok Thanks

---

<div class="post-metadata">

**Author:** ![ShermanP](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@ShermanP](https://forum.arduino.cc/u/ShermanP)\
**Post date:** [January 1, 2025, 8:35pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/14 "2025-01-01T20:35:25Z")

</div>

> [@cammycam32112](#):
>
> ```arduino
> {'4', '5', '6', 'B'),
> {'7', '8', '9', 'C'),
> 
> ```

These lines should have closing braces, not closing parentheses.

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [January 1, 2025, 10:52pm UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/15 "2025-01-01T22:52:55Z")

</div>

If you open a new and empty \*.ino-file  
This file isn't completely empty there will be

```arduino
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

```

Which is the **absolutely real** bare-minimum **each and every** Arduino-IDE-code **must** have.  
And these lines are missing in the code that you have posted.

Take a look into this tutorial:

[Arduino Programming Course](https://startingelectronics.org/software/arduino/learn-to-program-course/)

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [January 2, 2025, 1:24am UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/16 "2025-01-02T01:24:58Z")

</div>

@cammycam32112 - Follow this tutorial to get a good start with good code and good advice...

> [@Keypad data entry. A beginners guide](https://forum.arduino.cc/t/keypad-data-entry-a-beginners-guide/660309):
>
> A common problem raised in the forum is how to use a keypad to enter a number to be used in a sketch. The examples with the Keypad library show the principles but there is little or no explanation of how they work or how they can be changed The aim of this thread is to explain the principles of keypad entry, explain how and why some things work or don't work and to provide a way forward for more complicated use of the Keypad library Let's start with "How do I enter a number using the keypad ?" …

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 1, 2025, 1:25am UTC](https://forum.arduino.cc/t/why-wont-this-code-work/1337927/17 "2025-07-01T01:25:34Z")

</div>

Closed on July 1, 2025, 1:25am UTC

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