zain90
March 17, 2023, 12:15pm
1
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);
}
zain90:
this is the code :
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
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
1 Like
xfpd
March 17, 2023, 5:28pm
3
// 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.
So perhaps you could post your code, as most others are able to do, without resorting to photos? Please read:
Welcome to the Arduino forum!
A guide explaining how to get the best out of this forum is available at the link below. Please read it:
zain90
March 18, 2023, 1:20pm
11
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);
}
zain90
March 18, 2023, 1:22pm
12
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
docdoc
March 20, 2023, 4:25pm
21
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
system
Closed
September 16, 2023, 4:26pm
22
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.