message:
I have problem in sketch compiling error message is 'printNormalModeMessage' is not declared so what I can do

<!-- language: c++ -->

    /* a,rduino door look project */
    #include <SPI.h>
    #include <MFRC522.h>
    #include <LiquidCrystal.h>
    #include <Servo.h>

    #define RST_PIN  9
    #define SS_PIN 10

    byte readCard[4];
    char* myTags[100] = {};
    int tagsCount = 0;
    String tagID = "";
    boolean successRead = false;
    boolean correctTag = false;
    int proximitySensor;
    boolean doorOpened = false;

    //Creat instance
    MFRC522 mfrc522(SS_PIN, RST_PIN);
    LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
    //Parameters : (rs, enable, d4, d5, d6, d7)
    Servo myServo;

    void setup() {
      //Initiating
      SPI.begin();
      mfrc522.PCD_Init();
      lcd.begin(16,2);
      myServo.attach(8);

      myServo.write(10);

      lcd.print("-No Master Tag!-");
      lcd.setCursor(0,1);
      lcd.print("   SCAN NOW");

      while (!successRead) {
        successRead = getID();
        if (successRead == true) {
          myTags[tagsCount] = strdup(tagID.c_str());
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("-Master  Tag Set!-");
          tagsCount++;
        }
      }
      successRead = false;
      printNormalModeMessage();
    }
    void loop() {
      int proximitySensor = analogRead(A0);
      // if door closed
      if (proximitySensor > 200) {
        if ( ! mfrc522.PICC_IsNewCardPresent()) {
          return;
        }
        if ( ! mfrc522.PICC_ReadCardSerial()) {
          return;
        }
        tagID = "";
        for ( unit8_t i = 0; i < 4; i++) {
          readCard[i]  = mfrc522.uid.uidByte[i];
          tagID.concat(String(mfrc522.uid.uidByte[i],HEX));
        }
        tagID.toUpperCase();
        mfrc522.PICC_HaltA();

        correctTag = false;
        if (tagID == myTags[0]) {
          lcd.clear();
          lcd.print("Program mode:");
          lcd.setCursor (1,0);
          lcd.print("Add/ Remove Tag");
          while (!successRead) {
            successRead = getID();
            if (successRead == true) {
              for (int i = 0; i < 100; i++) {
                if (tagID == myTags[i]) {
                  myTags[i] = "";
                  lcd.clear();
                  lcd.setCursor(0,0);
                  lcd.print("   Tag Removed!");
                  printNormalModwMessage();
                  tagsCount++;
                  return:
                }
              }
            myTags[tagsCount] = strdup(tagID.c_str());
            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print(" Tag Added!");
            printNormalModeMessage();
            return;
            }
          }
        }
        successRead = false;
        for (int i = 0; i < 100; i++) {
          if (tagID == myTags[i] ) {
            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print( "Access Granted!");
            myServo.write(170);
            printNormalModeMessage();
            correctTag = true;
          }
        }
        if (correctTag == false) {
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print(" Access Denide!");
          printNormalModeMessags();
        }
      }
      else {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" Door opeded!");
        while (!doorOpened) {
          proximitySensor = analogRead(A0);
          if (proximitySensor > 200)  {
            doorOpened = true ;
          }
        }
        doorOpened = false;
        delay(500);
        myServo.write(10);
        printNormalModeMessage();
      }
    }
    uint8_t getID() {
      if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return 0;
      }
      if ( ! mfrc522.PICC_ReadCardSerial()) {
         return 0;
      }
      tagID = "";
      for ( unit_8 i = 0; i < 4; i++) {
        readCard[i] = mfrc522.uid.uidByte[i];
        tagID.concat(String(mfrc522.uid.uidByte[i],HEX));
      }
      tagID.toUpperCase();
      mfrc522.PICC_HaltA();
      return 1;
    }
    void printNoramalModeMessage() {
      delay(1500);
      lcd.clear();
      lcd.print("-Access Control-");
      lcd.setCorsor(0,1);
      lcd.print( " Scan Your Tag!");
    }

<!-- language: none -->

    Arduino: 1.8.2 (Windows 7), Board: "Arduino/Genuino Uno"

    C:\Program Files\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\Arduino\hardware -tools C:\Program Files\Arduino\tools-builder -tools C:\Program Files\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files\Arduino\libraries -libraries D:\arduino\libraries -fqbn=arduino:avr:uno -ide-version=10802 -build-path C:\Users\pc\AppData\Local\Temp\arduino_build_303473 -warnings=none -build-cache C:\Users\pc\AppData\Local\Temp\arduino_cache_499902 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files\Arduino\hardware\tools\avr -verbose D:\Arduino\dooropened.ino\dooropened.ino.ino
    C:\Program Files\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files\Arduino\hardware -tools C:\Program Files\Arduino\tools-builder -tools C:\Program Files\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files\Arduino\libraries -libraries D:\arduino\libraries -fqbn=arduino:avr:uno -ide-version=10802 -build-path C:\Users\pc\AppData\Local\Temp\arduino_build_303473 -warnings=none -build-cache C:\Users\pc\AppData\Local\Temp\arduino_cache_499902 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files\Arduino\hardware\tools\avr -verbose D:\Arduino\dooropened.ino\dooropened.ino.ino
    Using board 'uno' from platform in folder: C:\Program Files\Arduino\hardware\arduino\avr
    Using core 'arduino' from platform in folder: C:\Program Files\Arduino\hardware\arduino\avr
    Detecting libraries used...
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\pc\AppData\Local\Temp\arduino_build_303473\sketch\dooropened.ino.ino.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "C:\Users\pc\AppData\Local\Temp\arduino_build_303473\sketch\dooropened.ino.ino.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "C:\Users\pc\AppData\Local\Temp\arduino_build_303473\sketch\dooropened.ino.ino.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "C:\Users\pc\AppData\Local\Temp\arduino_build_303473\sketch\dooropened.ino.ino.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Users\pc\AppData\Local\Temp\arduino_build_303473\sketch\dooropened.ino.ino.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src\SPI.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Program Files\Arduino\libraries\rfid-master\src\MFRC522.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Program Files\Arduino\libraries\rfid-master\src\MFRC522Debug.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Program Files\Arduino\libraries\rfid-master\src\MFRC522Extended.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Program Files\Arduino\libraries\rfid-master\src\MFRC522Hack.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Program Files\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Program Files\Arduino\libraries\Servo\src\avr\Servo.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Program Files\Arduino\libraries\Servo\src\nrf52\Servo.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Program Files\Arduino\libraries\Servo\src\sam\Servo.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Program Files\Arduino\libraries\Servo\src\samd\Servo.cpp" -o "nul"
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Program Files\Arduino\libraries\Servo\src\stm32f4\Servo.cpp" -o "nul"
    Generating function prototypes...
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Users\pc\AppData\Local\Temp\arduino_build_303473\sketch\dooropened.ino.ino.cpp" -o "C:\Users\pc\AppData\Local\Temp\arduino_build_303473\preproc\ctags_target_for_gcc_minus_e.cpp"
    "C:\Program Files\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\pc\AppData\Local\Temp\arduino_build_303473\preproc\ctags_target_for_gcc_minus_e.cpp"
    Compiling sketch...
    "C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10802 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\Program Files\Arduino\libraries\rfid-master\src" "-IC:\Program Files\Arduino\libraries\LiquidCrystal\src" "-IC:\Program Files\Arduino\libraries\Servo\src" "C:\Users\pc\AppData\Local\Temp\arduino_build_303473\sketch\dooropened.ino.ino.cpp" -o "C:\Users\pc\AppData\Local\Temp\arduino_build_303473\sketch\dooropened.ino.ino.cpp.o"
    D:\Arduino\dooropened.ino\dooropened.ino.ino: In function 'void setup()':

    dooropened.ino:49: error: 'printNormalModeMessage' was not declared in this scope

       printNormalModeMessage();

                              ^

    D:\Arduino\dooropened.ino\dooropened.ino.ino: In function 'void loop()':

    dooropened.ino:62: error: 'unit8_t' was not declared in this scope

         for ( unit8_t i = 0; i < 4; i++) {

               ^

    dooropened.ino:62: error: 'i' was not declared in this scope

         for ( unit8_t i = 0; i < 4; i++) {

                              ^

    dooropened.ino:84: error: 'printNormalModwMessage' was not declared in this scope

                   printNormalModwMessage();

                                          ^

    dooropened.ino:86: error: expected primary-expression before ':' token

                   return:

                         ^

    dooropened.ino:86: error: expected ';' before ':' token

    dooropened.ino:86: error: expected primary-expression before ':' token

    dooropened.ino:93: error: 'printNormalModeMessage' was not declared in this scope

             printNormalModeMessage();

                                    ^

    dooropened.ino:105: error: 'printNormalModeMessage' was not declared in this scope

             printNormalModeMessage();

                                    ^

    dooropened.ino:113: error: 'printNormalModeMessags' was not declared in this scope

           printNormalModeMessags();

                                  ^

    dooropened.ino:129: error: 'printNormalModeMessage' was not declared in this scope

         printNormalModeMessage();

                                ^

    D:\Arduino\dooropened.ino\dooropened.ino.ino: In function 'uint8_t getID()':

    dooropened.ino:140: error: 'unit_8' was not declared in this scope

       for ( unit_8 i = 0; i < 4; i++) {

             ^

    dooropened.ino:140: error: 'i' was not declared in this scope

       for ( unit_8 i = 0; i < 4; i++) {

                           ^

    D:\Arduino\dooropened.ino\dooropened.ino.ino: In function 'void printNoramalModeMessage()':

    dooropened.ino:152: error: 'class LiquidCrystal' has no member named 'setCorsor'

       lcd.setCorsor(0,1);

           ^

    Using library SPI at version 1.0 in folder: C:\Program Files\Arduino\hardware\arduino\avr\libraries\SPI
    Using library rfid-master at version 1.3.6 in folder: C:\Program Files\Arduino\libraries\rfid-master
    Using library LiquidCrystal at version 1.0.5 in folder: C:\Program Files\Arduino\libraries\LiquidCrystal
    Using library Servo at version 1.1.2 in folder: C:\Program Files\Arduino\libraries\Servo
    exit status 1
    'printNormalModeMessage' was not declared in this scope

body:
See :

    dooropened.ino:49: error: 'printNormalModeMessage' was not declared in this scope

printNormalModeMessage();

You didn't implement this function.

(please align your code correctly to make it readable)


sender: user

sender: assistant

body:
    void printNoramalModeMessage() {
      delay(1500);
      lcd.clear();
      lcd.print("-Access Control-");
      lcd.setCorsor(0,1);
      lcd.print( " Scan Your Tag!");
    }

You can't spell "Normal".


message:
How to pass variables to custom callback functions

I want to use the Ticker library of the ESP8266 Arduino core to (asynchronously) delay the switch of a pin to a desired state like below. I am not sure about the "here is" function definitions and I am having a hard time to find some documentation. Please have a look at what I tried so far:

 #include <Ticker.h>

 Ticker change_pin;

 ...

  uint8_t desired_state = 1;
  ...
  change_pin.attach_ms(100, [](uint8_t state_to_change_to){
   if( digitalRead(PIN) != state_to_change_to ) {
    digitalWrite(PIN, state_to_change_to);
   }
   else {
    change_pin.detach();
   }
  }, desired_state);

But the compiler's yelling:

 espIKEA:145: error: no matching function for call to 'Ticker::attach_ms(int, toogle_light(uint8_t)::__lambda0, uint8_t&)'

    }, des_state);

       ^

 ...

 C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\Ticker/Ticker.h:45:7: note:   candidate expects 2 arguments, 3 provided

 C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\Ticker/Ticker.h:62:7: note: template<class TArg> void Ticker::attach_ms(uint32_t, void (*)(TArg), TArg)

   void attach_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg)

     ^

 C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\Ticker/Ticker.h:62:7: note:   template argument deduction/substitution failed:

 C:\Users\USER\Documents\Arduino\Scratch\pintest\pintest.ino:145:15: note:   mismatched types 'void (*)(TArg)' and 'toogle_light(u8)::__lambda0'

    }, des_state);

       ^

