Ok so i got another project in mind just need some help and to be steered in the right direction, got an arduino uno that i want to hook up to a key pad 4x3 3 length and 4 down, i simply want to be able to enter a 4 digit code and have it stored to an sd card, i don’t think the Arduino board has enough storage, also want to make this portable thats why i chose the arduino nano, is there something smaller or something better lmk thanks for the help
Hello, why did you post in a category that is explicitly designed as not for postiing questions?
I moved your post for this time.
do yourself a favour and please read How to get the best out of this forum and provide a better description of what you are looking for in terms of help.
There are dozens of tutorials for keypads, getting passcodes, writing to SDs etc…. What have you tried?
Micro SD is smaller as SD Card. Arduino Mini is smaller as Arduino Nano.
Yes and micro sd card, ok yes my question was pretty plain, would like and option for an sd card if i need to expand storage, but also don’t know if the arduino nano has storage or how much it can hold, if not needed great, what i mostly need is help with the code, pulled some code form online now just need to figure out how to save 4 digit code on the arduino its self( store it in a text file or something) and start over again to recored another one once i press enter
ok yes my question was pretty plain, would like and option for an sd card if i need to expand storage, but also don’t know if the arduino nano has storage or how much it can hold, if not needed great, what i mostly need is help with the code, pulled some code form online now just need to figure out how to save 4 digit code on the arduino its self( store it in a text file or something) and start over again to recored another one once i press enter, so far ive set up my arduino nano and the key pad now i just need help on how to save it
Which Nano. There are several completely different ones.
Why an SD card. A basic classic v3 Nano (and Uno) has 1k of EEPROM build-in,
Plenty of room to hide many 4-digit codes, that stay there when the power is turned off.
What else do you want to store.
The Uno/Nano v3 has 32k flash. That's a lot of code and quite a bit of text.
Leo..
one question is how many codes do you want to save. Is that like a log of passcode entries? Do you need to save timing too for example ?
Also how long do you need to keep them around?
See man your right on it, its my fist time doing a project so im new, bought some osoyoo lgt nano comatible with atmega328 off amazon, have the basic set up the arduino nano and the 3x4 key pad have them hooked up and have the basic code i pulled off online, it all works numbers show up and all, now like you were saying yes its like a logs of passwords 4 digits long, no more than around 1000 4 digits codes, i just simply want to be able to input a 4 digit code and when i press # pound it saves it to the arduino nano its self or an sd card were i can access it later any time i need and yes time and date would definitely help didn’t even think of that
so it seems you need to work on your requirements
Saving the time in the log will require access to an RTC of some sort
being able to access later on the data means you need to define how this is being accessed , may be a button to dump the file on the serial monitor
it's not difficult to patch all this together based on existing libraries
here is an example in a simulator
click to see the code
#include <Toggle.h>
#include "RTClib.h"
#include <Keypad.h>
#include <SD.h>
#define CS_PIN 10
const char * logFileName = "data.txt";
const uint8_t ROWS = 4;
const uint8_t COLS = 3;
char keys[ROWS][COLS] = {
{ '1', '2', '3'},
{ '4', '5', '6'},
{ '7', '8', '9'},
{ '*', '0', '#'}
};
uint8_t colPins[COLS] = { 5, 4, 3 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const byte dumpButtonPin = 2;
Toggle dumpButton;
RTC_DS1307 rtc;
void dumpData() {
File logFile = SD.open(logFileName);
if (logFile) {
Serial.println(logFileName);
while (logFile.available()) {
Serial.write(logFile.read());
}
logFile.close();
Serial.println("\n------------");
} else {
Serial.println("error opening log file!");
}
}
void handleKeypad() {
const byte codeLength = 4;
static char code[codeLength + 1];
static byte codePos = 0;
char key = keypad.getKey();
if (key != NO_KEY) {
if ((codePos == codeLength - 1) && (key == '#' || key == '*')) { // if we have the 4 digits and user validates
File logFile = SD.open(logFileName, FILE_WRITE); // and save it at the end of the file
if (logFile) {
Serial.print("writing "); Serial.println(code);
DateTime now = rtc.now();
logFile.print(now.year());
logFile.print('/');
if (now.month() < 10) logFile.write('0');
logFile.print(now.month());
logFile.print('/');
if (now.day() < 10) logFile.write('0');
logFile.print(now.day());
logFile.print("\t");
logFile.print(now.hour());
logFile.print(':');
if (now.minute() < 10) logFile.write('0');
logFile.print(now.minute());
logFile.print(':');
if (now.second() < 10) logFile.write('0');
logFile.print(now.second());
logFile.print('\t');
logFile.println(code);
logFile.close();
} else {
Serial.println("error opening log file for writing!");
}
codePos = 0;
} else {
if (key != '#' && key != '*') {
code[codePos++] = key;
code[codePos] = '\0'; // make it a correct c-string
if (codePos >= codeLength) codePos = codeLength - 1; // don't overflow
Serial.println(code);
}
}
}
}
void setup() {
dumpButton.begin(dumpButtonPin);
Serial.begin(115200);
Serial.print("Initializing SD card... ");
if (!SD.begin(CS_PIN)) {
Serial.println("Card initialization failed!");
while (true);
}
Serial.println("initialization done.");
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 25, 2024 at 2pm you would call:
// rtc.adjust(DateTime(2024, 1, 25, 14, 0, 0));
}
DateTime now = rtc.now();
Serial.print("Date: ");
Serial.print(now.year());
Serial.print('/');
if (now.month() < 10) Serial.write('0');
Serial.print(now.month());
Serial.print('/');
if (now.day() < 10) Serial.write('0');
Serial.println(now.day());
Serial.print("Time: ");
Serial.print(now.hour());
Serial.print(':');
if (now.minute() < 10) Serial.write('0');
Serial.print(now.minute());
Serial.print(':');
if (now.second() < 10) Serial.write('0');
Serial.println(now.second());
Serial.println("System ready to log codes.");
}
void loop() {
// pressing the button dumps the data from the log file
dumpButton.poll();
if (dumpButton.onPress()) dumpData();
// keypad management
handleKeypad();
}
Bro thanks so much you definitely steered me in the right direction, instead of that big nano uno im gonna use the nano, if i make this portable will i still be able to hook up to my laptop and then press the button and be able to see all the 4 digit code recorded
Have fun !
Silly request please speak in sentences with punctuation I think that dump might have ended with a question but I don't really know so I doubt anyone will notice or answer do you
Ok so I made the same thing just smaller, couldn't find a 3x4 keypad so I made it work with a 4x4. Will I lose the data if power is lost? and can I just hook up a small battery to it? to make it portable
check it out
thanks for taking the time out your very busy day to let me know how important i am to you thanks, my question was already answered!!
Glad I could help. You'll eventually discover that the effort to communicate clearly to others is rewarding. Until then, I've silenced you. No problem.
thanks for making me your number 1 priority since you have nothing else going on for u
@gt900 please stop this.
The remark about your post was anchored in willingness to clarify your intent - whether this was just a statement or if there was a question there.
Data saved in an SD card survives power loss.
I assume all is under control since you say it’s solved so I’ll close this thread.