The reading for 2 sensors does not show up in serial monitor

: I have 2 sensors
Sharp optical dust sensor and gy-906 contactless temperature sensor.
I wrote their programs in 1 file and when I use the serial monitor, the values do not show up until I disconnect the analog read pin A5 which I used for the dust sensor.
The temperature sensor is connected to SCL,SDA, 5v and ground.
The circuit for the dust sensor is as shown

I tried to to test each one of them Individually and they work just fine.

The program for both sensors in 1 file :

//gy-906
#include <Wire.h>
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

//Dust sensor
int measurePin = A5;
int ledPower = 12;

unsigned int samplingTime = 280;
unsigned int deltaTime = 40;
unsigned int sleepTime = 9680;

float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;

void setup(){
  
  //gy-906
  Serial.begin(9600);
  Serial.println("Adafruit MLX90614 test");  
  mlx.begin(); 
  
  
  //Dust sensor
  pinMode(ledPower,OUTPUT);


}

void loop(){
  
  //gy-906
  
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF()); 
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");

  Serial.println();
  
  delay(500); 

  //optical dust sensor
  digitalWrite(ledPower,LOW);
  delayMicroseconds(samplingTime);

  voMeasured = analogRead(measurePin);

  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH);
  delayMicroseconds(sleepTime);

  calcVoltage = voMeasured*(5.0/1024);
    dustDensity = 0.17*calcVoltage-0.1; 
    
  if ( dustDensity < 0)
  {
    dustDensity = 0.00;
  }
  Serial.println("Raw Signal Value (0-1023):");
  Serial.println(voMeasured);

  Serial.println("Voltage:");
  Serial.println(calcVoltage);

  Serial.println("Dust Density:");
  Serial.println(dustDensity); 

  
  delay(500);
  

}

Your topic was MOVED to its current forum category as it is more suitable than the original

A4 and A5 are used for I2C on an Uno.

Try using A0, or A1, or A2, or A3.

1 Like

A5 is the SCL pin

Could this explain your problem ?

Thanks man
but can you explain it more for me because I am new to arduino and I have been trying to solve this problem for hours!

I changed it from A5 to A0 and it worked.
but actually I did not understand what was the problem of using A5 and SCL, SDA together.
Since SCL, SDA and A5 are three different pins.

A5 and SCL may be differently labelled pins on the Arduino board but they are both connected to the same pin on the actual processor

1 Like

Pins A4 and A5 serve 2 different purposes but can only be used at a time for one purpose. I2C or Analog in.

1 Like

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