need a help about testing a password

i want to turn on/off a LED by a password without using a keypad
… need just char[5],
i want to put the password of 4 character at the time and test if true, Led X high, else, Led X low

this is an exemple of my own work … but it dosent work correctly

char data = ’ '; //Variable for storing received data
char cod[5]=(“1234”) ; //code to test (1234);
int v= 0; //counter
void setup()
pinMode(8, OUTPUT);
pinMode(10, OUTPUT);

void loop()
digitalWrite(8,HIGH); //alwayse on
for (int j=0; j<4; j++)
if(Serial.available() > 0) // Send data only when you receive data:
data =; //Read the incoming data & store into data

Serial.print(data); //Print Value inside data in Serial monitor

if (data==cod[j])


if (v==4)

… need a smart solution …
please …
thanks aloot

It doesn't work? What does that mean? Because you never reset v? Because a for loop is not the right control structure here?

Couple things.

1.) Please ALWAYS wrap your code in [ code ] [ /code ] tags… (use the </> icon if needed…)

2.) If you dont want to use a keyboard/keypad to enter in your ‘password’… how do you plan on entering it? What event lets you interact with your project?

3.) Where is this serial data coming from that you are attempting to parse in the code above?

I think reading the serial basics thread would help you out:

meaning by dosent work correctly m ... it need 4 time giving the right code to turn on the LED 10 .. all what i need is how to turn on a led using a password (caracters,numbers,...) ... the serial come from a bluetooth sumilation

I’m not clear on your are saying or asking??

Did you bother to look at the serial basic link I posted for you?

slight edit taken from example #2 there: (not tested at work, no IDE…etc)

// Example 2 - Receive with an end-marker

const byte numChars = 5;
char receivedChars[numChars];   // an array to store the received data
char targetPassword[] = "1234";
boolean newData = false;

void setup(){
    Serial.println("<Arduino is ready>");

void loop(){

void recvWithEndMarker(){
    static byte indexCounter = 0;
    char endMarker = '\n';
    char receivedCharater;
    while(Serial.available() > 0 && newData == false){
        receivedCharater =;

        if(receivedCharater != endMarker){
            receivedChars[indexCounter] = receivedCharater;
            if (indexCounter >= numChars){
                indexCounter = numChars - 1;
            receivedChars[indexCounter] = '\0'; // terminate the string
            indexCounter = 0;
            newData = true;

void showNewData(){
    if (newData == true) {
        Serial.print("This just in ... ");
        newData = false;

void blinkLED(submittedPassword){
	if(strcmp(submittedPassword, targetPassword) == 0){
		//do whatever you want to blink the led
		//no match turn on fail led