Input to Analogue A0 affects inout to Analogue A1

This is my first time so please be gentle!
I am using Arduino Mega 2560 to read input from three smoke sensors (MQ-2). These are read into analogue pins A1, A2 and A3. So far so good.
I then use a commercial smoke alarm and have tapped off the buzzer to see when it triggers. This I feed into Analogue A0.
The schematic below assumes the 5V goes to all sensors.
From the output, you can clearly see when the "buzzer" goes off as there is an almost sinusoidal effect on pin A1 (MQ-2 smoke sensor).
QUESTION: How can I prevent the inout to A0 affect the inout to A1?
Any help would be greatly appreciated.

CODE IS BELOW - SOME LINES ARE COMMENTED OUT AT THIS STAGE:

//SMOKE BOX TESTS
// Use smoke box to assess three smoke sensors. sensors 1 & 2 vertical and Sensor 3 horizontal
// Ability to print or plot results.
// Ability to store results along with date and Time.

#include <SD.h>
#include <RTClib.h>
#include <Wire.h>

// Date and time functions using a PCF8523 RTC connected via I2C and Wire lib #include "RTClib.h"

#include "RTClib.h"
#include "SD.h"

// Set Analogue pins for smoke detectors.
#define smokeA1 A1
#define smokeA2 A2
#define smokeA3 A3
#define smokeA0 A0 // optical sensor into Analogue pin A0

#define SD_CHIPSELECT 10

RTC_Millis rtc; // Read time from rtc
DateTime currentDateTime;

// SD card and Logging variables
String filename = "datalog.csv";
bool sdOk = true;
bool enableLogging = true; // Change to true to enable logging to SD card File logFile;
File logFile;

// Set variables for values of smoke from each sensor
int analogSensor1;
int analogSensor2;
int analogSensor3;
int opticalSensor1;
float voltage;
int Trigger;

// Set Smoke threshold value
//int sensorThres = 400;

// flag to show fire
//int zoneFire = 0;

//*********************************
void setup() {

pinMode(smokeA1, INPUT);
pinMode(smokeA2, INPUT);
pinMode(smokeA3, INPUT);
pinMode(smokeA0, INPUT);

Serial.begin(115200);
SetupSD();
SetupRTC();

}

//*********************************
void loop() {
ReadDateTime();
ReadSmoke();
LogData();
delay(100);
}

//*********************************
void SetupSD() {
Serial.println("Initialising SD card...");
if (!SD.begin(SD_CHIPSELECT)) {
Serial.println("SD Initialisation failed!");
sdOk = false;
}
else {
Serial.println("Initilisation complete");
sdOk = true;

// Create a new file
logFile = SD.open(filename, FILE_WRITE);
if (logFile) {
  logFile.println("DateTime,Smoke1, Smoke2, Smoke3, Optical");
  logFile.close();
}
else {
  Serial.print("Couldn't create logfile "); Serial.println(filename);
  sdOk = false;
}

}
}

//*********************************
void SetupRTC() {
// following line sets the RTC to the date & time this sketch was compiled
rtc.begin(DateTime(F(DATE), F(TIME)));

DateTime now = rtc.now();
rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second() + 6));

}

//*********************************
void ReadSmoke() {

analogSensor1 = analogRead(smokeA1); delay(10);
analogSensor2 = analogRead(smokeA2); delay(10);
analogSensor3 = analogRead(smokeA3); delay(10);
int opticalSensor1 = analogRead(smokeA0);
delay(10);
if (opticalSensor1 > 165){
Trigger = 100;
}else {
Trigger = 80;

}

//Serial.print(currentDateTime);
Serial.print(analogSensor1);
Serial.print('\t');
Serial.print(analogSensor2);
Serial.print('\t');
Serial.print(analogSensor3);
Serial.print('\t');
Serial.println(Trigger);
//Serial.print('\t');

}

//*********************************
void LogData() {
if (sdOk) {
String dataString = "";
dataString += currentDateTime.timestamp(DateTime::TIMESTAMP_FULL); dataString += ",";
dataString += analogSensor1; dataString += ",";
dataString += analogSensor2; dataString += ",";
dataString += analogSensor3; dataString += ",";
dataString += Trigger; dataString += ",";

logFile = SD.open(filename, FILE_WRITE);
if (logFile) {
  logFile.println(dataString);
  logFile.close();
}
else {
  Serial.println("LogDate: Couldn't create logfile");
  sdOk = false;
}

}
}

//*********************************
void ReadDateTime() {
currentDateTime = rtc.now();

}
//*********************************

Screenshot 2021-09-13 at 18.51.44

OOPS, WRONG UPLOAD.

Try take analog reading, discard first reading, take another reading, and use the 2nd reading instead. There is only one A:D converter and there may be a need to bleed off the previous reading from the sample and hold circuit of the A:D converter.

Also, for an UNO, I found that putting a 103 cap into the analog ref and ground improves A:D stability.

Thanks for your prompt response.
Added repeat readings and had a similar result (see below)
Will look at limiting to 103 next.

Another trick I've done is when not using all the A:D inputs, connect one to ground.

Say A4 grounded. Read A4, read A0, read A4, read A1, read A4, read A2, read A4.

When you change your code post the new changed code so you and we are on the same page, code wise.

1 Like

Again, thanks for your prompt response.
On it.........

Idahowalker
It works!!
Cannot thank you enough. I grounded A0 and used A10 as the input instead.
You have gone straight to the top of this year's Christmas Card List!! :innocent:

1 Like

Hi,
When you edited this to two readings.

analogSensor1 = analogRead(smokeA1); delay(10);
analogSensor2 = analogRead(smokeA2); delay(10);
analogSensor3 = analogRead(smokeA3); delay(10);

Did edit like this?

analogSensor1 = analogRead(smokeA1); delay(10);
analogSensor1 = analogRead(smokeA1); delay(10);
analogSensor2 = analogRead(smokeA2); delay(10);
analogSensor2 = analogRead(smokeA2); delay(10);
analogSensor3 = analogRead(smokeA3); delay(10);
analogSensor3 = analogRead(smokeA3); delay(10);

or like this

analogSensor1 = analogRead(smokeA1); delay(10);
analogSensor2 = analogRead(smokeA2); delay(10);
analogSensor3 = analogRead(smokeA3); delay(10);
analogSensor1 = analogRead(smokeA1); delay(10);
analogSensor2 = analogRead(smokeA2); delay(10);
analogSensor3 = analogRead(smokeA3); delay(10);

That last version will not accomplish what you need.

Tom... :smiley: :+1: :coffee: :australia:
PS, The ground trick is good if you have spare inputs. :+1:

Hi Tom
Thanks for the response.
Luckily (and it was pure luck) I did it the way you suggested.
Feeling smug so added a second optical trigger. Today I smell of smoke. :grinning:

Neil