So, I am having too few knowledge to understand what to do about it. I really would like to avoid having a separate function for the callback body.

PS: Important source file can be found here: [Ticker.h][1]

  [1]: https://github.com/esp8266/Arduino/blob/master/libraries/Ticker/Ticker.h

body:
It looks like you are trying to do a lambda function and that's a bit too modern for the Arduino compiler.

So you have:

    change_pin.attach_ms(100, ????, desired_state);

Its just the ???? we need to sort, which you have:

    void DoStuff (state_to_change_to)
    {
        if( digitalRead(PIN) != state_to_change_to )
        {
            digitalWrite(PIN, state_to_change_to);
        }
        else
        {
            change_pin.detach();
        }
    }

Now you can't just define your own function signature, it has to be either callback_t or callback_with_arg_t.  So to make your "DoSTuff" function comply with callback_with_arg_t you have to define it as:

    void DoStuff (void* argument);

Which means inside you function you will have to do this:

    void DoStuff (void* argument)
    {
        if (argument != NULL)
        {
           const uint8_t state_to_change_to = *argument;
           if( digitalRead(PIN) != state_to_change_to )
           .... As above.

Does that make sense?

The library defines the signature of the function that acts as the call back, it has to otherwise it wouldn't be able to provide all the parameters.  void* gets around any pretence at type safe behaviour and is fine as long as you are careful to control what can get passed through those parameters.
Always remember if you are working asynchronously there is no guarantee that data will still exist when you process it, if its dynamic memory it could have been freed/deleted or variables can go out of scope.


body:
The function you are trying to call is a template function:

<!-- language: lang-c++ -->

    template<typename TArg>
    void attach_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg)
    {
        ....
    }

So, you need to tell it what type of parameter you are passing:

<!-- language: lang-c++ -->

    change_pin.attach_ms<uint8_t>(100, [](uint8_t state_to_change_to) {
    //                     ^- tell the compiler about the parameter
        ....
    }, desired_state);

-----------

To pass more than one parameter: Since the library only allows one parameter, I would create a `struct` and pass a pointer to it.

<!-- language: lang-c++ -->

    struct callback_parameter {
        int i;
        char *p;
    };

Then create one of these structs and pass the address of it. You just have to make sure the struct is valid the entire time the timer is running. So either use `new`, `static`, or make it global.

<!-- language: lang-c++ -->

    callback_parameter param; // global variable

    ...

    change_pin.attach_ms<callback_parameter *>(100, [](callback_parameter * state_to_change_to) {
        ....
    }, &param);


message:
analogWrite mosfet problem

i have a custom atmega328p board which have connected to pin 9 the gate of a MOSFET.
If i run a simple sketch like:

    void setup() {

    }
    void loop() {
      analogWrite(9,70);
    }

The motor connected to the mosfet works just fine, from 70pwm to 255pwm.

On the other sketch i'm receiving serial data from an android app via bluetooth. Ive 2 Servo motors and a DC motor connected to the mosfet.
The 2 servos works like expected, the DC motor doesn't spin unless i use a 255pwm.

    void loop() {
      if(Serial.available() > 0){
          state = Serial.read();
      }
      if (state == 'S') {
          servoONE.write(90);
          servoTWO.write(90);
          analogWrite(MOSFET,MOSFET_LOW);
      }
      else if (state == 'F') {
          analogWrite(9,70);
          servoONE.write(90);
          servoTWO.write(90);
      }
      else if (state == 'L') {
          servoONE.write(MAX_SERVO);
          servoTWO.write(MIN_SERVO);
      }
      else if (state == 'R') {
          servoONE.write(MIN_SERVO);
          servoTWO.write(MAX_SERVO);
      }
      else if (state == 'Q') {
          analogWrite(MOSFET,MOSFET_HIGH);
          servoONE.write(MAX_SERVO);
          servoTWO.write(MIN_SERVO);
      }
      else if (state == 'E') {
          analogWrite(MOSFET,MOSFET_HIGH);
          servoONE.write(MIN_SERVO);
          servoTWO.write(MAX_SERVO);
      }
    }

Do you know why the same motor works on the first sketch with any pwm above 70 and on the second sketch it only works at 255?

body:
You have a timer conflict.

Pin 9 is OC1A which is the Output Compare Channel A pin of Timer 1. However the Servo.h library also uses timer 1.

So you can't use servos and still use pins 9 (OC1A) and 10 (OC1B) as PWM.

However, you can still use pins 3, 5, 6 and 11 as PWM since they are on other timers.


message:
Specify F_CPU in arduino to use 8MHz clock

I am using a custom made AVR board with Atmege-328p on it and it doesn't have a 16MHz crystal on it. I would like to use the internal 8MHz as clock. I have set the appropriate Fuses but now I am unable to tell the programs that F_CPU is 8000000UL. One way of doing it is to add another variant to the boards. I would like to if there is another way to set F_CPU ?

body: No, the boards.txt file is where it is defined and the only place it is (or can be) defined. Making a new board variant is the proper way of adding a new board with new settings.


message:
Arduino Due unable to access library

I am unable to run code on Arduino Due that I earlier ran on an Arduino Uno. The error indicates it is unable to recognize the library. Could this library access problem be due to difference of the micro-controllers of the 2 boards?

body:
Quite possibly. The modern library format contains a list of board types it runs on (in `library.properties`). If the Due (SAM) isn't listed then it won't be included in the list of libraries.

For instance the SD library has:

    name=SD
    version=1.1.1
    author=Arduino, SparkFun
    maintainer=Arduino <info@arduino.cc>
    sentence=Enables reading and writing on SD cards.
    paragraph=Once an SD memory card is connected to the SPI interface of the Arduino or Genuino board you can create files and read/write on them. You can also move through directories on the SD card.
    category=Data Storage
    url=http://www.arduino.cc/en/Reference/SD
    architectures=*

However the AVR specific SPI library has:

    name=SPI
    version=1.0
    author=Arduino
    maintainer=Arduino <info@arduino.cc>
    sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus.
    paragraph=SPI is a synchronous serial data protocol used by microcontrollers for communicating with one or more peripheral devices quickly over short distances. It uses three lines common to all devices (MISO, MOSI and SCK) and one specific for each device.
    category=Communication
    url=http://www.arduino.cc/en/Reference/SPI
    architectures=avr

Note the last line of each - `architectures=...` - that defines what the library can work with. If your (unspecified) library doesn't have `*` or include `sam` in that parameter then there is no way that library will work with the Due.


message:
Powering leds from arduino with adapter

Sorry for having (again) a beginners question, but I was wondering something.

If I would want to drive like 20-30 LEDs from an Arduino (Uno), and I want to use an external adapter (12V, 1A), going into the Arduino, in what way I should drive the LEDs?

Problems I see:

- I cannot connect too many LEDs per pin (max 20mA per pin)
- I cannot connect too many LEDs per 'group' (I have to find out which pins are connected to what groups)
- I cannot connect too many LEDS in total because of the max. 200 mA per VCC/GND (there are 2 or 3 GNDs, so that should be ok)
- Using a relay/transistor etc, but how do I get the power? (there are also only 2 VCCs for 200 mA max)

So my basic question: how can I use the 1A from my adapter?

body:
The simplest thing you can do is group the LEDs together into chains that *almost* add up to the voltage of the power supply.

If you have LEDs with a 2V forward voltage (typical red LEDs) you could have up to say 5 per chain.

Each chain, since it only has 20mA or so maximum, can be driven with a simple small transistor.

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/UptfV.png)

<!-- End schematic -->

Connect the 12V to either VIN or the barrel jack, and also drive the LED chain through a suitable resistor (R=V/I = (12 - (Num LEDs * Forward Voltage)) / 0.02). You can have as many chains as your supply can provide current for.


message:
Cannot find COM port for Arduino after replacing Atmega328p

I had mistakenly burnt my ATmega328p that was there on the Arduino UNO R3 board. So I bought a new ATmega328p-pu with Arduino UNO bootloader installed and a sample blinking LED program pre-flashed.

