IOT monitoring system - using ESP32

Hi all,

Would like to check is there any codes available for pulse sensor and GSR sensor to be send to thinkspeak for the review of readings. I am using ESP32(wifi included) for the microcontroller.

Appreciate some help from the experts here.

Many thanks in advance !

Look for example codes for the different devices.

i have found the different codes, but unable to combine them together to send to thinkspeak.

Select one code. Then cut and paste the other code into it, piece by piece. Keep declarations together, then setup codes inside the same setup. In loop add the second code body after the first one.

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);
}
}
}

Please start by reading the instructions for posting, then edit your code post (use the "pencil" icon below the post) to use "code" tags so we can read it properly.

Note you need to use "Auto-Format" (Ctrl-T) on the code in the IDE first.

the post is no longer available, but i made some slight edits to the code above. able to assist?

Call it a test to see if you can follow instructions. If you can't follow instructions, then it is no use trying to help you combine the 2 codes.

Yes, I can just do it for you but what will you learn?

The test, edit post number 5 and put the code in code tags.