intergrating with existing project car starter



  • hi everyone
    so i have a project for a nfc car starter ive just recently completed....
    i was wondering about integrating it into a node so that i could prestart and warm up my car in the mornings....

    however ive never dreamed of mysensors before that last few months and prebuilding my own seems a little out of my league....

    anyone have any advice on how i could integrate?
    thanks in advance to anyone who can give me even a hint
    this is running on an arduino nano

    int accessories = 2; //accessory
    int CarOn = 3; //power
    int Starter = 4; //ignition
    int indicatorPin1 = 5;
    int indicatorPin2 = 6;
    int indicatorPin3 = 7;
    int indicatorPin4 = 8;
    int handbrakePin1 = 9;
    int carRunState = 0;
    int handbrakeState = 0;
     
      #include <Wire.h>
      #include <PN532_I2C.h>
      #include <PN532.h>
    
      PN532_I2C pn532i2c(Wire);
      PN532 nfc(pn532i2c);
     
    void setup(void) {
      pinMode(accessories, OUTPUT);
      pinMode(CarOn, OUTPUT);
      pinMode(Starter, OUTPUT);
      pinMode(indicatorPin1, OUTPUT);
      pinMode(indicatorPin2, OUTPUT);
      pinMode(indicatorPin3, OUTPUT);
      pinMode(indicatorPin4, OUTPUT);
      pinMode(handbrakePin1, INPUT);
      Serial.begin(115200);
      Serial.println("Hello! I'm a Car!");
    
      nfc.begin();
    
      uint32_t versiondata = nfc.getFirmwareVersion();
      if (! versiondata) {
        Serial.print(versiondata);
        Serial.print("PN53x key scanner board not online");
        while (1); // halt
      }
      
      // Got ok data, report state
      Serial.print("Reader Online1, ");
     
      
      // Set the max number of retry attempts to read from a card
      // This prevents us from waiting forever for a card, which is
      // the default behaviour of the PN532.
      nfc.setPassiveActivationRetries(0xFF);
      
      // configure board to read NFC tags
      nfc.SAMConfig();
        
      Serial.println("Waiting for a valid key");
    }
    
    void loop(void) {
      String ringUid;
      boolean success;
      uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
      uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
      
      // Wait for an ISO14443A type cards (NFC Ring, Mifare, etc.).  When one is found
      // 'uid' will be populated with the UID, and uidLength will indicate
      // if the uid is 4 bytes (Mifare Classic) or 7 bytes (NFC Ring or Mifare Ultralight)
      success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
      
      if (success) {
        // Display some basic information about the card
        
    //    Serial.print("  UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
        Serial.print("  UID Value: ");
        for (uint8_t i = 0; i < uidLength; i++)
        {
          Serial.print("..");
          Serial.print(uid[i], HEX);
          ringUid += String(uid[i], HEX);
          
    
        }
        Serial.println(ringUid + "\n");
        if (ringUid == "42cbfd26f3f81" || ringUid == "4b4c22993c81" || ringUid == "4323222993c81" || ringUid == "4a2cd26f3f80"){
          Serial.println("Key accepted!");
    
      }
        
        
        if ((ringUid == "42cbfd26f3f81" || ringUid == "4b4c22993c81" || ringUid == "4323222993c81" || ringUid == "4a2cd26f3f80") && (carRunState == 0)){
          Serial.println("PERMISSION GRANTED, SYSTEMS ON");
          digitalWrite(accessories, HIGH);   // sets latching relay trigger on for ignition mode in car to allow start
          digitalWrite(indicatorPin2, HIGH); //show state, second LED
          //delay(100);                  // waits briefly
          digitalWrite(CarOn, HIGH);    // removes latching relay trigger
          delay(1500);
          carRunState = 1;
        }
        else if ((ringUid == "42cbfd26f3f81" || ringUid == "4b4c22993c81" || ringUid == "4323222993c81" || ringUid == "4a2cd26f3f80") && (carRunState == 1)){
         // if (handbrakeState = 0){if handbrake is on then safe to crank car, if not then skip this mode entirely
           { Serial.println("ENGINE CRANKING");
                delay(100);
           digitalWrite(Starter, HIGH);   // triggers output for engine starting
            digitalWrite(indicatorPin3, HIGH); //show state, third LED
            delay(1000);                  // waits for a second
            digitalWrite(Starter, LOW);    // removes triggered output 
          delay (1000);
            Serial.println("ENGINE CRANKING COMPLETE");
          }
          carRunState = 2;     
        }
        else if ((ringUid == "42cbfd26f3f81" || ringUid == "4b4c22993c81" || ringUid == "4323222993c81" || ringUid == "4a2cd26f3f80") && (carRunState == 2)){
         
           {
            
            digitalWrite(indicatorPin3, LOW); //turn off 3rd LED
                     // waits for a second
            Serial.println("ENGINE SHUTDOWN");
          //delay(200);                  // waits briefly  
          digitalWrite(CarOn, LOW);   //reset relay 
          digitalWrite(accessories, LOW);   
        delay(3000);
        carRunState = 0;
        digitalWrite(indicatorPin1, LOW); //LED1 off 
      }
      }
      }
    }
    
    

  • Admin

    Cool project!
    Just use a simple relay example. Insert the start-car code somewhere here:

    https://github.com/mysensors/MySensors/blob/development/examples/RelayActuator/RelayActuator.ino#L83



  • @hek looks good...thanks for that ill investigate over the next week getting it running


 

327
Online

7.9k
Users

8.8k
Topics

93.8k
Posts