However when I replaced it and plugged in to the PC using the provided Arduino programmer cable, I could not find the COM port in the device manager in Windows and neither in the Arduino IDE.

I should also mention that when I put the new Atmega328p-pu into the Arduino UNO board, the LED at 13 or L did start blinking. So I am inclined to think that both the bootloader and the sample program are there. But I cannot find the required COM port.

How do I fix this?

body:
Generally the IDE will detect one it can use, so you shouldn't need to use the Device Manager.

When you select the board type, so far, so good.

Then when you ask it to pick the port, it will present a list of ports that it has discovered that are registered in the Device Manager.

One thing you will notice is that if you have a Genuine Uno, for instance, it will list that next to the port name.

But if you are using a board (of any type) that have the CH340-type port it will show just the COM9 or whatever it finds.

If it doesn't find any ports (My laptop always detects the COM1 port on the back that I never use so in my case if that is all it finds then it is not finding any USB ports)  then jump ahead to the arrow below.

So by trying each one you will find a port that works with your board.  Or not.

I am sure you have already seen the errors it throws when you use a port that won't work for you.

----->  If you have tried all the ports listed and none works, then you are left with only a couple of possibilities:  Either the cable is bad, or the board is not responding.

Ultimately, it doesn't matter what it says in Device Manager if the IDE won't use it.

So if you can find another board and see if the cable works that would eliminate the cable as being a problem.

But if it simply will not respond then look above in the comments at what @Majenko said.

Good luck.


message:
How to store u-blox coordinates (lat, lng) values in doubles? [TinyGps++]

I use a u-blox gps with my arduino. I can successfully write out the value of a coordinate (lat, lng) like this: ` Serial.println (gps.location.lat(), 8);` but when I try to store the value with all the decimals it returns `8.00` instead of the correct coordinate + all of the 8 decimals.

This is my code:

    #include "TinyGPS++.h"
    #include <SoftwareSerial.h>
    SoftwareSerial gpsconnection (4,3);
    TinyGPSPlus gps;

    void setup()
    {
     Serial.begin(9600);
     gpsconnection.begin (9600);
    }

    void loop()
    {
     while (gpsconnection.available())
     {
       gps.encode(gpsconnection.read());
     }

     //this works and returns 8 decimals
     Serial.println (gps.location.lat(), 8);
     Serial.println (gps.location.lng(), 8);

     //but if i try to store it like this:
     double latcord = (gps.location.lat(), 8);
     double lngcord = (gps.location.lng(), 8);

     //it returns 8.00 on both the "latcord" and "lngcord" which is the wrong coordinate and also it doesnt return 8 decimals
     Serial.println (latcord);
     Serial.println (lngcord);

     //if i try to convert the value to a string and then back to a double like this:
     double lat = gps.location.lat();
     String msgLat =  String(lat, 8);

     double thelat = atof(msgLat.c_str());

     //with this i get the correct first two numbers out but only 2 decimals after, not 8 decimals as it should be.
     Serial.println (thelat);

    }

body:
You forgot the `, 8` from your println that specifies that it should print 8 decimal places. Instead you seem to have added it to the end of an assignment which makes absolutely no sense whatsoever.

    double latcord = gps.location.lat();
    double lngcord = gps.location.lng();

    Serial.println(latcord, 8);
    Serial.println(lngcord, 8);


message:
Output frequency from an SPI DAC (MCP4922) is lower than expected

I'm using a 2-channel, 12-bit DAC (MCP4922, [datasheet][1]) with an Arduino Uno, using the library written for it [here][2]. With the clock divider set to 2, I should have the SPI clock frequency at 8MHz. If each value sent to the DAC takes about 12 of these clock cycles, that leaves me with about 650kHz as my output frequency (when I'm sending a simple on-off signal like below), but the fastest I see is about 25kHz.

> void loop() {   dac.output2(4095, 0);   dac.output2(0, 4095);  }

Am I misunderstanding how the transfer protocol works? How can I make this faster? I'd like to both understand why this is so slow, and also to get an output frequency of at least 50kHz.

  [1]: http://ww1.microchip.com/downloads/en/DeviceDoc/22250A.pdf
  [2]: https://github.com/exscape/electronics/tree/master/Arduino/Libraries/DAC_MCP49xx

body:
Let's do some maths...

 * 16MHz master clock / 2 = 8MHz SPI clock
 * 2 transactions = 16 bits (not 12!)
 * 8,000,000 / 16 = 500,000
 * 2 transitions per cycle
 * 2 channels
 * 2 + 2 = 4
 * 500,000 / 4 = 125,000Hz

So in a *perfect* world you could expect 125kHz from the DAC. However the world is *far from* perfect.

Let's look at what it's *actually* doing when you use `output2()`:

    void DAC_MCP49xx::output2(unsigned short data_A, unsigned short data_B) {
      this->_output(data_A, CHANNEL_A);
      this->_output(data_B, CHANNEL_B);

      // Update the output, if desired.
      // The reason this is only in the dual-output version is simple: it's mostly useless
      // for the single-output version, as it would make more sense to tie the \LDAC pin
      // to ground, or do it manually. However, there should be a single-call method
      // to update *both* channels in sync, which wouldn't be possible with multiple
      // separate DACs (for which there is latch()).
      if (automaticallyLatchDual) {
        this->latch();
      }
    }

Assuming `automaticallyLatchDual` is false we can pretty much ignore that section. So it's calling `_output()` twice - once for each channel. And what does that do?

    void DAC_MCP49xx::_output(unsigned short data, Channel chan) {
      // Truncate the unused bits to fit the 8/10/12 bits the DAC accepts
      if (this->bitwidth == 12)
        data &= 0xfff;
      else if (this->bitwidth == 10)
        data &= 0x3ff;
      else if (this->bitwidth == 8)
        data &= 0xff;

      // Drive chip select low
      if (this->port_write)
        PORTB &= 0xfb; // Clear PORTB pin 2 = arduino pin 10
      else
        digitalWrite(ss_pin, LOW);

      // bit 15: 0 for DAC A, 1 for DAC B. (Always 0 for MCP49x1.)
      // bit 14: buffer VREF?
      // bit 13: gain bit; 0 for 1x gain, 1 for 2x (thus we NOT the variable)
      // bit 12: shutdown bit. 1 for active operation
      // bits 11 through 0: data
      uint16_t out = (chan << 15) | (this->bufferVref << 14) | ((!this->gain2x) << 13) | (1 << 12) | (data << (12 - this->bitwidth));

      // Send the command and data bits
      SPI.transfer((out & 0xff00) >> 8);
      SPI.transfer(out & 0xff);

      // Return chip select to high
      if (this->port_write)
        PORTB |= (1 << 2); // set PORTB pin 2 = arduino pin 10
      else
        digitalWrite(ss_pin, HIGH);
    }

That's quite a lot. All those boolean mathematics operations and decision making slows things down a lot. So does hopping from function to function (yes, the compiler will possibly try and inline some things).

Even the `SPI.transfer()` isn't that efficient with checks and while loops, etc.

To get anywhere near the kind of speed you are looking for you would need to use non-blocking SPI code so you can be transferring a byte out of the SPI port at the same time as getting the next byte ready to send. You don't need to *wait* for the current SPI transfer to finish (as the SPI library does), you just need to be sure that the previous one has finished before you start the next one.


message:
Power ON/OFF a car using Arduino with IR remote control

I'm trying somehow to power OFF the car when the song plays using Arduino using Infrared (IR) Remote.
I decided to play a song (SuperMario) using a Buzzer and when I press the Power ON button works fine and the song plays.

The problem is when I press Power OFF, I have to wait until the song ends to Power off the car.

I was thinking that maybe I need threads or something, but I'm not sure, or maybe there is a better way to fix this.

