Problems with AC CURRENT CLICK From MikroE

Hello,

I encountered issues while using the AC Current Click sensor. I utilized
the sample provided by MikroE but adapted it for Arduino. The problem is
that the sensor does not send any data until I press on the sensor, at
which point it sends some values even when the cable is not connected to
measure the current. Could you provide any information or suggestions to
help resolve this issue?

My code :

#include <SPI.h>

// Définition des broches (à adapter selon votre câblage)
const int CS_PIN = 10; // Chip Select pour le module SPI
const int AN_PIN = A0; // Pin analogique pour la lecture (si nécessaire)

// Paramètres SPI
const int SPI_SPEED = 1000000; // 1 MHz

// Constantes spécifiques à l'application
#define ACCURRENT_ADC_ITERATIONS            10
#define ACCURRENT_ADC_RESOLUTION            0x0FFF
#define ACCURRENT_AC_TO_DC_V_SCALE          1.8f
#define ACCURRENT_SENSOR_RESOLUTION         30.0f
#define ACCURRENT_A_TO_MA_SCALE             1000.0f

void setup() {
  // Initialiser la communication SPI
  Serial.begin(9600);
  SPI.begin();
  SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE0));
  pinMode(CS_PIN, OUTPUT);
  digitalWrite(CS_PIN, HIGH); // Désactiver le CS au démarrage

  // Initialiser les autres broches si nécessaire
  pinMode(AN_PIN, INPUT);
}

void loop() {
  // Exemple de lecture de courant
  float current = accurrent_get_a();
  float current_ma = current * ACCURRENT_A_TO_MA_SCALE;
  
  Serial.print(current);
  Serial.println(" A");
  Serial.print(current_ma);
  Serial.println(" mA");
  
  delay(1000); // Délai entre les lectures, ajustez selon les besoins
}

float accurrent_get_a() {
  uint8_t data_buf[2] = {0};
  float avg = 0;
  uint32_t sum = 0;

  for (uint8_t cnt = 0; cnt < ACCURRENT_ADC_ITERATIONS; cnt++) {
    digitalWrite(CS_PIN, LOW); // Activer le CS
    SPI.transfer(data_buf, 2); // Lire 2 octets
    digitalWrite(CS_PIN, HIGH); // Désactiver le CS
    
    sum += (((uint16_t)data_buf[0] << 8) | data_buf[1]) & ACCURRENT_ADC_RESOLUTION;
  }
  
  avg = (float)(sum / ACCURRENT_ADC_ITERATIONS);
  avg = ((avg / ACCURRENT_ADC_RESOLUTION) / ACCURRENT_AC_TO_DC_V_SCALE) * ACCURRENT_SENSOR_RESOLUTION;
  
  return avg; // Retourne la valeur moyenne ADC
}

Best regards,
Youssef

Please show a schematic of how you have the MikroE module and the Arduino connected together. Also show some good photographs of all relevant connections.

This sounds like bad connections. The photos requested above are important.

Here's a schematic :

Photograph of circuit :

Do you mean the little board or the actual current sensor on the end of the cable?

I suspect the pin thickness on the DuPont cables you're using is on the thin side, causing intermittent contact problems especially on the Arduino side, but possibly also on the breadboard.
image

If you want use that board with the R4 you need to power it with 5V NOT 3.3V.
You need to switch the jumper on the board to 5V.
Operating it at 3.3V and connecting it to the R4 may damage the R4 and/or click board.

I mean when i press on one of the two chips MCPs of the sensor

I have changed the cable but the same result

see post #6

But if you see here the 5V is not soldered :
image

That is what you need to change. Unsolder from 3V3 and solder to 5V

Unfortunately, I don't have a soldering iron at the moment.

Have you soldered tiny surface mount components before?

No i have not soldered any tiny surface mount components before

Then you will find it difficult to do it right and you may wind up damaging the board.

I will give you two choices:

  1. Remove the 3V3 jumper and solder in the 5V.
  2. Connect 5V to the 3.3V input, but it may or may not burn out the board

For nunber 2, according to the schematic of the click board, there is no difference between the 3.3V and 5V connections. However I'm not sure why they provided a jumper. If the schematics are correct it will work with 5V on the 3V3 connection. If the schematics are wrong, it may burn out the board.

It's your choice.

Are you using the current sensor that came with the board or a different one?

Yes, I noticed that they mentioned there's no difference between the two inputs. So, should I connect the 3.3V to the 5V input of the AC Current Click sensor?

I'm using the current sensor that came with the board—the blue one

I did not see that stated anywhere are you sure?
If you are sure, then connect the Arduino 5V to the 3V3 connection.

What i mean by there's no difference that it can work with both 3.3 V and 5 V