1

I have two codes for my to sensors and they work separately. However, I need to combine them in one program please can you help?

The pulse code

 /* PulseSensor Starter Project and Signal Tester
 *  The Best Way to Get Started  With, or See the Raw Signal of, your PulseSensor.com™ & Arduino.
 *
 *  Here is a link to the tutorial
 *  https://pulsesensor.com/pages/code-and-guide
 *
 *  WATCH ME (Tutorial Video):
 *  https://www.youtube.com/watch?v=RbB8NSRa5X4
 *
 *
-------------------------------------------------------------
1) This shows a live human Heartbeat Pulse.  
2) Live visualization in Arduino's Cool "Serial Plotter".  
3) Blink an LED on each Heartbeat.  
4) This is the direct Pulse Sensor's Signal.  
5) A great first-step in troubleshooting your circuit and connections.  
6) "Human-readable" code that is newbie friendly."  

*/


//  Variables
int PulseSensorPurplePin = 0;        // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED13 = 13;   //  The on-board Arduion LED


int Signal;                // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 550;            // Determine which Signal to "count as a beat", and which to ingore.


// The SetUp Function:
void setup() {
  pinMode(LED13,OUTPUT);         // pin that will blink to your heartbeat!
   Serial.begin(9600);         // Set's up Serial Communication at certain speed.

}

// The Main Loop Function
void loop() {

  Signal = analogRead(PulseSensorPurplePin);  // Read the PulseSensor's value.
                                              // Assign this value to the "Signal" variable.

   Serial.println(Signal);                    // Send the Signal value to Serial Plotter.


   if(Signal > Threshold){                          // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
     digitalWrite(LED13,HIGH);
   } else {
     digitalWrite(LED13,LOW);                //  Else, the sigal must be below "550", so "turn-off" this LED.
   }


delay(10);


}

The gsr code:

void setup()
{
    Serial.begin(9600);
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    digitalWrite(2, HIGH);
    delay(500);
    digitalWrite(3, HIGH);
    delay(500);
    digitalWrite(4, HIGH);
    delay(500);
}

void loop()
{
    if (analogRead(A0) > 60)
    {
        digitalWrite(4, HIGH);
    }
    else
    {
        digitalWrite(4, LOW);
    }
    if (analogRead(A0) > 20)
    {
        digitalWrite(2, HIGH);
    }
    else
    {
        digitalWrite(2, LOW);
    }
    if (analogRead(A0) > 45)
    {
        digitalWrite(3, HIGH);
    }
    else
    {
        digitalWrite(3, LOW);
    }

    Serial.println(analogRead(A0));
    delay(20);
}
3
  • 1
    just combine the codes in setup and loop functions - at a quick glance, there shouldn't be any conflict - have you even tried? if so, what problem did you face? Commented Feb 11, 2019 at 0:23
  • 1
    I faced problem my sensor not reading and i tried to change the analog input but it wouldn't read Commented Feb 11, 2019 at 17:09
  • 1
    Please provide us with the actual combined code so we can compile and flash it. Also the corresponding output of your three codes could be helpful
    – Sim Son
    Commented Feb 12, 2019 at 17:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.