Here is a Demo program:

    #include "IRremote.h"

    #define NOTE_B0  31
    #define NOTE_C1  33
    #define NOTE_CS1 35
    #define NOTE_D1  37
    #define NOTE_DS1 39
    #define NOTE_E1  41
    #define NOTE_F1  44
    #define NOTE_FS1 46
    #define NOTE_G1  49
    #define NOTE_GS1 52
    #define NOTE_A1  55
    #define NOTE_AS1 58
    #define NOTE_B1  62
    #define NOTE_C2  65
    #define NOTE_CS2 69
    #define NOTE_D2  73
    #define NOTE_DS2 78
    #define NOTE_E2  82
    #define NOTE_F2  87
    #define NOTE_FS2 93
    #define NOTE_G2  98
    #define NOTE_GS2 104
    #define NOTE_A2  110
    #define NOTE_AS2 117
    #define NOTE_B2  123
    #define NOTE_C3  131
    #define NOTE_CS3 139
    #define NOTE_D3  147
    #define NOTE_DS3 156
    #define NOTE_E3  165
    #define NOTE_F3  175
    #define NOTE_FS3 185
    #define NOTE_G3  196
    #define NOTE_GS3 208
    #define NOTE_A3  220
    #define NOTE_AS3 233
    #define NOTE_B3  247
    #define NOTE_C4  262
    #define NOTE_CS4 277
    #define NOTE_D4  294
    #define NOTE_DS4 311
    #define NOTE_E4  330
    #define NOTE_F4  349
    #define NOTE_FS4 370
    #define NOTE_G4  392
    #define NOTE_GS4 415
    #define NOTE_A4  440
    #define NOTE_AS4 466
    #define NOTE_B4  494
    #define NOTE_C5  523
    #define NOTE_CS5 554
    #define NOTE_D5  587
    #define NOTE_DS5 622
    #define NOTE_E5  659
    #define NOTE_F5  698
    #define NOTE_FS5 740
    #define NOTE_G5  784
    #define NOTE_GS5 831
    #define NOTE_A5  880
    #define NOTE_AS5 932
    #define NOTE_B5  988
    #define NOTE_C6  1047
    #define NOTE_CS6 1109
    #define NOTE_D6  1175
    #define NOTE_DS6 1245
    #define NOTE_E6  1319
    #define NOTE_F6  1397
    #define NOTE_FS6 1480
    #define NOTE_G6  1568
    #define NOTE_GS6 1661
    #define NOTE_A6  1760
    #define NOTE_AS6 1865
    #define NOTE_B6  1976
    #define NOTE_C7  2093
    #define NOTE_CS7 2217
    #define NOTE_D7  2349
    #define NOTE_DS7 2489
    #define NOTE_E7  2637
    #define NOTE_F7  2794
    #define NOTE_FS7 2960
    #define NOTE_G7  3136
    #define NOTE_GS7 3322
    #define NOTE_A7  3520
    #define NOTE_AS7 3729
    #define NOTE_B7  3951
    #define NOTE_C8  4186
    #define NOTE_CS8 4435
    #define NOTE_D8  4699
    #define NOTE_DS8 4978

    #define powerLedRed    2
    #define powerLedGreen  3
    #define receiver       5
    #define buzzer         7

    void translateIR( void );
    void powerON( void );;
    void powerOFF( void );
    void swap( int *x, int *y );
    void playSuperMario( void );
    void buzz( int targetPin, long frequency, long length );

    int power           = 2;
    int switchOFF       = 0;
    int switchON        = 1;

    int melody[] = {
      NOTE_E7, NOTE_E7, 0, NOTE_E7,  0, NOTE_C7, NOTE_E7, 0,
      NOTE_G7, 0, 0,  0,  NOTE_G6, 0, 0, 0,
      NOTE_C7, 0, 0, NOTE_G6,  0, 0, NOTE_E6, 0, 0,
      NOTE_A6, 0, NOTE_B6,  0, NOTE_AS6, NOTE_A6, 0,
      NOTE_G6, NOTE_E7, NOTE_G7,  NOTE_A7, 0, NOTE_F7, NOTE_G7, 0,
      NOTE_E7, 0, NOTE_C7,  NOTE_D7, NOTE_B6, 0, 0,
      NOTE_C7, 0, 0, NOTE_G6,  0, 0, NOTE_E6, 0, 0,
      NOTE_A6, 0, NOTE_B6,  0, NOTE_AS6, NOTE_A6, 0,
      NOTE_G6, NOTE_E7, NOTE_G7,  NOTE_A7, 0, NOTE_F7, NOTE_G7, 0,
      NOTE_E7, 0, NOTE_C7,  NOTE_D7, NOTE_B6, 0, 0
    };

    int tempo[] = {
      12, 12, 12, 12,  12, 12, 12, 12,  12, 12, 12, 12,  12, 12, 12, 12,
      12, 12, 12, 12,  12, 12, 12, 12,  12, 12, 12, 12,  12, 12, 12, 12,
      9, 9, 9,  12, 12, 12, 12,  12, 12, 12, 12,  12, 12, 12, 12,
      12, 12, 12, 12,  12, 12, 12, 12,  12, 12, 12, 12,  12, 12, 12, 12,
      9, 9, 9,  12, 12, 12, 12,  12, 12, 12, 12,  12, 12, 12, 12,
    };

    int underworld_melody[] = {
      NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,  NOTE_AS3, NOTE_AS4, 0,  0,
      NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,  NOTE_AS3, NOTE_AS4, 0,  0,
      NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,  NOTE_DS3, NOTE_DS4, 0,  0,
      NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,  NOTE_DS3, NOTE_DS4, 0,  0,
      NOTE_DS4, NOTE_CS4, NOTE_D4, NOTE_CS4, NOTE_DS4, NOTE_DS4, NOTE_GS3,
      NOTE_G3, NOTE_CS4, NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4,
      NOTE_GS4, NOTE_DS4, NOTE_B3, NOTE_AS3, NOTE_A3, NOTE_GS3, 0, 0, 0
    };

    int underworld_tempo[] = {
      12, 12, 12, 12,  12, 12, 6,  3,
      12, 12, 12, 12,  12, 12, 6,  3,
      12, 12, 12, 12,  12, 12, 6,  3,
      12, 12, 12, 12,  12, 12, 6,
      6, 18, 18, 18,  6, 6,  6, 6,  6, 6,
      18, 18, 18, 18, 18, 18,  10, 10, 10,
      10, 10, 10, 3, 3, 3
    };

    IRrecv irrecv(receiver);
    decode_results results;

    void setup( void )
    {
      pinMode(buzzer, OUTPUT);
      pinMode(powerLedGreen, OUTPUT);
      pinMode(powerLedRed,   OUTPUT);
      Serial.begin(9600);
      Serial.println("IR Receiver Button Decode");
      irrecv.enableIRIn();
    }

    void loop( void )
    {
      if ( power == 2 ) {
        powerOFF();
      }

      if (irrecv.decode(&results)) {
        translateIR();
        irrecv.resume();
      }
    }

    void playSuperMario( void ) {
      Serial.println(" 'Mario Theme'");
      int size = sizeof(melody) / sizeof(int);
      for (int thisNote = 0; thisNote < size; thisNote++) {
        int noteDuration = 1000 / tempo[thisNote];
        buzz(buzzer, melody[thisNote], noteDuration);

        int pauseBetweenNotes = noteDuration * 1.30;
        delay(pauseBetweenNotes);

        buzz(buzzer, 0, noteDuration);
      }
    }

    void buzz( int targetPin, long frequency, long length ) {
      digitalWrite(13, HIGH);
      long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
      long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing

      for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
        digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
        delayMicroseconds(delayValue); // wait for the calculated delay value
        digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
        delayMicroseconds(delayValue); // wait again or the calculated delay value
      }

      digitalWrite(13, LOW);
    }

    void translateIR( void ) {
      switch (results.value) {
        case 0xFF02FD:
          Serial.println(" -OK-");

          swap(&switchON, &switchOFF);

          if (switchON == 0 )
          {
            powerON();
            playSuperMario();
          }
          else
          {
            powerOFF();
          }
          break;
        default:
          Serial.println(" other button   ");
          power = 0;
      }
      //delay(500);
    }

    void powerOFF( void ) {
      digitalWrite(powerLedRed,   HIGH);
      digitalWrite(powerLedGreen, LOW);
      power = 0;
    }

    void powerON( void ) {
      digitalWrite(powerLedRed,   LOW);
      digitalWrite(powerLedGreen, HIGH);
    }

    void swap( int *x, int *y ) {
      if (*x != *y) {
        *x ^= *y;
        *y ^= *x;
        *x ^= *y;
      }
    }

inside the `translateIR` function I have this:

    void translateIR( void ) {
      switch (results.value) {
        case 0xFF02FD:
          Serial.println(" -OK-");

          swap(&switchON, &switchOFF);

          if (switchON == 0 )
          {
            powerON();
            playSuperMario();
          }
          else
          {
            powerOFF();
          }
          break;
        default:
          Serial.println(" other button   ");
          power = 0;
      }
      //delay(500);
    }

