RFID and Arduino (1)

In this tutorial, divided in two posts, I’ll show you how to use RFID (Radio-frequency Identification) tags with Arduino.

In the first part you’ll learn how to connect the reader to your Arduino and how to write a simple sketch to display the tag’s ID, while in the second part you’ll learn how to build a complete access control system based on RFID tags.

PN532

I chose as RFID reader a board based on the PN532 chip by NXP. This is a very versatile chip: it can work as a tag reader/writer but it can also act as a RFID tag; moreover it supports both I2C and SPI communication buses.

Adafruit created a breakout board for the PN532 chip and the Arduino libraries we’re going to use. Alternatively you can find on several webstores the following board, that I’m also going to use for this tutorial:

rfid-03 rfid-04

Connections

As I wrote before, the PN532 chip supports both I2C and SPI. For simplicity, I’ll use the first one, connecting the SDA and SCL pins of the board to the corresponding pins of Arduino. You have also to connect the IRQ pin to a digital pin of your Arduino (I chose pin 2); thanks to this connection the PN532 pin “warns” Arduino if a new tag is being read:

rfid-06 rfid-07

To select the I2C bus, you have to set the board’s dip switches as explained on the silk screen:

rfid-05

Finally, power the board connecting the VCC and GND pins to pins 5V and GND of Arduino.

For this project, I used the beta version of a new LCD shield by Lemontech. The main feature of this shield is that the LCD is connected to Arduino via an I2C expander; moreover all the buttons are connected to only one pin, the analog pin A0. This means that almost all the Arduino pins are still available for connecing other devices. The display’s default address – but you can change it – is 0x27 while the PN532 chip has address 0x24 so there’s no conflict.

rfid-10 rfid-11jpg

Having two devices connected to the I2C bus, I had to add two 10Kohm pull-up resistors for SCL and SDA as explained in the following schematics:

rfid-13

To keep things simple, I place them on a small breadboard:

rfid-08

I also added a small speaker (connected to pin 8 and GND) to play a sound everytime Arduino reads a tag:

rfid-09

Libraries

To be able to compile the sketch of this tutorial you have to install the following libraries in your IDE:

  • Adafruit PN532 di Adafruit
  • hd44780 di Bill Perry

Both the libraries are available in the Library Manager:

rfid-01

Sketch

The complete sketch is available in my Github repository.

To use the LCD, first you have to define its size (rows and columns), the address on the I2C bus and the pins it’s connected to. You can then initialize the library in the setup():

#define LCD_COLS      16
#define LCD_ROWS      2
hd44780_I2Cexp lcd(0x27, I2Cexp_PCF8574, 0,1,2,4,5,6,7,3,HIGH);
[...]
if(lcd.begin(LCD_COLS, LCD_ROWS) != 0) {
  Serial.println("- Unable to initialize LCD!");
  while(1);
}

The same for the PN532 chip: you have to declare the pin connected to the IRQ signal (RESET is optional) and then initialize it. Using the getFirmwareVersion method you can get the chip version and therefore verify that it’s working correctly:

#define PN532_IRQ     2
#define PN532_RESET   3
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
[...]
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if(!versiondata) {
  Serial.println("- Unable to find a PN532 board");
  while(1);
}
Serial.print("- found chip PN5"); 
Serial.println((versiondata>>24) & 0xFF, HEX);

Lastly, call the SAMConfig() method to configure the chip in normal mode and to enable the IRQ pin:

rfid-02

It’s very easy to read a tag. The readPassiveTargetID method returns true if a tag is near the reader:

success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {

In this case, you can play a sound and display the tag’s ID on the display:

tone(SPEAKER_PIN, TONE_FREQ, TONE_TIME);
lcd.clear();
lcd.print("Found RFID tag!");
lcd.setCursor(1,2);
lcd.print("ID: 0x");
for(int i = 0; i < uidLength; i++) {
  if(uid[i] <= 0xF) lcd.print("0");
  lcd.print(uid[i] & 0xFF, HEX);    
}

Demo

FPVising a Eachine H8 mini

The Eachine H8 mini quadcopter (here on Banggood) is without dubt one of the most popular quadcopters, both for its low price (10-15€) and for its good performance in terms of speed and flight time.

This quadcopter does not include a camera and therefore it cannot be used to flight in FPV (First Person View) mode… in this post I’m going to show you how to modify it to add this feature with few euros (or dollars ;) )!

There are other interesting mods for this quadcopter, for example silver13 developed some opensource alternative firmwares (acro and dual-mode) while goebish decoded its communication protocol and it’s now possible to control the miniquad with other transmitters.

