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();
}
//*********************************