Here is a [VIDEO Demo](https://youtu.be/DZtzMjYlNBA).
How to fix this?

body:
What you have to is in the for loop within function playSuperMario to check for the Off button. If so, stop the loop.

This is assuming the delay for waiting until the note is finished is ok.\

Maybe a better 'design' is not to use playSuperMario as one function, but within the loop function, to keep a boolean that defines if the song is playing or not. If playing, call a function: playNextNoteOfSuperMario. You also need to keep the index of the next to play note.

Something like:

    bool CurrentlyPlaying = false;

Maybe you can skip this variable CurrentlyPlaying since it is probably the same as (power == 2) ??. 2 means something, so use an enumeration for that.

    void powerOFF( void ) {
      digitalWrite(powerLedRed,   HIGH);
      digitalWrite(powerLedGreen, LOW);
      power = 0;
      CurrentlyPlaying = false;
    }

    void powerON( void ) {
      digitalWrite(powerLedRed,   LOW);
      digitalWrite(powerLedGreen, HIGH);
      I would expect power also to be assigned here.
      CurrentlyPlaying = true;
    }

    int CurrentNote = 0;

Set this variable again to 0 when Power On button pressed

    void loop( void )
    {
      if (songPlaying)
      {
          playNextNoteOfSuperMario();
      }

      if ( power == 2 ) {
        powerOFF();
      }

      if (irrecv.decode(&results)) {
        translateIR();
        irrecv.resume();
      }
    }

    void playNextNoteOfSuperMario( void ) {
      Serial.println(" 'Mario Theme'");
      int size = sizeof(melody) / sizeof(int);

      int noteDuration = 1000 / tempo[CurrentNote];
      buzz(buzzer, melody[CurrentNote], noteDuration);

      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      buzz(buzzer, 0, noteDuration);
    }


body:
There are two ways you can accomplish this. FYI, my buzzer is connected to pin 11 which is a PWM pin on the Arduino UNO.

 1. Get a [DFPlayer mini][1] which can play the song and all you do is press the stop function to stop the music just like in your code. (Recommended)
 2. Use MelodyWithoutDelay(Okay, but it works just as well and is less expensive)

For this answer, I will explain the MelodyWithoutDelay method.

As you have heard before, the delay function is a terrible way to stall the Arduino.  This is because the Arduino can not be aware, or multitask, while it is staring at its own clock.  I dealt with the same issue when I tried to "multitask" my Arduino to play music while receiving commands via Bluetooth.

For this reason, I created code a bit similar to the ToneMelody example given by Arduino.  I called it MelodyWithoutDelay.  It's a pretty swag name :)

Anyway, all you have to do replace my melody[] and noteDuration[] code with your melody[] and tempo[] code. And you have to change lengthOfSong to the number of notes in your melody from start to finish.
You might have to include the pitches.h file from the toneMelody example code given by Arduino.

But the bare meat you should be looking at is the void melodyWithoutDelay().

Instead of creating the code applicable to you, I will create the most basic form, which is the one I show below.  I need to show the MelodyWithoutDelay example to some viewers out there for their own projects too!.

Just marinate your head in the code and it should give you a good understanding on how to attack your mission.

 **If you want to test my code, Upload it and all you have to do is type 'g' in the Serial monitor and you should be able to pause and play the song.**

If you're wondering where I used the code check out my [Instructable][2].

Good Luck!

Here is the code:

        //Invented by Nathan Ramanathan
    #include "pitches.h"  //File with all the music notes in the known universe
    #define buzzer 11

    unsigned long songMillis = 0;
    bool check = false;
    int thisNote = -1;
    // notes in the melody:
    //int melody[] = {
    //  NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5
    //};

    int melody[] = {//The FINAL COUNTDOWN song
      NOTE_B4, NOTE_A4, NOTE_B4, NOTE_E4, 0, NOTE_C5, NOTE_B4, NOTE_C5, NOTE_B4, NOTE_A4, 0, NOTE_C5, NOTE_B4, NOTE_C5, NOTE_E4, NOTE_FS4, 0, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_FS4, NOTE_A4,   NOTE_G4,0,NOTE_B4,NOTE_A4,NOTE_B4,NOTE_E4,0,NOTE_C5,NOTE_B4,NOTE_C5,NOTE_B4,NOTE_A4,0,NOTE_B4,NOTE_A4,NOTE_B4,NOTE_E4,NOTE_FS4,0,NOTE_A4,NOTE_G4,NOTE_A4,NOTE_G4,NOTE_FS4,NOTE_A4,   NOTE_G4,NOTE_FS4,NOTE_G4,NOTE_A4,NOTE_G4,NOTE_A4,NOTE_B4,NOTE_A4,NOTE_G4,NOTE_FS4,NOTE_E4,NOTE_B4,NOTE_C5,NOTE_G4,0,NOTE_B4,NOTE_A4,NOTE_B4,NOTE_E4,0,NOTE_C5,NOTE_B4,NOTE_C5,NOTE_B4,NOTE_A4,    0,NOTE_C5,NOTE_B4,NOTE_C5,NOTE_E4,NOTE_FS4,0,NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_FS4, NOTE_A4,NOTE_G4,0,NOTE_B4,NOTE_A4,NOTE_B4,NOTE_E4,0,NOTE_C5, NOTE_B4, NOTE_C5, NOTE_B4, NOTE_A4,0, NOTE_C5,NOTE_B4,NOTE_C5,NOTE_E4,   NOTE_FS4,0,NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_FS4, NOTE_A4,NOTE_G4
    };

    // note durations: 4 = quarter note, 8 = eighth note, etc.:
    int noteDurations[] = {
      16, 16, 4, 4, 2, 16, 16, 8, 8, 4, 2, 16, 16, 4, 4, 4, 4, 16, 16, 8, 8, 8, 8,  4,8,16,16,4,4,2,16,16,8,8,4,2,16,16,4,4,4,6,16,16,8,8,8,8,  2,16,16,3,16,16,8,8,8,8,4,8,1,4,8,16,16,4,4,2,16,16,8,8,8,  2,16,16,4,4,4,8,16,16,8,8,8,8,4,6,16,16,4,4,2,16,16,8,8,4,2,16,16,4,4,  4,6,16,16,8,8,8,8,4
    };

    const int lengthOfSong = 23+25+25+30+9; //For some reason the millis() doesn't like calculating array size.
    //////////////////////////////////////////////////////////////////////
    void setup() {
      Serial.begin(115200);
      Serial.println("Type 'g' to hear a melody.");
    }

    void loop() {
      // no need to repeat the melody.
      unsigned long currentMillis = millis();
      if (Serial.available()) {
        int c = Serial.read();
        if (c == 'g') {               //type 'g' to start song
          check = !(check);
        }
        if (c == 'h') {               //type 'h' in the serial monitor to confirm that the arduino listens to you while it plays music!
           Serial.println("Hello");
        }
      }
      else {
        if (check) {
          MelodyWithoutDelay(currentMillis);
        }
      }
    }

    void MelodyWithoutDelay(long cMillis) {
      int noteDuration = 1700 / noteDurations[thisNote];
      int pauseBetweenNotes = noteDuration * 1.2;

      if ((cMillis - songMillis <= pauseBetweenNotes / 4)) {
      }
      else if ((cMillis - songMillis <= pauseBetweenNotes)) {
        tone(buzzer, melody[thisNote], noteDuration);
      }
      else {
        if (thisNote >= lengthOfSong) {
          thisNote = -2;
          check = false;
        }
        thisNote++;
        noTone(buzzer);
        songMillis = cMillis;
      }
    }

  [1]: https://youtu.be/UodfePdNfg8
  [2]: https://www.instructables.com/id/The-Multitasking-Final-Countdown-Timer-With-Wirele/


message:
PIR sensor code logic works on Mega but not on Yún

I am trying to use this example(it works on Arduino Mega): `millis() - lowIn` comes greater than `5000`when motion ends.

    /////////////////////////////
    //VARS
    //the time we give the sensor to calibrate (10-60 secs according to the datasheet)
    int calibrationTime = 30;

    //the time when the sensor outputs a low impulse
    long unsigned int lowIn;

    //the amount of milliseconds the sensor has to be low
    //before we assume all motion has stopped
    long unsigned int pause = 5000;

    boolean lockLow = true;
    boolean takeLowTime;

    int pirPin = 3; //the digital pin connected to the PIR sensor's output
    int ledPin = 13;

    /////////////////////////////
    //SETUP
    void setup() {
      Serial.begin(9600);
      pinMode(pirPin, INPUT);
      pinMode(ledPin, OUTPUT);
      digitalWrite(pirPin, LOW);

      //give the sensor some time to calibrate
      Serial.print("calibrating sensor ");
      for (int i = 0; i < calibrationTime; i++) {
        Serial.print(".");
        delay(1000);
      }
      Serial.println(" done");
      Serial.println("SENSOR ACTIVE");
      delay(50);
    }

    ////////////////////////////
    //LOOP
    void loop() {
      if (digitalRead(pirPin) == HIGH) {
        digitalWrite(ledPin, HIGH);
        //the led visualizes the sensor's output pin state
        if (lockLow) {
          // makes sure we wait for a transition to LOW before any further output is made:
          lockLow = false;
          Serial.println("---");
          Serial.print("motion detected at ");
          Serial.print(millis() / 1000);
          Serial.println(" sec");
          delay(50);
        }
        takeLowTime = true;
      }

      if (digitalRead(pirPin) == LOW) {
        digitalWrite(ledPin, LOW);
        //the led visualizes the sensors output pin state
        if (takeLowTime) {
          lowIn = millis();
          //save the time of the transition from high to LOW
          takeLowTime = false;
          //make sure this is only done at the start of a LOW phase
        }
        //if the sensor is low for more than the given pause,
        //we assume that no more motion is going to happen
        Serial.print(millis() - lowIn);
        Serial.print("    ");
        Serial.print(lockLow);
        Serial.print("    ");
        Serial.println(pause);
        if (!lockLow && millis() - lowIn > pause) {
          //makes sure this block of code is only executed again after
          //a new motion sequence has been detected
          lockLow = true;
          Serial.print("motion ended at "); //output
          Serial.print((millis() - pause) / 1000);
          Serial.println(" sec");
          delay(50);
        }
      }
    }

But it doesn't work on a Yún shield mounted on an Arduino Leonardo. The difference of `millis() - lowIn` always comes out to be lower than pause.

body:
The Arduino Leonardo uses the ATmega32U4 microcontroller which uses lower logic levels for the digital inputs. Perhaps that is not compatible with the PIR sensor. You can simulate the PIR sensor with a piece of wire and connect it to 5V or GND.

For the Leonardo, sometimes "SerialUSB" is used instead of "Serial". But if see a message on the serial monitor then "Serial" is okay.

If you can't make it work, then try to reduce the number of variables. In this case, remove the Yun shield and try it with the Leonardo board.

The Arduino Mega 2560 and Arduino Leonardo have both a 8-bit microcontroller and 'millis' works on both in exactly the same way. Therefor 'millis' itself or the variables can't be the problem.


message:
MIDI output circuit behaving incorrectly when not connecting with USB

I recreated this circuit to send MIDI notes to my MIDI-USB adapter to my computer.
[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/XIMi2.png

It works fine when the Arduino is powered via USB. When I power the Arduino Nano with 9v on Vin however, the output is gibberish. It just spams the input monitor on my computer with random midi commands. For testing I used this code:

        #include <MIDI.h>

        MIDI_CREATE_DEFAULT_INSTANCE();

        static const unsigned ledPin = 13;
        bool on = false;
        void setup()
        {
            pinMode(ledPin, OUTPUT);
            MIDI.begin(MIDI_CHANNEL_OFF);
        }

        void loop()
        {
            digitalWrite(ledPin, on);
            on = !on;
            MIDI.sendControlChange(12, 127, 1);
            delay(1000);
        }

The Arduino itself seems to be working fine when powered with 9v (note that I tested with both a wall power supply as well as a 9v battery) as the TX-led still  flashes briefly and the built-in led also toggles nicely.

At first I blamed my power supply and/or my power supply, but both work fine on my MIDI-keyboard so I don't think they are to blame.

Worth mentioning: When the Arduino was powered by Vin, I also as a test plugged in the USB-cable in the Arduino, But only touched the connector on the USB-port on my computer. I then received the correct notes.

Because of this I think it is an issue with the grounding. What am I doing wrong?

EDIT: Thanks for the response guys. I think I diagnosed my problem incorrectly. I'm using a cheap Chinese MIDI-adapter which I pried open, and it lacks an optocoupler. I'm getting a decent MIDI adapter now. Thanks!

body:
If you are connecting multiple devices then they have to share a common ground.

I only know about British mains sockets, they all have an earth pin connecting to a common ground, so usually you are OK.

Plug in transformers 'wall warts' sometimes don't connect to ground, the give away is the plastic pin.  In this case you need to provides a separate earth and connect it to the rest of the equipment.

PCs normally have a good earth and this is passed by the USB to connected devices.  So "the Arduino always works when it is connected to the PC" is usually a good indicator of an earthing issue.

I think your keyboard uses a wall wart and therefore when you remove the USB they both float.  Touching the USB lead to the Arduinos USB socket grounds it all again.

So it looks like you diagnosed the fault correctly :)


message:
Multiple definition of "..." Compiler Error

I am creating a simple library to test how multiple files in an Arduino program works. I have three files. MotorController.ino:

    #include <motor.h>

    void setup() {
       motorInitialize();
    }

    void loop() {

    }

motor.cpp:

    #include "motor.h"

    void motorInitialize() {

      for (int i = 0; i < 4; i++) {
         motorArray[i].writeMicroseconds(2000);
         delay(1500);
         motorArray[i].writeMicroseconds(2000);
         delay(1500);
      }
      delay(1000);

    }

and motor.h:

    #ifndef _motor_h_
    #define _motor_h_

    #include "Arduino.h"
    #include <Servo.h>

    Servo motor1, motor2, motor3, motor4;
    Servo motorArray[4] = {motor1, motor2, motor3, motor4};

    void motorInitialize();
    #endif

When I try to compile the program, I get the error:

    libraries/motorLibrary/motor.cpp.o (symbol from plugin): In function `motor1':
    (.text+0x0): multiple definition of `motor1'
    sketch/test.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
    libraries/motorLibrary/motor.cpp.o (symbol from plugin): In function `motor1':
    (.text+0x0): multiple definition of `motor2'
    sketch/test.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
    libraries/motorLibrary/motor.cpp.o (symbol from plugin): In function `motor1':
    (.text+0x0): multiple definition of `motor3'
    sketch/test.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
    libraries/motorLibrary/motor.cpp.o (symbol from plugin): In function `motor1':
    (.text+0x0): multiple definition of `motor4'
    sketch/test.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
    libraries/motorLibrary/motor.cpp.o (symbol from plugin): In function `motor1':
    (.text+0x0): multiple definition of `motorArray'
    sketch/test.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

I have read similar posts on this issue, but none of the solutions seem to work for me. I've followed the instructions on the Arduino website on how to create a library, and that doesn't seem to resolve this issue.

body:
Although the motor (global) variables are defined in a header files, they are included in both cpp files, thus defined twice.

Make them extern, and than define them in the motor.cpp file.

In motor.h, change

    Servo motor1, motor2, motor3, motor4;
    Servo motorArray[4] = {motor1, motor2, motor3, motor4};

to

    extern Servo motor1, motor2, motor3, motor4;
    extern Servo motorArray[4];

In motor.cpp, add:

    Servo motor1, motor2, motor3, motor4;
    Servo motorArray[4] = {motor1, motor2, motor3, motor4};

As a side note, use consts for values 4 and 2000.


message:
Serial monitor showing extra data

I am trying to communicate NODEMCU and Arduino Uno using Serial Communication (RX,TX) using SoftwareSerial library.

Here is my code

    int count;
    char reqst[] = " ";

    void setup() {

      Serial.begin(115200);
      Serial.println("Ready");

    }

    void loop() {

     while ( Serial.available() > 0 )  {

      char inChar = Serial.read();
      reqst[count] = inChar;
      count++;

         if (inChar == '\n') {

            Serial.print("String: ");
            Serial.println(reqst);
            count = 0;
            delay(1000);

         }

     }

    }

here my output in serial monitor is showing ;

String: aj
779

String: am
779

I have checked that from NODEMCU i am sending correct string but in Arduino Uno
the number "779" is coming from nowhere.

So my problem is i am not be able to execute my function according to the desired string. Can anyone tell why the number is coming below the string ?.

body:
    char reqst[] = " ";

Here you created an array two chars in length. But one of those characters must be used for the null terminator so actually it can only hold a string that's a single character long. If you write past the end of the array that will cause undefined behavior. This is likely to be the cause of the strange results you encountered. You need to size reqst[] large enough to contain any string you may receive, including the null terminator. You should add code to ensure that you never write off the end of the array and that it will always end in a null terminator.

I realize it may only be a simplified minimal example, but in the code you posted there is no need to store the incoming characters. Instead you could just print them as they are received.


message:
Interfacing with SPI

I am attempting to program an Arduino to interface with a DAC, specifically the AD7390 made by Analog Devices.

I have tried using the SPI library as a means of realising the interface but am confused by the PIN layout of the DAC. It provides me with SCK, SDI, CLR and LD pins.

The LD (Load Strobe) PIN is used to transfer buffers from the chip's on-board shift register to its DAC register.

The CLR PIN is used to forcibly clear the DAC register.

The documentation claims that the device is SPI compatible but, using these PINs with the Arduino Mega2560 as a micro-controller, only partially works and I am concerned that the circuit requirements of the SPI library are not being satisfied. In SPI documentation, a SS (slave select) PIN is universally mentioned but is not present with my device.

As I have managed to get the CLR PIN working, consistently and as expected, I wonder if a manual approach - i.e. using shiftIn() instead of the SPI library - is the way to go.

Any suggestions or advice would be appreciated.

body:
The AD7390 data sheet timing diagrams show that /LD is in effect a slave select, but an *active high* one.

Specifically, it says that while /LD is high, each rising clock edge causes "Shift-Register-Data Advanced One-Bit", while when it is low, the shift register data is transferred to the DAC.

So basically you would need to use SPI in a mode where the slave select is controlled by software and asserted with the opposite of the usual polarity, but the actual shifting of the data can be accomplished with the hardware SPI engine.

It does not seem that you are always required to use the /CLR input - if you don't want to use it, wire it high.  Otherwise, you can connect it to a GPIO, take it low, and then raise it so that the rising edge causes an asynchronous clear.


message:
PHP/My SQL Database -> to Arduino Serial Monitor

I'm using this domain http://www.decathlon.commonarchitecture.ca/ to host my phpmyadmin database and php code. I would like to read a specific column of the database in the serial monitor, displaying each number one right after the other. I'm unsure of whether to work with a GSM shield, an Ethernet shield or an Arduino wifi shield. Here is my php code (indents are off I know):

    <?php

     $dbhost = "mysql.commonarchitecture.ca";
     $username = "arduinodb";
     $password = "*******";
     $db = "arduinodb" ;

     mysql_connect("$dbhost" , "$username" , "$password");
      //echo "Connected" ;

     //select db
     mysql_select_db($db);
     //echo "Connected to db" ;

      $sql="SELECT * FROM data";

      $records=mysql_query($sql);

     ?>

     <!DOCTYPE html>

     <title> Consumption Data </title>

     Day
     Date
     Water Consumption (liters per person)

     <?php

     while($data=mysql_fetch_assoc($records)) {

       echo "
";

       echo "".$data['id']."	";

       echo "".$data['date']."	";

       echo "".$data['value']."	";

       echo "
";

      }//end while

      ?>

The code works, however I'm unsure of how to go about reading the data on an Arduino (very new to Arduino)

Here's my Arduino code paired with an ethernet shield

    #include <SPI.h>
    #include <Ethernet.h>

    byte mac[] = {   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

    IPAddress ip(192, 168, *, *);

    EthernetClient client;

    char server[] = "www.decathlon.commonarchitecture.ca";

    void setup()
    {
       Serial.begin(9600);

      // attempt a DHCP connection:
      Serial.println("Attempting to get an IP address using DHCP:");
      if (!Ethernet.begin(mac)) {
      // if DHCP fails, start with a hard-coded address:
      Serial.println("failed to get an IP address using DHCP, trying
      manually");
         Ethernet.begin(mac, ip);
      }

      Serial.print("My address:");
      Serial.println(Ethernet.localIP());
    }

    void loop()
    {
        // connect to the server
        if (client.connect(server, 80))
        {
            // print to serial monitor
            Serial.println("connected...");
            Serial.println("ARDUINO: forming HTTP request message");

            // send data the server through GET request
            client.print("GET /index.php?value");
            client.println(" HTTP/1.1");
            client.print("HOST:  ");
            client.println(server);

            Serial.println("ARDUINO: HTTP message sent");

            // give server time to receive request
            delay(1000);

            // get the response from the page and print it to serial port
            // to ascertain that request was received properly
            if(client.available())
            {
                Serial.println("ARDUINO: HTTP message received");
                Serial.println("ARDUINO: printing received headers and
    script response...\n");

                while(client.available())
                {
                    char c = client.read();
                    Serial.print(c);
                }
            }
            else
            {
                Serial.println("ARDUINO: no response received / no response
    received in time");
            }

            client.stop();
        }
        // do nothing forever after:
        while(true);
    }

My issue now is in getting the Arduino to read my php data, can I not use an http GET request to display data in my serial monitor? Am I using this function properly? There's a ton of documentation on posting Arduino sensor data to the web using php/my sql but not as much on retrieval of set data back into the serial monitor. Here's what the monitor reads currently...

    Attempting to get an IP address using DHCP:
    My address:192.168.*.*
    connected...
    ARDUINO: forming HTTP request message
    ARDUINO: HTTP message sent
    ARDUINO: no response received / no response received in time

body:
Firstly if you really are using an Uno then you cant read the data without putting the uno on a network (obviously).  To do this you could get either a Ethernet shield of a Wifi shield.  A wifi shield is probably based on an ESP8266 and you talk to it by creating a serial connection (using a software serial port).  There are plenty of examples and messages on here to get you started.

Once that's working you need to write a web client (note that this is much easier if you program the ESP8266 rather than the Arduino).  Your client needs to request the page from your server and then parse the returned data and extract the field you want.

While you are waiting for you network shield to arrive you could practice doing it on a Windows PC with Visual Studio, it will be easier to debug.


body:
Any one of a GSM shield, an Ethernet shield or an Arduino wifi shield should be able to pull a web page from a web server and feed it into your Arduino.

I highly recommend buying hardware from people that put lots of example program text on their website, rather than trying to save a few nickles buying "equivalent" hardware from people that don't give any examples, leading to hours of frustration.

Some of the places I've found that have lots of example program text (in no particular order):

* [Arduino Ethernet Shield 2][1]: links to ["Getting Started with the Arduino Ethernet Shield and Ethernet Shield 2"][2] which in turn links to example code "WebClient: make a HTTP request" and "WebClientRepeating: Make repeated HTTP requests."

* [Arduino Ethernet Shield 2][3]: links to [Arduino Ethernet2 Library][4] which in turn links to example code

* [W5500 Ethernet Shield for Arduino v1.0][5]: links to [WIZ5500 based Ethernet Shield library for Arduino][6] which in turn links to example code "WebClient" and "WebClientRepeating"

* [Adafruit FONA 800 Shield - Voice/Data Cellular GSM for Arduino][7]: links to [Datasheets & App notes][8], and the "SIM800 IP App Note" has some brief examples of using HTTP to pull from a web server.

* [SparkFun ESP8266 Thing - Dev Board][9]: links to [ESP8266 Thing Development Board Hookup Guide][10], which has an example that "Read all the lines of the reply from server and print them to Serial". (related: ["Quick Tip: HTTP GET with the ESP8266 Thing"][11] )

If I were you, I would test the hardware with *exactly* the example programs given for that hardware, and resist the urge to "improve" them until after I confirm that the example programs actually do work.
(Perhaps you already did that? If so, please update your question to say the example code seemed to run OK, and exactly which example code you tried, and what minor changes you made that still seemed to run OK, so we can focus on *what changed* between "partially working" vs. "not even that part working").

(I personally find it easier to parse [JSON data][12] sent by a web server set up to send out `"Content-Type: application/json; charset=utf-8"`, or [TOML data][13] sent by a web server as `"Content-Type: text/plain; charset=utf-8"`,
rather than programmatically parse HTML tables sent by a web server set up to send out `"Content-Type: text/html; charset=utf-8"`, but any of these ways should work).

  [1]: https://store.arduino.cc/usa/arduino-ethernet-shield-2
  [2]: https://www.arduino.cc/en/Guide/ArduinoEthernetShield
  [3]: https://www.sparkfun.com/products/11166
  [4]: http://www.arduino.org/learning/reference/ethernet-two-library
  [5]: https://www.adafruit.com/product/2971
  [6]: https://github.com/adafruit/Ethernet2
  [7]: https://www.adafruit.com/product/2468
  [8]: https://learn.adafruit.com/adafruit-fona-800-shield/downloads
  [9]: https://www.sparkfun.com/products/13711
  [10]: https://learn.sparkfun.com/tutorials/esp8266-thing-development-board-hookup-guide/example-sketch-posting-to-phant
  [11]: http://shawnhymel.com/695/quick-tip-http-get-with-the-esp8266-thing/
  [12]: https://en.wikipedia.org/wiki/JSON
  [13]: https://en.wikipedia.org/wiki/TOML


message:
Arduino FIFO queue for with potentiometer values and 7 segment display

As of now I have code that takes a value from a potentiometer and maps it from 0-9. Based on this mapped value a number will be displayed on the seven segment display.

Currently, if I quickly turn the pot completely then back to zero it will show everything very quickly and then show 0 until I change the pot value again. What I am trying to do is make it so if it's quickly turned completely then back to 0, after a second it will display all the number from 0-9 then back down to 0, each for a second.

I was given a hint to use arrays to create a FIFO queue but I am not sure how to go about doing this and I have been stuck on this for a while. Here's my code:

    // Pin 2-8 is connected to the 7 segments of the display.
    // Pin 0 is for potentiometer
    int potval;
    int pinA = 2;
    int pinB = 3;
    int pinC = 4;
    int pinD = 5;
    int pinE = 6;
    int pinF = 7;
    int pinG = 8;
    int i;

    // the setup routine runs once when you press reset:
    void setup() {
      // initialize the digital pins as outputs.
      pinMode(pinA, OUTPUT);
      pinMode(pinB, OUTPUT);
      pinMode(pinC, OUTPUT);
      pinMode(pinD, OUTPUT);
      pinMode(pinE, OUTPUT);
      pinMode(pinF, OUTPUT);
      pinMode(pinG, OUTPUT);
    }

    void loop() {
      potval=map(analogRead(A0),0,921,0,9);
      if (potval==0){
        //0
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, HIGH);
      }
      if (potval==1){
        //1
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
      }
      if (potval==2){
        //2
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, LOW);
      }
      if (potval==3){
        //3
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, LOW);
      }
      if (potval==4){
        //4
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, LOW);
      }
      if (potval==5){
        //5
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, LOW);
      }
      if (potval==6){
        //6
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, LOW);
      }
      if (potval==7){
        //7
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
      }
      if (potval==8){
        //8
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, LOW);
      }
      if (potval==9){
        //9
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, LOW);
      }
    }

