carbon sensor value and sweat sensor value clash

Hi guys, so currently i'm on a project where i'm suppose to add multiple sensors together and create a form of alert through LED light up and vibration motor. As such, when any of these sensors have sense a "critical" value as defined in arduino IDE, the LED will light up accordingly and vibration motor will vibrate accordingly as well.

And as such the sensors that are used for my project are :

  1. DS18B20 Temperature sensor module (with breakout)
  2. DFRobot SEN0219 carbon dioxide sensor
  3. Adafruit ultimate GPS sensor
  4. DIY Sweat sensor
  5. TCS3200 colour sensor
  6. RGB LED
  7. coin vibration motor
    8 ) arduino nano

The setup for all the sensor, LED and vibration are as based on the following websites (*exclude Vcc and ground setup):

  1. Temperature sensor: it has only three pins (+, - , and out), therefore Vcc to +, GND to -, and one jumper wire for output signal
  2. Carbon dioxide sensor: Gravity__Analog_Infrared_CO2_Sensor_For_Arduino_SKU__SEN0219-DFRobot
  3. Adafruit ultimate GPS sensor:Breakout Arduino Wiring | Adafruit Ultimate GPS | Adafruit Learning System ( tx to arduino nano d3, rx to arduino d2)
  4. DIY Sweat sensor: Arduino Detects Pants On Fire | Hackaday, How to Make an Arduino Ohm Meter | Circuit Basics (essentially it is voltage divider with the use of known and unknown resistors, in this case skin is the "unknown resistor")
  5. TCS3200 colour sensor: http://howtomechatronics.com/tutorials/ ... or-sensor/
  6. RGB LED: http://howtomechatronics.com/tutorials/arduino/how-to-use-a-rgb-led-with-arduino/
  7. Coin vibration motor: Loading...

The Vcc and GND to power all components are as follows:

  1. Lipo battery 7.4V, 850 mAh to pololu step down regulator 5V, 2.5A to: Colour sensor, Sweat sensor, GPS sensor, Temperature sensor, RGB LED and vibration motor
  2. arduino nano 5v pin and gnd to carbon dioxide sensor
  3. Lipo battery 7.4V, 850 mAh to arduino nano Vin and GND
  4. usb connection to arduino nano

And the following code were used to operate all of the sensors:

/* Variables for LED */
int redPin = 9;                                            
int greenPin = 10;                                          
int bluePin = 11;                                           

/* Variables for Motor */
const int motorPin = 13;                                  

/* Variables for Carbon Sensor */
int carbonPin = A0;                                         

/* Variables for Temperature */
#include <OneWire.h>                                        
#include <DallasTemperature.h>                              
#define ONE_WIRE_BUS 12                                     
OneWire oneWire(ONE_WIRE_BUS);                             
DallasTemperature sensors(&oneWire);                        

/* Variables for Galvanic Skin Response Sensor */
const int gsrPin  =  A1;                                    
int raw = 0;                                                
int Vin = 5;                                                
float Vout = 0;                                          
float R1 = 510000;                                        
float R2 = 0;                                               
float buffer = 0;                                           
float conductance = 0;                                      

/* Variables for GPS */
#include <Adafruit_GPS.h>                                  
#include <SoftwareSerial.h>                                 
SoftwareSerial mySerial(3, 2);                              
Adafruit_GPS GPS(&mySerial);
#define GPSECHO  false                                      
boolean usingInterrupt = false;                             
void useInterrupt(boolean);                               
uint32_t timer = millis();

/* Variables for Colour Sensor */
#define S0 4                                               
#define S1 5                                                
#define S2 6                                                
#define S3 7                                                
#define sensorOut 8                                         

int redFrequency = 0;                                      
int greenFrequency = 0;                                     
int blueFrequency = 0;                                      



void setup()                                                
{
  
    /* Configuration of pins */
    pinMode(redPin,OUTPUT);                                 
    pinMode(greenPin,OUTPUT);                              
    pinMode(bluePin,OUTPUT);                                
    
    pinMode(motorPin,OUTPUT);                              

    pinMode (carbonPin,INPUT);                              

    pinMode (gsrPin,INPUT);                                 

    pinMode(S0, OUTPUT);                                    
    pinMode(S1, OUTPUT);                                    
    pinMode(S2, OUTPUT);                                  
    pinMode(S3, OUTPUT);                                    
    pinMode(sensorOut, INPUT);                              

    /* Output frequency scaling of 20% */
    digitalWrite(S0,HIGH);                                  
    digitalWrite(S1,LOW);                                   
      
    Serial.begin(115200);                                   

    
    
    sensors.begin();                                        

    /* Setup for GPS sensor */
    GPS.begin(9600);                                        
    GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);          
    GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);              
    useInterrupt(true);                                     
        
}

