Where is the Problem in this code?

I am a beginner with Arduino, and I need help with it.

I have a MAX11612-MAX11617 12-bit converter connected to a Hall sensor using two capacitors and a resistor. The converter's VDD is connected to the Arduino's VDD,
GND -->> GND,
SDA -->> A4,
and SCL -->> A5.

AIN11 of the converter is connected to a resistor and capacitor to GND, and AIN3 is connected to a Hall sensor. "

I have written the code, but it is not working, and the monitor only shows negative values without moving a magnet nearby. What could be the problem, in the code or in the connection?"

this is the code :

#include <Wire.h>

const byte CHIP_ADDRESS = 0x33;
const byte HALL_SENSOR_REGISTER = 0x03;

void setup() {
Serial.begin(9600);
Wire.begin();
}

void loop() {

Wire.beginTransmission(CHIP_ADDRESS);
Wire.write(HALL_SENSOR_REGISTER);
Wire.endTransmission();

Wire.requestFrom(ADC_ADDR, 2);

int sensorValue = Wire.read() << 8 | Wire.read();

float voltage = (sensorValue * 5.0) / 4096.0;
Serial.print("spannung: ");
Serial.print(voltage);
Serial.println(" V");

delay(2000);
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the CODE icon above the compose window) to make it easier to read and copy for examination

1 Like

// Wandler-für-hallsensor.ino
// https://forum.arduino.cc/t/where-is-the-problem-in-this-code/1103225

/*
I have a MAX11612-MAX11617 12-bit converter connected to a Hall sensor using two 
capacitors and a resistor. The converter's VDD is connected to the Arduino's VDD

GND -->> GND
SDA -->> A4
SCL -->> A5

AIN11 of the converter is connected to a resistor and capacitor to GND, 
and AIN3 is connected to a Hall sensor. 

            *---------------------+
  REF/AIN11 | 1    MAX11614    16 | VDD
      AIN10 | 2    MAX11617    15 | GND
      AIN09 | 3                14 | SDA
      AIN08 | 4                13 | SCL
      AIN00 | 5                12 | AIN07
      AIN01 | 6                11 | AIN06
      AIN02 | 7                10 | AIN05
      AIN03 | 8                 9 | AIN04
            +---------------------+

|  Message (Enter to send message to Arduino Uno on COM6
|  Spannung: -4.20 V
|  Spannung: -4.19 V
|  Spannung: -4.19 V
*/

#include <Wire.h>

const byte CHIP_ADDRESS = 0x33;
const byte HALL_SENSOR_REGISTER = 0x03;

void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop() 
{
  Wire.beginTransmission (CHIP_ADDRESS);
  Wire.write(HALL_SENSOR_REGISTER);
  Wire.endTransmission();

  Wire.requestFrom(CHIP_ADDRESS, 2);
  int sensorValue = Wire.read() << 8 Wire.read();

  // Berechnen der Spannung
  float voltage = sensorValue(5.0 / 4096.0);

  Serial.print("Spannung: ");
  Serial.print(voltage, 2);
  Serial.println("V");
  delay(4000);
}

@SemperIdem - okay (strike(d)through)

...and when OCR gets it wrong, it's worse than useless.

Let's wait for the actual code.

Please post a schematic. Verbal descriptions are too error prone.

Please post a photo of a hand drawn schematic diagram, with pins and connections clearly labeled. Also post links to the sensor and ADC data sheets.

The datasheet says

Data Byte (Read Cycle)
...
The result is transmitted in two bytes; first four bits of the first byte are high, then MSB through LSB are consecutively clocked out.

So perhaps you could post your code, as most others are able to do, without resorting to photos? Please read:

thank u for ur answer

this ist the code :

#include <Wire.h>

const byte CHIP_ADDRESS = 0x33;
const byte HALL_SENSOR_REGISTER = 0x03;

void setup() {
Serial.begin(9600);
Wire.begin();
}

void loop() {

Wire.beginTransmission(CHIP_ADDRESS);
Wire.write(HALL_SENSOR_REGISTER);
Wire.endTransmission();

Wire.requestFrom(ADC_ADDR, 2);

int sensorValue = Wire.read() << 8 | Wire.read();

float voltage = (sensorValue * 5.0) / 4096.0;
Serial.print("spannung: ");
Serial.print(voltage);
Serial.println(" V");

delay(2000);
}

thank u for ur Answer

page 22
https://www.analog.com/media/en/technical-documentation/data-sheets/max11612-max11617.pdf

Perhaps you intended to do this:

#include <Wire.h>

const byte CHIP_ADDRESS = 0x33;
const byte HALL_SENSOR_REGISTER = 0x03;

void setup() {
  Serial.begin(9600);
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(CHIP_ADDRESS);
  Wire.write(HALL_SENSOR_REGISTER);
  Wire.endTransmission();
  Wire.requestFrom(ADC_ADDR, 2);
  int sensorValue = Wire.read() << 8 | Wire.read();
  float voltage = (sensorValue * 5.0) / 4096.0;
  Serial.print("spannung: ");
  Serial.print(voltage);
  Serial.println(" V");
  delay(2000);
}

As others have pointed out, the high nibble of the first byte is all high, so you have to fix that.
I'd suggest looking at bit functions, such as bit-and and bit-or, to find your answer... doing one of those will allow you to suppress the high four bits(nibble) of the first byte received.
Hint. This line:

int sensorValue = Wire.read() << 8 | Wire.read();

was a good start, just not complete.

1 Like

You came here for help, right? So, ignoring the helpers will make you no friends.
Fix your code. If the hint wasn't enough, ask questions.

I asked for a schematic. Sorry, but that is not a schematic. It's a data sheet that's been scribbled on. It shows nothing of the Hall effect sensor or Arduino wiring. There are no values attached to the components, one of them is a "mystery part", I assume it's a resistor. Really, you have to make more effort.

By PM I was informed he'd not be testing anything as it's the weekend. When he returns to the office he'll be back.
...

"office"?
So this is commercial?

Since he's deleting his own replies, I think I will save myself some stress and add to my ignore list.

3 Likes

Huh, we already told you that if you want to obtain help you MUST alway USE CODE TAGS when posting your code! You keep ignoring that, so we'll ignore you in the future.

1 Like

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