body:
Without seeing the code it is bit difficult to help. Please edit your answer and include the relevant parts of the code, otherwise we will end up (re)writing your code for you.

Hint: why not, when you detect a change in the pot, take the new reading, and then count down/up *slowly* (at the rate that you desire) from the currently displayed reading to the new measured reading - using a `for` loop, which contains a `delay()`? With each iteration of the loop you can display the new value. Easy!

### However, this sounds like a terrible idea

Note that your code won't do anything else whilst the display is incrementing and decrementing, using this method. So, if you were to spend a lot of time twiddling with the knob, then the code wouldn't get much time to actually do any real work, apart from displaying the updated value.

In order for your code to do real work, whilst displaying the new updated value, you would either need interrupts, or integrate the display updating procedure into the `loop()`, such that each iteration of the `loop()` updates the display (or upon each *n* iterations of `loop()`, as `loop()` will probably be looping to quickly. You will probably need to use `millis()`).

NOTE: From a UX aspect, although it all sounds very 1960's-James-Bond-evil-guy-equipment, the whole notion of the displayed value slowly following the actual location of the knob sounds, at best, extremely infuriating, if not down right dangerous (depending upon the context). Human feedback should be as fast as possible. Else the user will constantly be turning the knob to reach the value that they which to achieve, when in fact they have already passed that value, and may be over compensating, and it is just the fancy display graphics that is showing the wrong value.