Shopping list

To modify your H8 mini you will need:

In addition you can buy a dedicated antenna, but you can also replace it with just some wire.

h8fpv-01

Smoke test

Before working on the miniquad, let’s perform a smoke test on all the components to verify if they work individually.

Let’s start with the camera and the transmitter: solder the camera’s yellow wire to the VIN (Video IN) pin of the transmitter and the black wire to GND (ground). Now solder a piece of wire to the ANT (antenna) pin of the transmitter and, using a 5v external power supply, power both the camera and the transmitter:

h8fpv-02 h8fpv-03

Using a 5.8GHz receiver you can verify that they work fine:

h8fpv-04 h8fpv-05

Now test the step-up regulator. Connect a 1 cell LiPo to pins  + and – and verify with a multimeter that the output of the regulator is near to 5V (voltage required to power the other components):

h8fpv-06 h8fpv-07

Quadcopter

Once verified that all the components are working, you can start modifying the quadcopter.

With a screwdriver remove the 4 screws to open the plastic case and remove the printer circuit board:

h8fpv-08 h8fpv-09

Identify the two pads connected to the battery and solder two wires; you’ll use them to power the new components:

h8fpv-10 h8fpv-11

Connect the outputs of the step-up converter to pins GND and VCC of the transmitter, then solder the two wires to its input pins. I also added a small switch to be able to turn the FPV system on/off independently:

h8fpv-12 h8fpv-13

With some hot glue stick the converter and the transmitter to the bottom of the quadcopter and the camera on the front of it. Connect the camera to the transmitter as already explained during the smoke test and solder the antenna. If you chose to use a wire as antenna, you can add a small plastic tube to keep it in vertical position:

h8fpv-14 h8fpv-15

Your H8 mini is now ready for its first FPV flight!

h8fpv-16 h8fpv-17

Updated CH340G board

Some weeks ago I blogged about my project of a minimal board based on the CH340G chip.

After some tests, I slightly modified the project:

  • I added two leds that blink when data are transmitted/received
  • I added a jumper that allows to decide if you want power supply (5V) in the connector or not
  • added a 10nF capacitor to make the circuit more stable.

Eagle files in my Github repository have been updated.

Here are some photos of the new PCB (the purple color should tell you that it was manufactured by OshPark):

ch340g-10

The new board with all the components and a comparison with the first version:

ch340g-11

ch340g-12

 

CH340G board

On this site I’ve already posted about the CH340G chip, manufactured by a chinese company and often adopted as a cheap solution when a USB -> serial converter is needed.

As the chip package (SOP16) is quite easy to solder, I ordered some ICs from AliExpress and I designed a minimal demoboard, based on the reference schematics:

ch340g-00

You can download Eagle files (both schematics and board) in my Github repository.

I used Seeedstudio’s FusionPCB service to manufacture the PCBs (if you want to learn how to use it for your PCBs you can follow my tutorial) and hare are some photos of the first prototype:

ch340g-01

ch340g-02

To verify if it works, you can connect the TX and RX pins with a jumper;  if you open a serial terminal, you should see each character you type:

ch340g-03

In the end, here’s the link to the WCH official website where you can download the drivers.

Nixie thermometer – Completed!

The design and development of this project is described in ten blog posts: for the chronological list follow this link

Today I received from Elecrow the PCB for my Nixie thermometer:

nixie-39

Here are two photos of the top and bottom sides:

nixie-40 nixie-41

First, I soldered the female connectors for the Arduino and the power supply module on the bottom side; then I soldered the sockets, the resistors and the 5V voltage regulator on the top side:

nixie-42 nixie-43

Before going further, I performed a smoke test: it’s indeed very important to check that the power supply is correct measuring with a multimeter the voltage that is present in different points (sockets, leds…) of your circuit. The test was ok, so I put in place the nixie with the symbol °C and verified that it lighted up (that nixie is directly connected to the power supply):

nixie-44 nixie-45

At least, I soldered the led modules, inserted the drivers in their sockets and put the other nixie tubes in pace: the project was completed!

nixie-46 nixie-47

nixie-48 nixie-49

nixie-50 nixie-51

Gallery

Here are some shots of the nixies with different led colors and a short video about the project:

nixie-60 nixie-61

nixie-62 nixie-63

nixie-64 nixie-65

Mistakes

When I was assembling the first PCB, I noticed two mistakes:

  • the silk screen of the power connector is wrong: the + mark is near the negative pin
  • the distance between the nixie tubes is not enough: the PCBs overlap

nixie-52 nixie-53

I’ve already updated the Eagle files in my Github repository