This is the second part of the code (unable to post as a whole tread due to word limit)

void loop()                                                 // Repeat function
{ 
  
    /* Setup for risk values which will be use for LED lightup */
    int SkinRiskValue;                                      
    int SweatRiskValue;                                    
    int LocationRiskValue;                                  
    int ColourRiskValue;                                   
    int CarbonRiskValue;                                    
    int y;                                                 
    char* myStrings[]={"No colour  ", "Red detected  ", "Green detected  ", "Blue detected  ","Purple detected  ","Orange detected  ","Yellow detected  "}; 
    int x;                                                  

    /* Setup for Carbon Dioxide */
    int carbonValue = analogRead (carbonPin);              
    float voltage = carbonValue*(5000/1024.0);              
    int voltage_diference=voltage-400;                      
    float concentration = voltage_diference * 50.0/16.0;    
    
    /* Setup for GSR Sensor */
    raw = analogRead(gsrPin);                              
    buffer = raw * Vin;                                    
    Vout = (buffer)/1024.0;                                 
    buffer = (Vin/Vout) -1;                                 
    R2 = R1 * buffer;                                       
    conductance = (1/R2)*1000000;                           

    /* Setup for Temperature */
    sensors.requestTemperatures();                          

    /* Setup for GPS */
    if (GPS.newNMEAreceived())                             
    {
        if (!GPS.parse(GPS.lastNMEA()))                     
          return;                                           
    }



    if (timer > millis())  timer = millis();               

    if (millis() - timer > 4000)                            
    { 
        timer = millis();                                  


        /* Display values at serial monitor */
        Serial.print("Temperature: ");                      
        Serial.print(sensors.getTempCByIndex(0));          
        Serial.print(" Degree");                           
        Serial.print("  |  ");                             
        
        Serial.print("Carbon Dioxide is: ");                
        Serial.print(concentration);                      
        Serial.print(" ppm   ");                            
        Serial.print("voltage: ");                          
        Serial.print(voltage);                             
        Serial.print("  mv");                              
        Serial.print("  |  ");                             
        
        Serial.print("Conductance: ");                      
        Serial.print (conductance, 6);                     
        Serial.print("  uS   ");                            
        Serial.print("Resistance: ");                       
        Serial.print (R2, 4);                              
        Serial.print("  Ohm");                             
        Serial.print("  |  ");                           
                
        digitalWrite(S2,LOW);                          
        digitalWrite(S3,LOW);                              
        redFrequency = pulseIn(sensorOut, LOW);             
        Serial.print("Red = ");                            
        Serial.print(redFrequency);                         
        digitalWrite(S2,HIGH);                              
        digitalWrite(S3,HIGH);                              
        greenFrequency = pulseIn(sensorOut, LOW);           
        Serial.print(" Green = ");                          
        Serial.print(greenFrequency);                       
        digitalWrite(S2,LOW);                               
        digitalWrite(S3,HIGH);                              
        blueFrequency = pulseIn(sensorOut, LOW);            
        Serial.print(" Blue = ");                         
        Serial.print(blueFrequency);                       
        Serial.print("  ");                                

       
        /* Setup for Temperature */
        float skin_temp = sensors.getTempCByIndex(0);       
        
        
        /* if else conditions for Colour */
        if(redFrequency > 20 && redFrequency < 45 &&  greenFrequency > 55 && greenFrequency < 80 && blueFrequency > 35 && blueFrequency < 60 && greenFrequency > blueFrequency &&  blueFrequency > redFrequency) 
        {
            ColourRiskValue = 3;                           
            x = 1;                                          
        }
        
        else if(redFrequency > 15 && redFrequency < 30 &&  greenFrequency > 40 && greenFrequency < 65 && blueFrequency > 30 && blueFrequency < 55 && greenFrequency > redFrequency &&  blueFrequency > redFrequency)
        {
            ColourRiskValue = 3;                             
            x = 5;                                     
        }
                
        else if(redFrequency > 35 && redFrequency < 55 &&  greenFrequency > 15 && greenFrequency < 50 && blueFrequency > 30 && blueFrequency < 55 && redFrequency > greenFrequency /*&&  redFrequency > blueFrequency*/) 
        {
            ColourRiskValue = 3;                              
            x = 2;                                            
        }
        
        else if(redFrequency > 45 && redFrequency < 75 &&  greenFrequency > 25 && greenFrequency < 45 && blueFrequency > 10 && blueFrequency < 30 && redFrequency > greenFrequency &&  greenFrequency > blueFrequency) 
        {
            ColourRiskValue = 3;                              
            x = 3;                                            
        }
        
        else if(redFrequency > 25 && redFrequency < 45 &&  greenFrequency > 40 && greenFrequency < 65 && blueFrequency > 15 && blueFrequency < 35 && greenFrequency > blueFrequency &&  greenFrequency > redFrequency)
        {
            ColourRiskValue = 3;                             
            x = 4;                                           
        }
        
        else if(redFrequency > 10 && redFrequency < 25 &&  greenFrequency > 15 && greenFrequency < 30 && blueFrequency > 15 && blueFrequency < 40 && blueFrequency > redFrequency/* && greenFrequency > redFrequency*/) 
        {
            ColourRiskValue = 3;                            
            x = 6;                                            
        }
        
        else                                                
        {
            ColourRiskValue = 0;                            
            x=0;                                              
        }


        /* Display values at serial monitor */
        Serial.print("Colour: ");                           
        Serial.print(myStrings[x]);                       
        Serial.print("  |  ");                             
        Serial.print(" Location (Latitude, Longtitude): "); 
        Serial.print(GPS.latitudeDegrees, 6);               
        Serial.print(", ");                                 
        Serial.println(GPS.longitudeDegrees, 6);            
        Serial.println("");                                 
        
        
        /* if conditions for Temperature */
        if (skin_temp < 25.5)                               
        {
             SkinRiskValue = 0;                            
        } 
        
        if (skin_temp > 25.5 && skin_temp < 26)             
        {
             SkinRiskValue = 1;                             
        } 
        
        if (skin_temp > 26.00 && skin_temp < 26.5)          
        {
            SkinRiskValue = 2;                              
        }  
        
        if (skin_temp > 26.50)                              
        {
            SkinRiskValue = 3;                              
        }
/* if conditions for Carbon dioxide */
        if (concentration < 900)                           
        {
            CarbonRiskValue = 0;                            
        }
    
        if (concentration > 900 && concentration < 1500)    
        {
           CarbonRiskValue = 1;                             
        }

        if (concentration > 1500 && concentration < 2000)  
        {
            CarbonRiskValue = 2;                            
        }
    
        if (concentration > 2000)                           
        {
           CarbonRiskValue = 3;                             
        }


    
        /* if conditions for Sweat */
        if (conductance < 5)                               
        {
            SweatRiskValue = 0;                            
        }
      
        if (conductance > 1 && conductance < 5)             
        {
            SweatRiskValue = 1;                             
        }
    
        if (conductance > 5 && conductance < 10)            
        {
           SweatRiskValue = 2;                              
        }
    
        if (conductance > 10)                               
        {
            SweatRiskValue = 3;                             
        }



        /* if conditions for GPS */
        if (GPS.latitudeDegrees > 1.441700 && GPS.latitudeDegrees < 1.442000 || GPS.latitudeDegrees > 1.443600 && GPS.latitudeDegrees < 1.443900)                     
        {
            if (GPS.longitudeDegrees > 103.806400 && GPS.longitudeDegrees < 103.808700)              
            {   
                LocationRiskValue = 1;                                                                  
            }
        }  

        else if (GPS.longitudeDegrees > 103.806400 && GPS.longitudeDegrees < 103.806760 || // If condition is met
        {
            if (GPS.latitudeDegrees > 1.441700 && GPS.latitudeDegrees < 1.443900)                   
            {
                LocationRiskValue = 1;                                                              
            }
        }
        
        else if (GPS.latitudeDegrees > 1.442000 && GPS.latitudeDegrees < 1.442516 || GPS.latitudeDegrees > 1.443288 && GPS.latitudeDegrees < 1.443600)                
        {
            if (GPS.longitudeDegrees > 103.80676 && GPS.longitudeDegrees < 103.808425)              
            {   
                LocationRiskValue = 2;                                                                    
            }
        }  

        else if (GPS.longitudeDegrees > 103.806760 && GPS.longitudeDegrees < 103.807276 || GPS.longitudeDegrees > 103.807909 && GPS.longitudeDegrees < 103.808425)   
        {
            if (GPS.latitudeDegrees > 1.442000 && GPS.latitudeDegrees < 1.443600)                   
            {
                LocationRiskValue = 2;                                                              
            }
        }
        
        else if (GPS.latitudeDegrees > 1.442516 && GPS.latitudeDegrees < 1.443288 && GPS.longitudeDegrees > 103.807276 && GPS.longitudeDegrees < 103.807909)          
        {
            LocationRiskValue = 3;                                                                  
        } 
        
        else                                                                                                                                                            
        {
            LocationRiskValue = 0;                                                                      
        }

   
        
        /* Setup for fading LED and summation of values */
        int TotalRiskValue = SkinRiskValue + SweatRiskValue + ColourRiskValue + LocationRiskValue + CarbonRiskValue;    
        y = map(TotalRiskValue, 1, 15, 0, 255);              
        int i = 255 - y;                                     
        Serial.print("LED Colour Mapping (R,G,B): ");        
        
        Serial.print("255 ");                                
        Serial.print(" , ");                                 
        Serial.print(i);                                     
        Serial.print(" , 0 ");                              
        Serial.print("  |  ");                              
        Serial.print("  total risk: ");                     
        Serial.print(TotalRiskValue);                        
        Serial.print("  skin: ");                            
        Serial.print(SkinRiskValue);                        
        Serial.print("  Carbon: ");                          
        Serial.print(CarbonRiskValue);                       
        Serial.print("  sweat:  ");                          
        Serial.print(SweatRiskValue);                        
        Serial.print("  color risk: ");                      
        Serial.print(ColourRiskValue);                      
        Serial.print("  location risk:  ");                  
        Serial.println(LocationRiskValue);                   
        Serial.println(" ");                                 

        delay(1000);
        if (TotalRiskValue > 0 && TotalRiskValue <16)        
        {
            setColor(255, i, 0);                             
                            
            if (TotalRiskValue > 10)                         
            {
                digitalWrite(motorPin, HIGH);                
                delay(500);                                  
                digitalWrite(motorPin, LOW);                
                delay(500);                                  
                digitalWrite(motorPin, HIGH);                
                delay(500);                               
                digitalWrite(motorPin, LOW);                 
                delay(500);                                 
                digitalWrite(motorPin, HIGH);                
                delay(500);                                  
                digitalWrite(motorPin, LOW);                
                delay(500);                                 
            }
            
            else if (TotalRiskValue > 5  && TotalRiskValue < 11)
            {
                digitalWrite(motorPin, HIGH);                
                delay(1000);                                
                digitalWrite(motorPin, LOW);                
                delay(1000);                                
            
            }
            
            delay(1000);                                     
            setColor(0,0,0);                                 
        }
        
        else                                              
        {     
            setColor(0, 0, 0);                               
        }
    }
}



SIGNAL(TIMER0_COMPA_vect)                                   
{
    char c = GPS.read();                                     
    #ifdef UDR0                                              
    if (GPSECHO)                                            
    if (c) UDR0 = c;                                         
    #endif                                                   
}



void useInterrupt(boolean v) 
{
    if (v)                                                   
    {  
        OCR0A = 0xAF;
        TIMSK0 |= _BV(OCIE0A);
        usingInterrupt = true;
    }  
    
    else                                                    
    {
        TIMSK0 &= ~_BV(OCIE0A);
        usingInterrupt = false;
    }
}


void setColor(int redValue, int greenValue, int blueValue) eValue)