Assuming that the knob is controlling something else (actuator, motor, heater, etc.), and not just a pretty display in itself, *unless*, you are actually outputting the delayed displayed digital value, and not the knob's actual current analogue value, I would seriously recommend against doing this.

I may be wrong, and it would probably require a separate question on [SE.UX][1], although, I would imagine that it has been asked already.

  [1]: https://ux.stackexchange.com/


body:
First of all, that way of writing the displays is quite horrible to me ;) Better to use a matrix (and, please, no ints for small variables like pin numbers, and make them constant). This is the code fixed with these improvements:

    // Pin 2-8 is connected to the 7 segments of the display.
    // Pin 0 is for potentiometer
    int potval;
    const byte pinA = 2;
    const byte pinB = 3;
    const byte pinC = 4;
    const byte pinD = 5;
    const byte pinE = 6;
    const byte pinF = 7;
    const byte pinG = 8;

    byte Matrix[][7] = { { LOW , LOW , LOW , LOW , LOW , LOW , HIGH}, // potval 0
                         { HIGH, LOW , LOW , HIGH, HIGH, HIGH, HIGH}, // potval 1
          ... fill with the other rows ...
          { LOW , LOW , LOW , HIGH, HIGH, LOW , LOW }  // potval 9
                        };

    // the setup routine runs once when you press reset:
    void setup() {
    // initialize the digital pins as outputs.
    pinMode(pinA, OUTPUT);
    pinMode(pinB, OUTPUT);
    pinMode(pinC, OUTPUT);
    pinMode(pinD, OUTPUT);
    pinMode(pinE, OUTPUT);
    pinMode(pinF, OUTPUT);
    pinMode(pinG, OUTPUT);
    }

    void loop() {
     potval=map(analogRead(A0),0,921,0,9);

     digitalWrite(pinA, Matrix[potval][0]);
     digitalWrite(pinB, Matrix[potval][0]);
     digitalWrite(pinC, Matrix[potval][0]);
     digitalWrite(pinD, Matrix[potval][0]);
     digitalWrite(pinE, Matrix[potval][0]);
     digitalWrite(pinF, Matrix[potval][0]);
     digitalWrite(pinG, Matrix[potval][0]);
    }

You can further improve it by not having seven variables but only an array to iterate over, but .. ok, let's keep this.

Ok, now you want to do a "slow movement". In order to do this you can use a variable to track the current position, and let it move towards the target value once every XX ms. This is the approach used, for instance, in CNCs and 3d printers movements.

    // Pin 2-8 is connected to the 7 segments of the display.
    // Pin 0 is for potentiometer
    int potval;
    const byte pinA = 2;
    const byte pinB = 3;
    const byte pinC = 4;
    const byte pinD = 5;
    const byte pinE = 6;
    const byte pinF = 7;
    const byte pinG = 8;

    unsigned long int prevMillis;
    const int delayBetweenMovement = 200;

    byte Matrix[][7] = { { LOW , LOW , LOW , LOW , LOW , LOW , HIGH}, // potval 0
                         { HIGH, LOW , LOW , HIGH, HIGH, HIGH, HIGH}, // potval 1
          ... fill with the other rows ...
          { LOW , LOW , LOW , HIGH, HIGH, LOW , LOW }  // potval 9
                        };

    // the setup routine runs once when you press reset:
    void setup() {
    // initialize the digital pins as outputs.
    pinMode(pinA, OUTPUT);
    pinMode(pinB, OUTPUT);
    pinMode(pinC, OUTPUT);
    pinMode(pinD, OUTPUT);
    pinMode(pinE, OUTPUT);
    pinMode(pinF, OUTPUT);
    pinMode(pinG, OUTPUT);
    prevMillis = millis() - delayBetweenMovement;
    }

    void loop() {
     if ((millis() - prevMillis) >= delayBetweenMovement)
     {
      prevMillis += delayBetweenMovement;

      potval=map(analogRead(A0),0,921,0,9);
      static int CurrentPotVal = potval;

      if (potval > CurrentPotVal)
       CurrentPotVal++;
      if (potval < CurrentPotVal)
       CurrentPotVal--;

      digitalWrite(pinA, Matrix[CurrentPotVal][0]);
      digitalWrite(pinB, Matrix[CurrentPotVal][0]);
      digitalWrite(pinC, Matrix[CurrentPotVal][0]);
      digitalWrite(pinD, Matrix[CurrentPotVal][0]);
      digitalWrite(pinE, Matrix[CurrentPotVal][0]);
      digitalWrite(pinF, Matrix[CurrentPotVal][0]);
      digitalWrite(pinG, Matrix[CurrentPotVal][0]);
     }
    }

