How to weigh it and use Bluetooth to view the output in putty

As a university project, we created a code that tags an nfc card and weighs it, then sends it to Bluetooth without connecting it to a laptop and a port and outputs it to putty. But nothing is output on putty. What's the problem? The red light says Bluetooth connected comes out normally, but the TX RX doesn't light up
Below is the full text of our code.

#include <Wire.h>
#include <Adafruit_PN532.h>
#include "HX711.h"
#include <SoftwareSerial.h>

#define PN532_IRQ   (2)
#define PN532_RESET (3)
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

#define calibration_factor -7050.0
const int DOUT = 4;
const int CLK = 5;
HX711 scale;

SoftwareSerial bluetooth(6, 7); // RX, TX (HC-06 module)

void setup(void) {
  Serial.begin(9600);
  nfc.begin();
  scale.begin(DOUT, CLK);
  scale.set_scale(calibration_factor);
  scale.tare();
  bluetooth.begin(9600);

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (!versiondata) {
    bluetooth.println("Didn't find PN53x board");
  } else {
    bluetooth.print("Found chip PN5");
    bluetooth.println((versiondata >> 24) & 0xFF, HEX);
    bluetooth.print("Firmware ver. ");
    bluetooth.print((versiondata >> 16) & 0xFF, DEC);
    bluetooth.print('.');
    bluetooth.println((versiondata >> 8) & 0xFF, DEC);
  }

  nfc.SAMConfig();

  bluetooth.println("Waiting for an ISO14443A Card ...");
}

void loop(void) {
  bluetooth.println("Found");
  uint8_t success;
  uint8_t uid[] = {0, 0, 0, 0, 0, 0, 0};
  uint8_t uidLength;

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

  if (success) {
    bluetooth.println("Found an ISO14443A card");
    bluetooth.print("UID Length: ");
    bluetooth.print(uidLength, DEC);
    bluetooth.println(" bytes");
    bluetooth.print("UID Value: ");
    for (uint8_t i = 0; i < uidLength; i++) {
      bluetooth.print(uid[i], HEX);
      bluetooth.print(" ");
    }
    bluetooth.println();

    if (uidLength == 4) {
      bluetooth.println("Seems to be a Mifare Classic card (4 byte UID)");
      uint8_t keya[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
    }

    float weight_kg = scale.get_units(1);

    
    bluetooth.print("UID: ");
    for (uint8_t i = 0; i < uidLength; i++) {
      bluetooth.print(uid[i], HEX);
      bluetooth.print(" ");
    }
    bluetooth.print("Weight: ");
    bluetooth.print(weight_kg, 1);
    bluetooth.println(" kg");
  } else {
    bluetooth.println("NFC tag not found.");
  }
}

I think we made a mistake with Arduino's connection somewhere, right? when I compile the code no error occur

1 Like

Hello koreanstudent

Welcome to the worldbest Arduino forum ever.

I assume that you have written the programme by yourself, then it is quite easy to find the error.

There's a trick to figuring out why something isn't working:

Use a logic analyzer to see what happens.
Put Serial.print statements at various places in the code to see the values of variables and determine whether they meet your expectations.

Have a nice day and enjoy coding in C++.

I don't understand that.

You will need to establish a Bluetooth connection to the laptop before any data will pass over the wireless

You haven't actually said what "Bluetooth" you're using.
"HC-06 module" is mentioned in a comment - is that it?

As the HC-06 is just a UART connection, have you tried observing that with a terminal?
ie, is your sketch actually sending anything to the HC-06?
Is it at the correct baud rate, etc?

Have you tested the HC-06 alone?

It looks like the code you've provided is designed to read NFC card information and weigh an object using an HX711 load cell sensor, and then send this data over Bluetooth to a connected device. The issue you're facing seems to be related to the Bluetooth communication not working as expected. Let's go through some troubleshooting steps:

1- Check Bluetooth Connections:

Ensure that your HC-06 Bluetooth module is correctly connected to your Arduino. The connections should be:
HC-06 TX to Arduino RX (Pin 7 in your code)
HC-06 RX to Arduino TX (Pin 6 in your code)
VCC and GND connections are correctly made.
Also, confirm that the Bluetooth module is powered and in pairing mode.

2- Baud Rate Matching:

Make sure that the baud rates of both the Arduino (SoftwareSerial) and the Bluetooth module match. In your code, both are set to 9600, which seems fine.

3- Serial Monitor vs. Putty:

Test your Arduino code by using the Arduino IDE's Serial Monitor before attempting to use PuTTY. This will help you verify that the Arduino is indeed sending data over the Bluetooth module. If you see data in the Serial Monitor, it's more likely to be a PuTTY configuration issue.

4- PuTTY Configuration:

Double-check your PuTTY settings:
Ensure that you've selected the correct COM port for your Bluetooth module.
Make sure the baud rate in PuTTY matches the one in your Arduino code (9600 in your code).
Verify that you are using the "Serial" connection type in PuTTY.

5- Bluetooth Pairing:

Confirm that your computer or receiving device is properly paired with the HC-06 Bluetooth module.

6- TX/RX LED Indicators:

If the TX/RX LEDs on your Arduino are not lighting up at all, it could indicate a hardware issue. Double-check your wiring and connections.

7- Debugging Output:

Add some debugging output to your Arduino code to help diagnose the issue. For example, print messages before and after sending data over Bluetooth. This can help you pinpoint where the problem might be occurring.

Here's an example of how you can add debugging output to your Arduino code:

bluetooth.print("Sending data over Bluetooth... ");
if (bluetooth.println("Test Data")) {
bluetooth.println("Data sent successfully.");
} else {
bluetooth.println("Failed to send data.");
}
By adding these debugging statements, you can check whether the data is being sent successfully over Bluetooth.

can you please clarify the question

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.