Introduction: Arduino - NRF24L01 - TFT - Parts Counting Unit.

In this project, we will learn how to make a counting parts unit can be used in industry for counting parts or anything else you want to used for.

For this propose we will make two units : transmitter and receiver units.

In the transmitter units we will use the IR sensor for counting the parts, after we attend the number we need to switch on the lamp using a relay module and send information to receiver unit (administration) using two NRF24L01 modules and we get alarme by message on TFT module and by singing a very famous theme : Game of Thrones.

So let's go on to the work.

Step 1: Parts Required

1- Transmitter unit you will need for :

Arduino Uno.

NRF24L01.

Relay Module (I used my home-made double Relay Module).

Lamp.

IR Sensor.

2- Reciver unit you will need for :

Arduino Uno.

NRF24L01.

TFT module for Arduino.

Speaker.

And also batteries,wires,tiny breadboard.

Step 2: Testing Parts : NRF24L01 (features)

Now after we collect the materials that you need for this project let's move on to test our components before you plug in all together.

First of all let's start with some characteristics of the NRF24L01 module:

-The NRF24L01 transceiver module, uses the 2.4 GHz band and it can operate with baud rates from 250 kbps up to 2 Mbps. If used in open space and with lower baud rate its range can reach up to 100 meters (10m inside a building).

-The module can use 125 different channels which gives a possibility to have a network of 125 independently working modems in one place. Each channel can have up to 6 addresses, or each unit can communicate with up to 6 other units at the same time.

-The chip needs a supply current of about 11mA , The operating voltage of the module is from 1.9 to 3.6V.

-Three of these pins are for the SPI communication and they need to be connected to the SPI pins of the Arduino, The pins CSN and CE can be connected to any digital pin of the Arduino board.

Now lets' move on to implementing with the Arduino.

Step 3: Testing Parts : NRF24L01 (Implementing)

-We start by "Hello World" example.

-So once we connect the NRF24L01 modules to the Arduino boards (see picture 1) , Or you can also (see Table 1) we are ready to make the codes for both the transmitter and the receiver.

- First we need to download and install the RF24 library to run this code (see below).

- Note: as mentioned early , the NRF24L01 needs the SPI protocol to communicate with the Arduino, the Arduino’s SPI implementation uses four signal wires (plus ground). These are listed in (Table 2), together with the pin connections conventionally used on the Uno.

Transmitter Code:

#include  <SPI.h>
#include  <nRF24L01.h>
#include  <RF24.h>
RF24 radio(8, 10); // CE, CSN
const byte address[6] = "00001";
void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}
void loop() {
  const char text[ ] = "Hello World"; // change it as you wish 
  radio.write(&text, sizeof(text));
  delay(1000);
}

Receiver Code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(8, 10); // CE, CSN
const byte address[6] = "00001";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}
void loop() {
  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }
}

If everything is all right let's move on to test the TFT Screen.

Step 4: Testing Parts :TFT Display(features)

First of all let's start with some characteristics of the TFT Screen:

-The Arduino TFT screen is a backlit TFT LCD screen with a micro SD card slot in the back. You can draw text, images, and shapes to the screen with the TFT library.

-By default, the screen is oriented so it is wider than it is tall. The top of the screen is the same side as the text 'SD CARD''. In this orientation, the screen is 160 pixels wide and 128 pixels high.

-The TFT library is included with Arduino IDE 1.0.5 or later by default.

-If you plan on using the SD card on the TFT module, you must use hardware SPI, so we don't need it because we just wants to print a simple message to indicate that our unit complete its work.

-If you want more information about the TFT Screen you can visit The Arduino Official Site.

Step 5: Testing Parts :TFT Display (Implementing)

In this implementing part we will learn how to writes text in the TFT Screen the message will be "Still Working" that we needed it for the next of our project.

-Connecting to the Arduino Uno(see picture1).

TFT simple message code:

#include   <TFT.h>// Arduino LCD library
#include  <SPI.h>
// pin definition for the Uno
#define cs   5
#define dc   6
#define rst  7
// pin definition for the Leonardo
// #define cs   7
// #define dc   0
// #define rst  1
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
// char array to print to the screen
char MSG_Printout[7];
void setup() {
  TFTscreen.begin();  // Put this line at the beginning of every sketch that uses the GLCD:
  TFTscreen.background(0, 0, 0);  // clear the screen with a black background
  TFTscreen.stroke(255, 231, 44);   // set the font color to white
  TFTscreen.setTextSize(2);     //TFTscreen.setTextSize(2);
}
void loop() {
  // write the text and update it every 2s
   TFTscreen.text(" Still\n ", 40, 20);
   TFTscreen.text(" Working\n ", 30, 40);
   TFTscreen.setTextSize(1);
   TFTscreen.stroke(255, 0, 0);
   TFTscreen.text("--> Please Wait --<\n ", 20, 80);
<p>delay(2000);</p>  }
<br>