The `delayBetweenMovement` constant makes a delay between the readings. With this method, if you quickly turn it to 9 and then to 0 you will not arrive to 9. For instance you put a 9, the display starts doing 0..1..2..3, then you switch to 0 and the count will not reach 9, but start going back to 0. Reaching 9 will require some more structures; if you need it ask and I'll make some modifications

EDIT: as requested, here is a version that can memoryze up to 20 states and reproduce them. If you need them just increase the FIFO size.

Note: I haven't tested these programs. In the other two I was pretty confident I hadn't made any major bug, but this one is a bit more complicated. There can be some bugs left..

    // Pin 2-8 is connected to the 7 segments of the display.
    // Pin 0 is for potentiometer
    const byte pinA = 2;
    const byte pinB = 3;
    const byte pinC = 4;
    const byte pinD = 5;
    const byte pinE = 6;
    const byte pinF = 7;
    const byte pinG = 8;

    unsigned long int prevMillis;
    const int delayBetweenMovement = 200;

    byte Matrix[][7] = { { LOW , LOW , LOW , LOW , LOW , LOW , HIGH}, // potval 0
          { HIGH, LOW , LOW , HIGH, HIGH, HIGH, HIGH}, // potval 1
          ... fill with the other rows ...
          { LOW , LOW , LOW , HIGH, HIGH, LOW , LOW }  // potval 9
         };

    const byte FifoSize = 20;
    byte TargetFifo[FifoSize];
    byte FifoHead = 0, FifoTail = 0;

    byte potval;

    // the setup routine runs once when you press reset:
    void setup() {
     // initialize the digital pins as outputs.
     pinMode(pinA, OUTPUT);
     pinMode(pinB, OUTPUT);
     pinMode(pinC, OUTPUT);
     pinMode(pinD, OUTPUT);
     pinMode(pinE, OUTPUT);
     pinMode(pinF, OUTPUT);
     pinMode(pinG, OUTPUT);
     prevMillis = millis() - delayBetweenMovement;
    }

    byte FifoAvailableForWrite()
    {
     if (FifoTail > FifoHead)
      return (FifoSize - FifoTail + FifoHead);
     else
      return (FifoHead - FifoTail);
    }

    void loop() {
     potval=map(analogRead(A0),0,921,0,9);
     static byte prevPotVal = potval;
     static int CurrentPotVal = potval;

     if ((prevPotVal != potval) && (FifoAvailableForWrite() > 1))
     {
      TargetFifo[FifoTail] = potval;
      prevPotVal = potval;
      FifoTail = (FifoTail + 1) % FifoSize;
     }

     if ((millis() - prevMillis) >= delayBetweenMovement)
     {
      prevMillis += delayBetweenMovement;

      if (FifoHead != FifoTail)
      {
       if (TargetFifo[FifoHead] > CurrentPotVal)
        CurrentPotVal++;
       if (TargetFifo[FifoHead] < CurrentPotVal)
        CurrentPotVal--;
       while (TargetFifo[FifoHead] == CurrentPotVal)
        FifoHead = (FifoHead + 1) % FifoSize;
      }

      digitalWrite(pinA, Matrix[CurrentPotVal][0]);
      digitalWrite(pinB, Matrix[CurrentPotVal][0]);
      digitalWrite(pinC, Matrix[CurrentPotVal][0]);
      digitalWrite(pinD, Matrix[CurrentPotVal][0]);
      digitalWrite(pinE, Matrix[CurrentPotVal][0]);
      digitalWrite(pinF, Matrix[CurrentPotVal][0]);
      digitalWrite(pinG, Matrix[CurrentPotVal][0]);
     }
    }


message:
Error while boot loading Atmega 2560 using Arduino Mega 2560

I have developed custom board using Atmega 2560. I am doing boot loading process using the process of migrate from an Arduino board to a standalone microcontroller.

[![Custom Atmega 2560 Board][1]][1]

I have followed this steps...

1) Upload the ArduinoISP sketch onto your Arduino board.

2) Wire up the Arduino board and microcontroller as connections mentioned on Arduino Site.

3) Select "Arduino/Genuino Mega/ Mega 2560" from the Tools > Board menu.

4) Select "Arduino as ISP" from Tools > Programmer

5) Run Tools > Burn Bootloader

While doing this process I am getting this Error...

> avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.
Error while burning bootloader.

I have done connection like this...

    MISO  -  D50
    MOSI  -  D51
    SCK   -  D52
    Reset -  D53/Reset
    +5V   -  Vcc
    GND   -  GND

What wrong I am doing? Or any step I have missed?

  [1]: https://i.stack.imgur.com/jFykt.jpg

body:
You wired the whole thing backwards. The proper wiring is

    Your board - Arduino
         MISO  -  D50
         MOSI  -  D51
         SCK   -  D52
         Reset -  D53
         Vcc   -  5V
         GND   -  GND

This is kind of obvious from the picture: you would normally use the ISP
connector of the _target_ board.


body:
Same connections worked for me. Just one connection have to change.

    Reset - D10


message:
How do I measure speed and manipulate the speed based on distance covered?

I'm doing a project on arduino. I'm using a online simulator to design the circuit. I have a dc motor. How do we measure the rpm,speed at that rpm,distance covered by the motor in a given time. For example,

When motor starts, it starts rotating slowly and gradually increases it's RPM. When it covered a distance of 50 meters, the motor slows down and stops. After 10 seconds, the motor starts again at that 50 meter point and goes to 100 meters point and stops. Like this it stops for every 50m. For this we need to keep track of the distance travelled by motor and control it's speed.

How do I achieve the above working. I have tried alot and verified many tutorials but couldn't understand what to do. Please help me out.
(The online simulator I'm using has a L293D motor driver, IR sensor and a ultrasonic distance sensor in it's component list.)

body:
They key point here is to know the distance. The simplest way of finding that distance is to know how many times the wheel has completed an entire revolution. Multiply that number of revolutions by the circumference of your wheel and you have the distance the wheel has covered.

Depending on how precisely you want to measure that distance you may get away with a simple magnet and [hall effect sensor](https://en.wikipedia.org/wiki/Hall_effect_sensor). Place the magnet on the wheel, and locate the hall effect sensor so the magnet passes it close enough to trigger. Each pulse from the sensor is one rotation of the wheel.

You could increase the resolution by adding more magnets - 4 magnets set at 90° points around the wheel will give you a pulse for each quarter of a revolution (so multiply pulses by a quarter of your circumference).

If you want better resolution and accuracy you could attach a [rotary encoder](https://en.wikipedia.org/wiki/Rotary_encoder) to the axle of the wheel. This, depending on the encoder, can give you far better resolution than simple magnets. Some will also give you the angle the wheel is at (not that such information would be of interest in this project).


message:
sizeof() on custom library constructor returns wrong result

I made a custom library (let's call it `DigitalOutput.h`) to learn a bit about librairies and to simplify my work. Here is the basic constructor in the _.h_ file:

    DigitalOutput(uint8_t pin);

Here is the code in the _.cpp_ file :

    DigitalOutput::DigitalOutput(uint8_t pin)
    {
     _pin    = pin;
     _status = LOW;
     pinMode(pin, OUTPUT);
    }

So very simple stuff. Now, in my program, I call the function the usual way:

    DigitalOutput LED(7); // pin #7 will be configured
                          // as an output pin to control the LED
Now the issue comes when I create an array and then use the `sizeof()` function.
Here is the code from my program (using an Arduino Mega):

    DigitalOutput  LED_array[] = {22,23,24,25,26,27,28,29,
                                   30,31,32,33,34,35,36,37};
So, the array contains **16** elements. But when I do for instance...

    #define   LED_NUMBER    sizeof(LED_array)
    //...
    void setup(){
        //...
        Serial.println(sizeof(LED_array));
        Serial.println(LE_NUMBER);
    }
...I get **160** as a result in both cases instead of **16**...

So I end up doing a weird `#define LED_NUMBER sizeof(LED_array) / 10` in order to get the proper result which is then used throughout the program. Any idea of why this isn't working right?

body:
You are checking the size of the object (DigitalOutput).
This object contains:

- _pin
- _status

And this probably results in 10 bytes per object, times 16 objects = 160 bytes.

So you are not creating an (unsigned byte) array which is 16 bytes.


body:
It is working perfectly correctly.

`sizeof` doesn't return the number of elements in an array, it returns *the number of bytes the array takes up*. Since each entry in your array is an instance of your DigitalOutput class, the size is the number of elements multiplied by the size of the class - in this case 10 bytes.

To get the number of elements you must divide the number of bytes by the size of one element:

    int numEles = sizeof(LED_array) / sizeof(DigitalOutput);

or

    int numEles = sizeof(LED_array) / sizeof(LED_array[0]);


message:
Using SoftwareSerial library with EnableInterrupt

I'm working on a project that involves both serial communication and GSM transmission.
I'm using the SoftwareSerial library for RS232 communication, and GSM (SMS) transmission:

 - TX and RX for RS232 : Arduino Uno D3 and D4 pins
 - TX and RX for GSM module : Arduino Uno D7 and D8 pins

The project requires also the use of the EnableInterrupt library to enable interrupt in Arduino's analog pins, meaning that I DON'T USE EnableInterrupt for all of the Arduino's digital pins including D3, D4, D7 and D8.

However when running the program that includes the two libraries, this long error message shows up :

    libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':

    (.text+0x0): multiple definition of `__vector_3'

    sketch\sketch_jun14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

    libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':

    (.text+0x0): multiple definition of `__vector_5'

    sketch\sketch_jun14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

    libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':

    (.text+0x0): multiple definition of `__vector_4'

    sketch\sketch_jun14a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

    collect2.exe: error: ld returned 1 exit status

    exit status 1
    Erreur de compilation pour la carte Arduino/Genuino Uno

Clearly, there is a conflict between the two libraries, Is there any solution to remove this conflict and run the two libraries together ?

Thanks in advance !

body:
* SoftwareSerial uses *all* PinChange interrupts.
* EnableInterrupts uses *all* PinChange interrupts.

You can see the conflict.

All you can do is to modify *both* libraries to remove support for the interrupts you don't need it to support - that way you share out the responsibility for handling the different interrupts between the two libraries.