i cant seem to combine both codes together. Below are the 2 codes i found, can any expert here assist?
Pulse sensor
#define USE_ARDUINO_INTERRUPTS false
#include <PulseSensorPlayground.h>
#include <WiFi.h>
#include <ThingSpeak.h>
const char ssid'[ ]' = "";
const char password'[ ]' = "";
WiFiClient client;
const long CHANNEL = ; //In this field, enter the Channel ID
const char *WRITE_API = "";// Enter the Write API key
long prevMillisThingSpeak = 0;
int intervalThingSpeak = 200; // 15 seconds to send data to the dashboard
const int OUTPUT_TYPE = SERIAL_PLOTTER;
const int PULSE_INPUT = 32;
const int PULSE_BLINK = 2;
const int PULSE_FADE = 5;
const int THRESHOLD = 2000;
byte samplesUntilReport;
const byte SAMPLES_PER_SERIAL_SAMPLE = 10;
PulseSensorPlayground pulseSensor;
void setup()
{
Serial.begin(9600);
pulseSensor.analogInput(PULSE_INPUT);
pulseSensor.blinkOnPulse(PULSE_BLINK);
pulseSensor.fadeOnPulse(PULSE_FADE);
pulseSensor.setSerial(Serial);
pulseSensor.setOutputType(OUTPUT_TYPE);
pulseSensor.setThreshold(THRESHOLD);
samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;
if (!pulseSensor.begin())
{
for'(;;)'
{
digitalWrite(PULSE_BLINK, LOW);
delay(50);
digitalWrite(PULSE_BLINK, HIGH);
delay(50);
}
}
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(ssid, password);
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
}
}
void loop()
{
if (pulseSensor.sawNewSample())
{
if (--samplesUntilReport == (byte) 0)
{
samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;
pulseSensor.outputSample();
if (pulseSensor.sawStartOfBeat())
{
pulseSensor.outputBeat();
}
}
int myBPM = pulseSensor.getBeatsPerMinute();
if (myBPM < 100 && myBPM > 50){
if (millis() - prevMillisThingSpeak > intervalThingSpeak)
{
ThingSpeak.setField(1, myBPM);
int x = ThingSpeak.writeFields(CHANNEL, WRITE_API);
if (x == 200)
{
Serial.println("Channel update successful.");
}
else
{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
prevMillisThingSpeak = millis();
}
}
}
}
GSR sensor
/*
GSR connection pins to Arduino microcontroller
Arduino GSR
GND GND
5V VCC
A2 SIG
D13 RED LED
*/
/*
GSR, standing for galvanic skin response, is a method of
measuring the electrical conductance of the skin. Strong
emotion can cause stimulus to your sympathetic nervous
system, resulting more sweat being secreted by the sweat
glands. Grove – GSR allows you to spot such strong emotions
by simple attaching two electrodes to two fingers on one hand,
an interesting gear to create emotion related projects, like
sleep quality monitor. http://www.seeedstudio.com/wiki/Grove_-_GSR_Sensor
*/
const int LED=2;
const int GSR=36;
int threshold=0;
int sensorValue;
void setup(){
long sum=0;
Serial.begin(9600);
pinMode(LED,OUTPUT);
digitalWrite(LED,LOW);
delay(1000);
for(int i=0;i<500;i++)
{
sensorValue=analogRead(GSR);
sum += sensorValue;
delay(5);
}
threshold = sum/500;
Serial.print("threshold =");
Serial.println(threshold);
}
void loop(){
int temp;
sensorValue=analogRead(GSR);
Serial.print("sensorValue=");
Serial.println(sensorValue);
temp = threshold - sensorValue;
if(abs(temp)>60)
{
sensorValue=analogRead(GSR);
temp = threshold - sensorValue;
if(abs(temp)>60){
digitalWrite(LED,HIGH);
Serial.println("Emotion Changes Detected!");
delay(3000);
digitalWrite(LED,LOW);
delay(1000);
}
}
}