Nixie thermometer – Completed!

The design and development of this project is described in ten blog posts: for the chronological list follow this link

Today I received from Elecrow the PCB for my Nixie thermometer:

nixie-39

Here are two photos of the top and bottom sides:

nixie-40 nixie-41

First, I soldered the female connectors for the Arduino and the power supply module on the bottom side; then I soldered the sockets, the resistors and the 5V voltage regulator on the top side:

nixie-42 nixie-43

Before going further, I performed a smoke test: it’s indeed very important to check that the power supply is correct measuring with a multimeter the voltage that is present in different points (sockets, leds…) of your circuit. The test was ok, so I put in place the nixie with the symbol °C and verified that it lighted up (that nixie is directly connected to the power supply):

nixie-44 nixie-45

At least, I soldered the led modules, inserted the drivers in their sockets and put the other nixie tubes in pace: the project was completed!

nixie-46 nixie-47

nixie-48 nixie-49

nixie-50 nixie-51

Gallery

Here are some shots of the nixies with different led colors and a short video about the project:

nixie-60 nixie-61

nixie-62 nixie-63

nixie-64 nixie-65

Mistakes

When I was assembling the first PCB, I noticed two mistakes:

  • the silk screen of the power connector is wrong: the + mark is near the negative pin
  • the distance between the nixie tubes is not enough: the PCBs overlap

nixie-52 nixie-53

I’ve already updated the Eagle files in my Github repository

Nixie thermometer – PCB

The design and development of this project is described in ten blog posts: for the chronological list follow this link

After having verified that everthing is ok (electronic prototype and sketch) it’s now time to develop the PCB for my Nixie thermometer.

I opened Eagle and drew the schematics:

nixie-36

I then started to design the PCB. The request was that it should have been round and as small as possible. Therefore I decided to place the components on both sides, with the biggest modules (the power supply and the Arduino pro Micro) on the bottom one.

The result is as follows:

nixie-top nixie-routed

It’s very important during this phase to verify that everything is properly connected: it’s indeed better to spend a couple of minutes now, than receive a wrong PCB from the service two-three weeks later. For this reason, I printed the drawings (top and bottom layers) at double size and I checked – with the help of a marking pen – all the connections comparing them with my perfboard prototype:

nixie-37 nixie-38

Once verified that everything was ok, I prepared the Gerber files and sent them to my service (for this project I chose Elecrow).

In my repository on Github you can download the Eagle files and also a ZIP archive that includes all the required Gerber files, ready to be uploaded on the service’s website.

 

Nixie thermometer – PCB

After having verified that everthing is ok (electronic prototype and sketch) it’s now time to develop the PCB for my Nixie thermometer.

I opened Eagle and drew the schematics:

nixie-36

I then started to design the PCB. The request was that it should have been round and as small as possible. Therefore I decided to place the components on both sides, with the biggest modules (the power supply and the Arduino pro Micro) on the bottom one.

The result is as follows:

nixie-top nixie-routed

It’s very important during this phase to verify that everything is properly connected: it’s indeed better to spend a couple of minutes now, than receive a wrong PCB from the service two-three weeks later. For this reason, I printed the drawings (top and bottom layers) at double size and I checked – with the help of a marking pen – all the connections comparing them with my perfboard prototype:

nixie-37 nixie-38

Once verified that everything was ok, I prepared the Gerber files and sent them to my service (for this project I chose Elecrow).

In my repository on Github you can download the Eagle files and also a ZIP archive that includes all the required Gerber files, ready to be uploaded on the service’s website.

 

Nixie thermometer – the prototype is complete!

The design and development of this project is described in ten blog posts: for the chronological list follow this link

Today I completed the prototype of my Nixie thermometer.

First, I put some heat-shrink tubing around each RGB led, to be sure that the light is emitted only upward and that the tubes are illuminated through the holes in the PCBs:

nixie-33

Then I wrote a sketch that includes all the previous examples, including the cycling (everytime you press the button) of the leds’ colors. You can download the final sketch from my Github’s repository.

Here are some shots and a video about how it works…

nixie-34 nixie-35

Nixie thermometer – the prototype is complete!

Today I completed the prototype of my Nixie thermometer.

First, I put some heat-shrink tubing around each RGB led, to be sure that the light is emitted only upward and that the tubes are illuminated through the holes in the PCBs:

nixie-33

Then I wrote a sketch that includes all the previous examples, including the cycling (everytime you press the button) of the leds’ colors. You can download the final sketch from my Github’s repository.

Here are some shots and a video about how it works…

nixie-34 nixie-35