10 Replies Latest reply on Nov 13, 2019 2:29 PM by clem57

    Arduino Uno Rev 3 + MIT App Inventor + Bluetooth Module HC05 + Door Magnetic Switch

    kikovader

      Hello, so this is my first time learning on how to use a Microcontroller like Arduino Uno and currently, I am planning to do on some mini project which uses these items below:

      1. Arduino Uno Rev 3

      2. Bluetooth Module HC-05

      3. An App to receive the data which I created using MIT App Inventor

      4. Door Magnetic Switch.

       

       

      To be very honest I do not know where to start but I have already designed the User Interface of the Application without the Programming Block. I want it to work in away, when the Door Magnetic Switch formed closed circuit, it will send 1 or "ON" in the App through the Arduino Uno. However, when the Door Magnetic Switch formed an open circuit, it will send "0" of "OFF" in the App.

       

      Is this possible?

      Please help me. I am begging you. Please


        • Re: Arduino Uno Rev 3 + MIT App Inventor + Bluetooth Module HC05 + Door Magnetic Switch
          dougw

          The state can be changed in the UNO firmware or the App Inventor software with one or two lines of code or it can be changed in the hardware at the switch by altering how the magnetic switch is connected. Which method would you prefer?

            • Re: Arduino Uno Rev 3 + MIT App Inventor + Bluetooth Module HC05 + Door Magnetic Switch
              kikovader

              I am planning go display change of state in the MIT App Inventor Application which I built. In a way that, I want to use this App to monitor whether the door is close or open.

              I am just confused whether my codes in the Adruino IDE is correct and at the same I am also doubting my programming block in MIT App Inventor.

              Do you think it is possible to do this Sir?

              1 of 1 people found this helpful
                • Re: Arduino Uno Rev 3 + MIT App Inventor + Bluetooth Module HC05 + Door Magnetic Switch
                  dougw

                  I expect if you post your code here, the members will provide advice.

                    • Re: Arduino Uno Rev 3 + MIT App Inventor + Bluetooth Module HC05 + Door Magnetic Switch
                      kikovader

                      Hi Sir, I am sorry for the delay in replying to your help. But here is the code:

                       

                       

                       

                      //Define the pins being used.

                      //Connect the Door Magnetic Switch or Sensor to pin 4.

                      int ledOpen=2;

                      int ledClose=3;

                      int switchReed=4;

                       

                       

                      //When the Door Magnetic Switch formed Closed Circuit = 1

                      //When the Door Magnetic Swich formed Open Circuit = 0

                       

                       

                      void setup()

                      {

                        //Initialize serial communication with Bluetooth Module HC-05

                       

                        Serial.begin(9600); //Serial.begin is used to set the speed of communication in bits per second. By default it is 9600. In short, changing the number will change the speed of transferring data.

                        //Set the speed of transferring data to default speed.

                       

                       

                        pinMode(ledOpen, OUTPUT);

                        pinMode(ledClose, OUTPUT);

                        pinMode(switchReed, INPUT);

                       

                       

                      }

                       

                       

                      void loop()

                      {

                       

                       

                        if (digitalRead(switchReed)==HIGH)

                          {

                            digitalWrite(ledOPen, LOW);

                            digitalWrite(ledClose, HIGH);

                            Serial.print("detected");

                          }

                        else

                          {

                            digitalWrite(ledOpen, HIGH);

                            digitalWrite(ledClose, LOW);

                            Serial.print(notDetected");

                          }

                          delay(100);

                      }

                      1 of 1 people found this helpful
                        • Re: Arduino Uno Rev 3 + MIT App Inventor + Bluetooth Module HC05 + Door Magnetic Switch
                          Jan Cumps
                          digitalWrite(ledOPen, LOW);

                           

                          You need to fix a typo in this line. Lower case P

                           

                           

                          Serial.print(notDetected");

                           

                           

                          Opening quotes missing.

                           

                           

                          You could take care to only communicate if the status of the reedswitch changed between digital reads.

                          3 of 3 people found this helpful
                          • Re: Arduino Uno Rev 3 + MIT App Inventor + Bluetooth Module HC05 + Door Magnetic Switch
                            kikovader

                            Besides that, here is the User Interface for the App that I built.

                            When the magnetic door switch formed a closed circuit, 1. I want "Status 2" of "Flex Stro 1" to display "Unavailable"

                            When the magnetic door switch formed an open circuit, 0. I want "Status 1" of "Flex Stro 1" to display "Available"

                             

                             

                            I am just unsure whether I have done it correctly and I have not tried this whole thing yet. But there is something inside me which tells me that it is wrong so yea.

                            It would be nice if someone can help me out

                            1 of 1 people found this helpful
                              • Re: Arduino Uno Rev 3 + MIT App Inventor + Bluetooth Module HC05 + Door Magnetic Switch
                                neilk

                                Looking at your Arduino code, I can see that you are intending to connect the HC-05 Bluetooth module directly to the hardware Rx and Tx of the Arduino. Whilst this will work, it can be unreliable. It's much more reliable to use another pair of digital pins to communicate with your Bluetooth device. Have a look here at my blog:

                                 

                                https://www.element14.com/community/people/neilk/blog/2018/02/14/mit-appinventor-and-arduino-much-improved-method-of-sending-data-from-arduino-and-receiving-on-android-device

                                 

                                I have used HC-06, but it will also work with HC-05 - HC-06 is a slave only device. HC-05 can be programmed as a master or slave device. I think you could actually use HC-06 in your application.

                                 

                                Your MIT AppInventor blocks don't include all that I have found necessary to connect to a Bluetooth device and don't contain any blocks to disconnect from the Bluetooth device.

                                 

                                I always use a connection structure similar to this:

                                 

                                 

                                And I also include a disconnection block:

                                 

                                 

                                The rest of your blocks look OK, superficially, but I would always develop something as complex as this in small steps, testing each step as I go along. If you take this approach, you will be able to debug your project as you go along.

                                 

                                Hope this helps

                                 

                                Neil

                                2 of 2 people found this helpful
                                  • Re: Arduino Uno Rev 3 + MIT App Inventor + Bluetooth Module HC05 + Door Magnetic Switch
                                    kikovader

                                    Hi Neil,

                                     

                                    I am sorry if I took too long to reply to you but I have been trying to understand what are the differences if I connect my HC-05 to RX TX directly and what if I did not connect it directly.

                                     

                                    I tried to follow my original plan which is connecting the HC-05 to RX TX of the Arduino Directly, however faced some issues.

                                     

                                    I tried to use the MIT App Inventor Emulator to do the try out. At first it shows this:

                                     

                                    When Bluetooth button was picked, the next screen shows nothing, basically it is just black and I do not know how this happen It does not even display the list of Bluetooth Connections available for me to connect. I did not download the App to my phone because I am using iOS L:(

                                     

                                    .

                                     

                                     

                                    In terms of programming block, here is my programming block which I have modified according to your suggestion which is really makes sense:

                                     

                                     

                                    And the programming code for the Arduino is below:

                                    //Define the pins being used.

                                    //Connect the Door Magnetic Switch or Sensor to pin 4.

                                    int ledOpen=2;

                                    int ledClose=3;

                                    int switchReed=4;

                                     

                                    //When the Door Magnetic Switch formed Closed Circuit = 1

                                    //When the Door Magnetic Swich formed Open Circuit = 0

                                     

                                    void setup()

                                    {

                                      //Initialize serial communication with Bluetooth Module HC-05

                                     

                                      Serial.begin(9600); //Serial.begin is used to set the speed of communication in bits per second. By default it is 9600. In short, changing the number will change the speed of transferring data.

                                      //Set the speed of transferring data to default speed.

                                     

                                     

                                      pinMode(ledOpen, OUTPUT);

                                      pinMode(ledClose, OUTPUT);

                                      pinMode(switchReed, INPUT);

                                     

                                     

                                    }

                                     

                                     

                                    void loop()

                                    {

                                     

                                     

                                      if (digitalRead(switchReed)==HIGH)

                                        {

                                          digitalWrite(ledOpen, LOW);

                                          digitalWrite(ledClose, HIGH);

                                          Serial.print("detected");

                                        }

                                      else

                                        {

                                          digitalWrite(ledOpen, HIGH);

                                          digitalWrite(ledClose, LOW);

                                          Serial.print("notDetected");

                                        }

                                        delay(100);

                                    }

                                     

                                    Could you help me to solve this issue Please

                                    1 of 1 people found this helpful
                                      • Re: Arduino Uno Rev 3 + MIT App Inventor + Bluetooth Module HC05 + Door Magnetic Switch
                                        neilk

                                        Hi Kim

                                         

                                        Your set up is so complex (relatively speaking) that we cannot see the wood for the trees.

                                         

                                        Using the emulator doesn't help matters! It's much easier and more reliable to use the MIT AI2 Companion App on an Android device.

                                         

                                        I'm a bit confused as to your motivations in this project - using AppInventor when you don't have an Android device on which to run the App??

                                         

                                        So, why connecting the HC-05 directly to the Uno Rx and Tx, is unreliable:

                                         

                                        Firstly, the presence of the HC-05 across the Rx/Tx lines sometimes, but not always, stops a new sketch from being uploaded the the Uno. To rectify this it is necessary to disconnect the HC-05 from the Uno Rx/Tx

                                         

                                        Secondly,  the presence of the HC-05 across the Rx/Tx lines sometimes, but not always, stops the HC-05 from accepting a connection request on the Bluetooth side. To rectify this it is necessary to reset the HC-05, by disconnecting the +5V supply.

                                         

                                        So back to the project:

                                         

                                        You need to simplify your system so that it can be shown to work step by step. I suggest you do this by reproducing the stages in my blog which I referenced in my previous reply.

                                         

                                        If you cannot reproduce the steps in my Blog, then we need to delve deeper, and you will need to provide a schematic of the Uno and HC-05 connections.

                                         

                                        Until you can demonstrate that you can communicate with the Uno/HC-05 system, using something like Blueterm, there is little point in worrying about the detail of the AppInventor design and blocks.

                                         

                                        Hope this helps

                                         

                                        Neil

                                        2 of 2 people found this helpful
                          • Re: Arduino Uno Rev 3 + MIT App Inventor + Bluetooth Module HC05 + Door Magnetic Switch
                            clem57

                            Nice project overall. I suggest to break the project into smaller pieces to have the least amount of troubles.