<?xml version="1.0" encoding="UTF-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <link href="https://funduinoshop.com/en/blog/arduino/?sAtom=1" rel="self" type="application/atom+xml" />
    <author>
        <name>Funduinoshop</name>
    </author>
    <title>Blog / Atom Feed</title>
    <id>https://funduinoshop.com/en/blog/arduino/?sRss=1</id>
    <updated>2026-04-09T12:49:13+02:00</updated>
    
        <entry>
            <title type="text">The MPU-6050 module: Gyroscope and accelerometer</title>
            <id>https://funduinoshop.com/en/blog/arduino/the-mpu-6050-module-gyroscope-and-accelerometer</id>
            <link href="https://funduinoshop.com/en/blog/arduino/the-mpu-6050-module-gyroscope-and-accelerometer"/>
            <summary type="html">
                <![CDATA[
                
                                            There are only a few modules on the market that have triggered such a hype in the last few months as the MPU-6050 module. The two-in-one circuit board combines two popular...
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 There are only a few modules on the market that have generated as much hype in recent months as the MPU-6050 module. The two-in-one board combines two popular sensor features: The module can be used as a gyroscope as well as an accelerometer at the same time.  How so? The sensor includes a 3-axis gyroscope and a 3-axis accelerometer on one and the same chip. This allows&amp;nbsp;to retrieve all (!) sensor values simultaneously. Thus, the hobbyist is always well informed about the current sensor position. This feature is particularly interesting for model building, especially for balancing chassis or drones. can also access external magnetometers or other sensors via an additional master I2C bus, so that these sensor data can also be fully recorded.&amp;nbsp; 
 A quick overview of the sensor data of the MPU-6050 (GY-521): 
 
 Chipset: MPU-6050 (also known as GY-521) 
 Power supply: 3.3 - 5V DC 
 Line of freedom: 6* 
 Interface: I2C 
 Pin spacing: 2.54 mm   
 
 Now we come to the exciting part: the practice. To give you a nice overview of the useful functions of the MPU-6050 module, we have developed an example circuit diagram for you. The MPU-6050 module is read out by a Funduino UNO R3 and the collected data is evaluated.  We are primarily interested in the sensor data of the gyroscope. We want to read out the values of the X-, Y- and Z-axis and determine if a change of the sensor position has taken place. The change of the position should be displayed to us with colored LEDs. 
   
 So far, so good: but how do we implement this? 
 The program code of the MPU-6050 module 
 Now we get down to the nitty-gritty: well, half of it. First we have to download the appropriate library for the MPU6050 module and integrate it into our Arduino IDE. The library is called &quot;&amp;lt;MPU6050_tockn.h&amp;gt;&quot; and can be found and installed directly from the library management of the Arduino IDE. 
 After this first step we start with the actual code. First, we define the LED connections for our LEDs, which will serve us as indicators for the axis position. Then we define two variables for the axis position of each of the three axes.&amp;nbsp; 
 Surely you ask yourself why we need two variables per axis. Since we want to determine whether the position of the respective axis has changed, we must first determine which value the sensor has recorded for the current position. We save this sensor value of the MPU-6050 for a short period of time in the first variable. In the second variable, the value of the axis position is saved again a little later. We can now compare the two recorded measured values with each other. If a deviation of the position by a previously defined minimum value has been detected (in our code example +-3), we can assume that the sensor has changed the position. In this case we switch on the assigned LED.&amp;nbsp; 
 Especially nice: the captured measurement data can be displayed well in the serial plotter of the Arduino IDE.   
  // This sketch compares the angles of the X/Y/Z axes with the previous values. 
 // If they are different by +/-3°, the sketch switches LEDs. (jew.1 for POS or for NEG) 
 // Attention: These are not the absolute values but RELATIVE values compared to the previous measurement 


  #include   &amp;lt;MPU6050_tockn.h&amp;gt;   // include libraries  
  #include   &amp;lt;Wire.h&amp;gt;   // &amp;lt;-  

MPU6050 mpu6050 (Wire ,  0.1 ,  0.1 );  // Attenuate values. The smaller (direction &quot;0&quot;), the more nervous the values- 
                                  // the bigger (direction &quot;1&quot;) the more sluggish the values 

 const   int  ledXpos  =2 ;  //*** 
 const   int  ledXneg  =3 ;  // * 
 const   int  ledYpos  =4 ;  // * define the LED connections 
 const   int  ledYneg  =5 ;  // *
 const   int  ledZpos  =6 ;  // *
 const   int  ledZneg  =7 ;  //*** 

 int  xNowPos;  // variable CURRENT X-Pos 
 int  yNowPos;  // Variable CURRENT Y-Pos 
 int  zNowPos; // Variable CURRENT   Z-Pos 

 int  xPrePos;  // Variable PREVIOUS X-Pos 
 int  yPrePos;  // Variable PREVIOUS Y-Pos 
 int  zPrePos;  // Variable PREVIOUS Z-Pos 

 int  difference =  3 ;

 void    setup() { // Start setup function 
  Serial  .begin  (115200 );  // Open serial transmission (115200Baud) !!! Setup at the monitor as well !!! 
  
  pinMode (ledXpos,  OUTPUT );  //*** 
  pinMode (ledXneg,  OUTPUT );  // * 
  pinMode (ledYpos,  OUTPUT );  // * Set that LED connectors are outputs 
  pinMode (ledYneg,  OUTPUT );  // *
  pinMode (ledZpos,  OUTPUT );  // *
  pinMode (ledZneg,  OUTPUT );  //*** 
  
  Wire  .begin ();  // Start I2C protocol 
  mpu6050 .begin ();  // Start gyro 
  mpu6050.calcGyroOffsets();  // Gyro calculates its offsets !!! Meanwhile leave it quiet !!! 
                                // Use mpu6050.calcGyroOffsets(true) to track it in the serial monitor. 
 delay  (1000 );  // That&#039;s what we&#039;re waiting for ...
}

 void   loop () {  // Start of the loop loop 

  mpu6050.update();  // Create new data set in the gyro 

xNowPos=(mpu6050.getGyroAngleX());  // Request new record from gyro, write to X variable 
yNowPos=(mpu6050.getGyroAngleY());  // Request new data set from gyro, write to Y variable 
zNowPos=(mpu6050.getGyroAngleZ());  // Request new record from gyro, write to Z variable 

 if  (xNowPos &amp;lt; xPrePos-(difference))  // Compare old dataset with new one. Difference &amp;lt; -3 ? 
 {digitalWrite (ledXpos,  LOW );  digitalWrite (ledXneg,  HIGH );}  // Then switch LEDs accordingly 
 else   if  (xNowPos &amp;gt; xVorPos+(difference))  // Compare old data set with new one. Difference &amp;lt; +3 ? 
 {digitalWrite (ledXpos,  HIGH );  digitalWrite (ledXneg,  LOW );}  // Then switch LEDs accordingly 
 else   // Or just turn off all X LEDs ...
 {digitalWrite (ledXpos,  LOW );  digitalWrite (ledXneg,  LOW );}  // Then switch LEDs accordingly

 if  (yNowPos &amp;lt; yPrePos-(difference))  // Compare old data set with new one.   Difference &amp;lt; -3 ? 
 {digitalWrite (ledYpos,  LOW );  digitalWrite (ledYneg,  HIGH );}  // Then switch LEDs accordingly 
 else   if  (yNowPos &amp;gt; yVorPos+(difference))  // Compare old data set with new one. Difference &amp;lt; +3 ? 
 {digitalWrite (ledYpos,  HIGH );  digitalWrite (ledYneg,  LOW );}  // Then switch LEDs accordingly 
 else   // Or just turn off all Y LEDs ...
 {digitalWrite (ledYpos,  LOW );  digitalWrite (ledYneg,  LOW );}  // Then switch LEDs accordingly

 if  (zNowPos &amp;lt; zPrePos-(difference))  // Compare old data set with new one.   Difference &amp;lt; -3 ? 
 {digitalWrite (ledZpos,  LOW );  digitalWrite (ledZneg,  HIGH );}  // Then switch LEDs accordingly 
 else   if  (zNowPos &amp;gt; zPrePos+(difference))  // Compare old data set with new one. Difference &amp;lt; +3 ? 
 {digitalWrite (ledZpos,  HIGH );  digitalWrite (ledZneg,  LOW );}  // Then switch LEDs accordingly 
 else   // Or just turn off all Z LEDs ...
 {digitalWrite (ledZpos,  LOW );  digitalWrite (ledZneg,  LOW );}  // Then switch LEDs accordingly

xVorPos=xJetztPos;  // Update the (so far) old data set 
yVorPos=yJetztPos;  // Update the (so far) old data set 
zVorPos=zJetztPos;  // Update the (previously) old record 
                                     // Then, in the next run, it can be compared against &quot;before&quot; again 

 Serial  .print (xNowPos);  // &amp;gt;&amp;gt; serial plotter&amp;lt;&amp;lt; fair notation [output X] 
 Serial  .print ( &quot; &quot; ) ;Serial . print (yNowPos);  // (&quot; &quot;) = (\t) = New color [output Y] 
 Serial  . print( &quot; &quot; ) ;Serial . println (zNowPos);  // (&quot; &quot;) = (\t) = New color [output   Z] 
  delay  (15 );  // (minimal delay calms down the serial output) 
}  // end of loop 


 // Feel free to experiment a bit with the damping in the third program line 
 //-&amp;gt; MPU6050 mpu6050(Wire, 0.3, 0.3); 
 // or with the delay() at the end. Afterwards observe the values in the &amp;gt;&amp;gt;serial PLOTTER &amp;lt;&amp;lt;  
                ]]>
            </content>

                            <updated>2022-05-15T08:00:00+02:00</updated>
                    </entry>

    
    
        <entry>
            <title type="text">The PN532 NFC RFID Module - Near Field Communication</title>
            <id>https://funduinoshop.com/en/blog/arduino/the-pn532-nfc-rfid-module-near-field-communication</id>
            <link href="https://funduinoshop.com/en/blog/arduino/the-pn532-nfc-rfid-module-near-field-communication"/>
            <summary type="html">
                <![CDATA[
                
                                            In this article we would like to show you how to read ID tags. The focus of the article is the PN532 NFC RFID module. The module is based on the NXP PN532 chip. This chipset is mainly used in the field of NFC (Near Field Communication)....
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 RFID? NFC? What is it? 
 In this article we would like to show you how to read ID tags. The focus of the article is the PN532 NFC RFID module.&amp;nbsp; 
 The module is based on the NXP PN532 chip. This chipset is widely used in the field of NFC (Near Field Communication). An NFC-enabled object, often a check card with an NFC chip, is held up to an NFC reader. This allows information to be exchanged in a fraction of a second.&amp;nbsp; 
 Does that sound abstract? If you have a newer EC card and use it for contactless payment, then you know NFC even from everyday life. By placing the card on the card terminal, the transaction is initiated - quickly and easily. 
 We would like to take a closer look at the technical processes behind this. The PN532 module is ideally suited for this purpose, as it is both I2C and SPI capable. The desired type of communication can be selected directly on the board of the PN532 by flipping the switches on it. The required switch position of the respective interfaces very you to the right of the circuit diagram, which is located a little further down the page. 
 &amp;nbsp; 
 The schematic: 
   
 Tip: A high resolution version of this picture can be found  here . There you can see the pinout a bit better.   
 The program code (I2C version) 
  //******************************************************************************************************* 
 //** Example sketch for reading ID tags. With matching ID PIN 13 is switched on for 2 seconds ** 
 //** is switched on (LED). If ID is wrong, a tone is generated at pin 12. (PASSIVE buzzer / piezzo) ** 
 //** use. Instead of an LED, a door lock can also be switched (via TIP120 switching amplifier ** 
 //******************************************************************************************************* 

  #include   &amp;lt;Wire.h&amp;gt;   // Library for I2C protocol  
  #include   &amp;lt;Adafruit_PN532.h&amp;gt;   // Library for the NFC/RFID module !  !! Please load by Arduino IDE !!!  


  #define  PN532_IRQ (2)  // Define the IRQ port  
  #define  PN532_RESET (3)  // Define the Reset connector  

 const   int  AlarmPin =  12 ;  // Pin 12 output for piezo speaker 
 const   int  OutputPin =  13 ;  // Pin 13 output for LED or via TIP120 to a magnetic lock 
 unsigned   long  cardid;  // Variable for the read TAG ID 

 unsigned   long  TAGid1 =  1702536620 ;  // IDs to be accepted can be entered here 
 unsigned   long  TAGid2 =  4070796058 ;  // Otherwise leave blank. The ID of single TAGs can be specified with 
 unsigned   long  TAGid3 ;  // the serial monitor (set 115200 baud) 

Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);  // Create instance with I2C protocol 


 void    setup() { // start setup function 
  pinMode (AlarmPin,  OUTPUT );  // define PIN as output 
   pinMode (OutputPin,  OUTPUT );  // Define PIN as output 
  Serial  .begin  (115200 );  // Open serial transmission with 115200 baud (ser monitor same baud setting!) 
  Serial  .println ( &quot;Hello!&quot; );  // Send text &quot;Hello!&quot; to serial monitor 
  nfc .begin ();  // Start communication with RFID reader 
  unsigned   long  versiondata = nfc.getFirmwareVersion();  // Read version number of firmware 
  if  (! versiondata) {  // If no response is received 
    Serial  .print ( &quot;Can&#039;t find board ! &quot;);  // Send text &quot;Can&#039;t find...&quot; to serial monitor 
    while  (1 );  // so long stop 
  }

  Serial  .print ( &quot;Chip PN5 found&quot; );  Serial  .println ((versiondata &amp;gt;&amp;gt;  24 ) &amp;amp;  0xFF , HEX);  // Send text and version info to serial monitor
  Serial  .print ( &quot;Firmware ver. &quot; );  Serial . print ((versiondata &amp;gt;&amp;gt;  16 ) &amp;amp;  0xFF , DEC);  // Monitor if response from board is received 
  Serial  .print ( &#039;.&#039; );  Serial . println ((versiondata &amp;gt;&amp;gt;  8 ) &amp;amp;  0xFF , DEC);  //  
  
  nfc.SAMConfig();  // Configure board to read RFID tags 

  Serial  .println ( &quot;Waiting for an ISO14443A chip . ..&quot;);  // Send text that waiting to serial monitor 
}


 void   loop () {  // Start loop function 
  uint8_t success;  // Create variable 
  uint8_t uid[] = {  0 ,  0 , 0, 0,  0  };  // Buffer to store the UID 
  uint8_t uidLength;  // Length of the UID (4 or 7 bytes depending on ISO14443A card/chip type) 

  // Wait for an ISO14443A chip. If one is detected, the variable 
  // will be filled with the UID. Depending on the length (4 bytes (Mifare Classic) or 
  // 7 bytes (Mifare Ultralight) the card type is detected. 
  
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &amp;amp;uidLength);

  if  (success) {  // If detected, work off ....
    Serial  .println ( &quot;Found an ISO14443A card&quot; );
    Serial  .print ( &quot; UID Length: &quot; );  Serial . print (uidLength, DEC);  Serial . println ( &quot; bytes&quot; );
    Serial  .print ( &quot; UID Value: &quot; );
    nfc.PrintHex(uid, uidLength);  // print information to serial monitor 

    if  (uidLength ==  4 ) {  // If the card/chip has 4 byte length ....
                                                           // Mifare Classic card 
      cardid = uid [0 ];  // 
      cardid &amp;lt;&amp;lt;=  8 ;  // Set the 4 byte blocks 
      cardid |= uid [1 ];  // 
      cardid &amp;lt;&amp;lt;=  8 ;  // to a single block 
      cardid |= uid [2 ];  // 
      cardid &amp;lt;&amp;lt;=  8 ;  // together 
      cardid |= uid [3 ];  // 
      Serial  .print ( &quot;Appears to be a Mifare Classic #&quot; );  // 
      Serial  .println (cardid);  // Output the information 
      Serial  .println ( &quot;&quot; );  //  
      Serial  .println ( &quot;&quot; );  //  
    }
      if  ((cardid) == (TAGid1)||(cardid) == (TAGid2)||(cardid) == (TAGid3))  // Query whether the TAGs 1..2..3 with the respective 
 {digitalWrite (OutputPin ,HIGH );  // matches. Then switch depending on the 
 delay  (2000 );
 digitalWrite (OutputPin ,LOW );}  // on or off 
 else 
 {tone (AlarmPin,  1000 );  // And output a tone/frequency if necessary 
 delay  (4000 );
 noTone (AlarmPin);}
    }  // End of IF query/loop 
}  // End of the loop  
 The program code (SPI version) 
  //******************************************************************************************************* 
 //** Example sketch for reading ID tags. If the ID matches, PIN 13 will be ** for 2 seconds 
 //** is switched on (LED). If ID is wrong, a tone is generated at pin 12. (PASSIVE buzzer / piezzo) ** 
 //** use. Instead of an LED, a door lock can also be switched (via TIP120 switching amplifier ** 
 //******************************************************************************************************* 

  #include   &amp;lt;Wire.h&amp;gt;   // library for I2C protocol  
  #include   &amp;lt;SPI.h&amp;gt;   // Library for SPI protocol  
  #include   &amp;lt;Adafruit_PN532.h&amp;gt;   // Library for the NFC/RFID module !!! Please load by Arduino IDE !!!  

 const   byte  PN532_SCK =  2 ;  // 
 const   byte  PN532_MOSI  =3 ;  // Define the connections for  
 const   byte  PN532_SS =  4 ;  // the SPI connection to the RFID  
 const   byte  PN532_MISO  =5 ;  // board 

 const   int  AlarmPin =  12 ;  // define  the connections for 
 const   int  OutputPin =  13 ;  // the (switching) outputs 
 unsigned   long  cardid;  // variable for the read TAG-ID 

 unsigned   long  TAGid1 =  1702536620 ;  // IDs to be accepted can be entered here 
 unsigned   long  TAGid2 =  4070796058 ;  // Otherwise leave blank. The ID of single TAGs can be specified with 
 unsigned   long  TAGid3 ;  // the serial monitor (set 115200 baud) 

Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);  // Create instance with SPI protocol 

 void    setup() { // Start setup function 
  pinMode (AlarmPin,  OUTPUT );  // Define PIN as output 
   pinMode (OutputPin,  OUTPUT );  // Define PIN as output 
  Serial  .begin  (115200 );  // Open serial transmission with 115200 baud (ser monitor same baud setting!) 
  Serial  .println ( &quot;Hello!&quot; );  // Send text &quot;Hello!&quot; to serial monitor 
  nfc .begin ();  // Start communication with RFID reader 
  unsigned   long  versiondata = nfc.getFirmwareVersion();  // Read version number of firmware 
  if  (! versiondata) {  // If no response is received 
    Serial  .print ( &quot;Can&#039;t find board ! &quot;);  // Send text &quot;Can&#039;t find...&quot; to serial monitor 
    while  (1 );  // so long stop 
  }

  Serial  .print ( &quot;Found chip PN5&quot; );  Serial  .println ((versiondata &amp;gt;&amp;gt;  24 ) &amp;amp;  0xFF , HEX);  // Send text and version info to serial monitor
  Serial  .print ( &quot;Firmware ver. &quot; );  Serial . print ((versiondata &amp;gt;&amp;gt;  16 ) &amp;amp;  0xFF , DEC);  // Monitor when response comes from board 
  Serial  .print ( &#039;.&#039; );  Serial . println ((versiondata &amp;gt;&amp;gt;  8 ) &amp;amp;  0xFF , DEC);  //  

  nfc.SAMConfig();  // Configure board to read RFID tags 

  Serial  .println ( &quot;Waiting for an ISO14443A chip . ..&quot;);  // Send text that waiting to serial monitor 
}


 void   loop () {  // Start loop function 
  uint8_t success;  // Create variable 
  uint8_t uid[] = {  0 ,  0 , 0, 0,  0  };  // Buffer to store the UID 
  uint8_t uidLength;  // Length of the UID (4 or 7 bytes depending on ISO14443A card/chip type) 

  // Wait for an ISO14443A chip. If one is detected, the variable 
  // will be filled with the UID. Depending on the length (4 bytes (Mifare Classic) or 
  // 7 bytes (Mifare Ultralight) the card type is detected. 
 
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &amp;amp;uidLength);

  if  (success) {  // If detected, work off ....
    Serial  .println ( &quot;Found an ISO14443A card&quot; );
    Serial  .print ( &quot; UID Length: &quot; );  Serial . print (uidLength, DEC);  Serial . println ( &quot; bytes&quot; );
    Serial  .print ( &quot; UID Value: &quot; );
    nfc.PrintHex(uid, uidLength);  // print information to serial monitor 

    if  (uidLength ==  4 ) {  // If the card/chip has 4 byte length ....
                                                           // Mifare Classic card 
      cardid = uid [0 ];  // 
      cardid &amp;lt;&amp;lt;=  8 ;  // Set the 4 byte blocks 
      cardid |= uid [1 ];  // 
      cardid &amp;lt;&amp;lt;=  8 ;  // to a single block 
      cardid |= uid [2 ];  // 
      cardid &amp;lt;&amp;lt;=  8 ;  // together 
      cardid |= uid [3 ];  // 
      Serial  .print ( &quot;Appears to be a Mifare Classic #&quot; );  // 
      Serial  .println (cardid);  // Output the information 
      Serial  .println ( &quot;&quot; );  //  
      Serial  .println ( &quot;&quot; );  //  
    }
      if  ((cardid) == (TAGid1)||(cardid) == (TAGid2)||(cardid) == (TAGid3))  // Query whether the TAGs 1..2..3 with the respective 
 {digitalWrite (OutputPin ,HIGH );  // matches. Then switch depending on the 
 delay  (2000 );
 digitalWrite (OutputPin ,LOW );}  // on or off 
 else 
 {tone (AlarmPin,  1000 );  // And output a tone/frequency if necessary 
 delay  (4000 );
 noTone (AlarmPin);}
    }  // End of IF query/loop 
}  // End of loop  
 &amp;nbsp; 
                ]]>
            </content>

                            <updated>2022-05-10T11:30:00+02:00</updated>
                    </entry>

    
</feed>