{
    analogWrite(redPin, redValue);                     
    analogWrite(greenPin, greenValue);                      
    analogWrite(bluePin, blueValue);                        
}

image attached shows the connections through the breadboard. **note: setup and coding works as intended.

so basically with the setup and coding inplace, this is where problem comes about. when i power up the devices as seen from the listed connection mentioned earlier. and then i open up the serial monitor, i notice that when i touch the DIY sweat sensor (which is the red and black wire as seen in the picture) the value of sweat increase, but however, the carbon dioxide value ALSO increase together with the sweat sensor. this can be seen in the attached image. This happens also when i remove my hand from the wires. the carbon dioxide value also decrease.

This do not happens all the time. sometimes i would try restarting arduino IDE and replug the usb connection and lipo battery. and then it goes back to normal, where the touch of sweat sensor do not affect the carbon dioxide sensor value. but after it becomes normal, i would then "activate" all of the sensors, then the value of sweat sensor AGAIN affect the carbon sensor value.

so can anyone tell me what is this happening? i dun really understand because voltage supply to carbon sensor and sweat sensor are different, and the code had also define carbon pin and sweat pin differently, where carbon is given as A0 sweat (GSR) is given as A1 in arduino IDE. My friend actually pinpointed that this could be due to voltage glitch which im not really sure what he meant.

IN addition, can anyone help to resolve this issue?

The example of normal values when sweat sensor is touch is also shown. it can be notice that the carbon sensor values do not clash with sweat sensor, where their values are independent (after several attempts of resetting and restarting of arduino IDE and microcontroller)

First think I would do is check that every sensor is getting its supply at the right voltage (ie that
all the supplies and the supply wiring are working/intact). Measure the voltage at the sensor between
its local ground and supply pins - is the voltage too low? If so investigate that first.

Then look at (with a multimeter) the signal voltages of the sensors in question when you touch the sweat
sensor - is there a genuine voltage change that shouldn't be happening ? If so then investigate that
before worrying about the Arduino code at all.

Then check the Arduino input pins are getting the same voltages you saw at the sensor.

Basically check each thing indivually before attempting to debug the complete system - only when
everything individually is know to be performing OK is it worth proceeding.

You may find there's an issue with ground currents, or using flimsy signal wires to carry significant power,
or faulty breadboard pin, or unwanted oscillations, who knows.

If the hardware is fine, then its time to look at the software.