If everything is all right let's move on to the next step.

Step 6: Breadboard Layout: Transmitter Unit

In this section we will put together the breadboard for the Transmitter unit.

for the transmitter unit I will add :

IR sensor ( for counting) .

Relay (to control the lamp).

Lamp( to indicate if the number of the parts is reached (I programmed 12 of course you can change it as you like).

I will add the fritizing file (see below).

Step 7: Arduino Code : Transmitter

-So once we connect all the components as shown in the previous step, we are ready to make the code for the finale transmitter.

Final Transmitter Code:

#include <SPI.h>
#include  <nRF24L01.h>
#include  <RF24.h>
RF24 radio(8, 10); // CE, CSN
const byte address[6] = "00001";
byte k = 0;
int myIR = A0;
byte N_pieces = 12; // nomber of pieces to count change it as you like
byte myLamp = 2;</p><p>void setup() {
  pinMode (myIR,INPUT); 
  pinMode(myLamp,OUTPUT);
  digitalWrite(myLamp,LOW);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
  Serial.begin(9600);
}
void loop() {
  const char text[] = "yes"; 
    if (analogRead(A0) <= 500) { 
    k=k+1;
    Serial.println(k);
    delay(1000);
  }
  if(k >= N_pieces) {
  digitalWrite(myLamp,HIGH);
  radio.write(&text, sizeof(text));
  delay(250);
  }
}

Step 8: Breadboard Layout: Receiver Unit

In this section we will put together the breadboard for the Receiver unit.
For the receiver unit I will add :

- Enceinte (Headspeaker buzzer).

Notice: - I will use the ICSP(In Circuit Serial Programing) pins to connect TFT and NRF24L01 in the Arduino.

-The speaker will sing the famous theme of the Game Of Thrones TV series.

I will add the fritizing file (see below).

Step 9: Arduino Code : Receiver

-So once we connect all the components as shown in the previous step, we are ready to make the code for the finale receiver.

First download the sketch of the GOT (Game Of Thrones) theme see below, and then put it the same folder as the Final Receiver code.

Final Receiver Code:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include  <TFT.h>
#define cs   5
#define dc   6
#define rst  7
TFT TFTscreen = TFT(cs, dc, rst);
RF24 radio(8, 10); // CE, CSN
const byte address[6] = "00001";
char MSG_Printout[7];
// Buzzer
int speakerPin = 2;
void startTFT () { 
  TFTscreen.begin();
  TFTscreen.background(0, 0, 0);
}
void setup() {
  pinMode(speakerPin, OUTPUT);
  startTFT () ;
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}
void loop() {
  if (radio.available()) {
    char text[] = "";
    char text2[] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
    {
    String MSG = "Finish";
  MSG.toCharArray(MSG_Printout, 7);
  TFTscreen.background(0, 0, 0);
  TFTscreen.setTextSize(2);
  TFTscreen.stroke(255, 231, 44);
  TFTscreen.text(MSG_Printout, 50, 50);
  delay(250);
  TFTscreen.stroke(0, 0, 0);
  TFTscreen.text(MSG_Printout, 0, 20);
  GameOfThrones(); // GOT theme.
}
   else  {
   TFTscreen.background(0, 0, 0);
   TFTscreen.stroke(255, 231, 44);
   TFTscreen.setTextSize(2);
   TFTscreen.text(" Still\n ", 40, 20);
   TFTscreen.text(" Working\n ", 30, 40);
   TFTscreen.setTextSize(1);
   TFTscreen.stroke(255, 0, 0);
   TFTscreen.text("--> Please Wait --<\n ", 20, 80);
  }
  delay(2000);
}

Step 10: Functionality and Conclusion

Now, after everything is alright we move to test our project see the video.

If you have any question of course you can contact me at : ahmnouira@gmail.com , Or leave a comment.
myYoutube.

myFacebook.

myTwitte.

Thanks for reading this instructable ^^ and have a nice day.

See ya.

Ahmed Nouira.