Hey folks,
Having some issues with Arduino Uno cooperating with certain sensors.
New to the Arduino stuff. I've started an using an Uno to collect data for a project. I'm having issues using the two sensors, HMC5883L & IR Obstacle Sensor. The issue I'm having is when following setup tutorials and testing the sensors I'll get a connection but for these two sensors, they will output a value and won't change.
The tutorials I'm following are:
For the IR Obstacle Sensor
And
For the Magnetometer
For the IR Sensor:
int LED = 13; // Use the onboard Uno LED
int isObstaclePin = 7; // This is our input pin
int isObstacle = HIGH; // HIGH MEANS NO OBSTACLE
void setup() {
pinMode(LED, OUTPUT);
pinMode(isObstaclePin, INPUT);
Serial.begin(9600);
}
void loop() {
isObstacle = digitalRead(isObstaclePin);
if (isObstacle == LOW)
{
Serial.println("OBSTACLE!!, OBSTACLE!!");
digitalWrite(LED, HIGH);
}
else
{
Serial.println("clear");
digitalWrite(LED, LOW);
}
delay(200);
}
The module is a KY-032:
Wired as directed in the tutorial.
The issue I am having ... the tutorial will output "Path is clear" if there are no obstacles and "Stop something is ahead!!", it will only output on the serial monitor "Path is clear". The potentiometer adjustment appears to have no impact on the reading or detection. Tx LED is flashing as if its reading or communicating. I've tried isolating it from other potentially disruptive light sources. Tried a different USB Cable.
For the magnetometer:
#include <Wire.h> //I2C Arduino Library
#define addr 0x1E //I2C Address for The HMC5883
void setup(){
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(addr); //start talking
Wire.write(0x02); // Set the Register
Wire.write(0x00); // Tell the HMC5883 to Continuously Measure
Wire.endTransmission();
}
void loop(){
int x,y,z; //triple axis data
//Tell the HMC what regist to begin writing data into
Wire.beginTransmission(addr);
Wire.write(0x03); //start with register 3.
Wire.endTransmission();
//Read the data.. 2 bytes for each axis.. 6 total bytes
Wire.requestFrom(addr, 6);
if(6<=Wire.available()){
x = Wire.read()<<8; //MSB x
x |= Wire.read(); //LSB x
z = Wire.read()<<8; //MSB z
z |= Wire.read(); //LSB z
y = Wire.read()<<8; //MSB y
y |= Wire.read(); //LSB y
}
// Show Values
Serial.print("X Value: ");
Serial.println(x);
Serial.print("Y Value: ");
Serial.println(y);
Serial.print("Z Value: ");
Serial.println(z);
Serial.println();
delay(500);
}
The module is a GY-273.
Wired as shown in the tutorial.
Upon setup I have the magnetometer communicating but it just spits out the headings output but, like the IR sensor. It's just got this output:
X Value: -23803
Y Value: 128
Z Value: 773
No movement or magnetic interference will change the values. I've got the libraries included and am using the code within the tutorial for both sensors. Unplugging the input pins for the sensors leaves it just spitting out the same output..
I have tested my board against an RGB LED Module, an ultrasonic sensor (which worked very well) and a microphone that lacked the sensitivity but would register shouting directly into the mic.
Any help or directions would be appreciated..
Cheers

