# IOT monitoring system - using ESP32

**URL:** <https://forum.arduino.cc/t/iot-monitoring-system-using-esp32/934353>\
**Category:** General Guidance\
**Created:** [December 10, 2021, 2:16pm UTC](https://forum.arduino.cc/t/iot-monitoring-system-using-esp32/934353 "2021-12-10T14:16:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon95595578](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anon95595578](https://forum.arduino.cc/u/anon95595578)\
**Post date:** [December 10, 2021, 2:16pm UTC](https://forum.arduino.cc/t/iot-monitoring-system-using-esp32/934353/1 "2021-12-10T14:16:21Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [December 10, 2021, 2:31pm UTC](https://forum.arduino.cc/t/iot-monitoring-system-using-esp32/934353/2 "2021-12-10T14:31:23Z")

</div>

Look for example codes for the different devices.

---

<div class="post-metadata">

**Author:** ![anon95595578](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anon95595578](https://forum.arduino.cc/u/anon95595578)\
**Post date:** [December 10, 2021, 2:36pm UTC](https://forum.arduino.cc/t/iot-monitoring-system-using-esp32/934353/3 "2021-12-10T14:36:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [December 10, 2021, 2:52pm UTC](https://forum.arduino.cc/t/iot-monitoring-system-using-esp32/934353/4 "2021-12-10T14:52:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon95595578](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anon95595578](https://forum.arduino.cc/u/anon95595578)\
**Post date:** [December 17, 2021, 6:14am UTC](https://forum.arduino.cc/t/iot-monitoring-system-using-esp32/934353/5 "2021-12-17T06:14:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [December 17, 2021, 9:26am UTC](https://forum.arduino.cc/t/iot-monitoring-system-using-esp32/934353/6 "2021-12-17T09:26:20Z")

</div>

Please start by reading the [instructions for posting](http://arduino.cc/forum/index.php/topic,148850.0.html), 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.

---

<div class="post-metadata">

**Author:** ![anon95595578](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anon95595578](https://forum.arduino.cc/u/anon95595578)\
**Post date:** [December 18, 2021, 5:11am UTC](https://forum.arduino.cc/t/iot-monitoring-system-using-esp32/934353/7 "2021-12-18T05:11:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [December 18, 2021, 10:24am UTC](https://forum.arduino.cc/t/iot-monitoring-system-using-esp32/934353/8 "2021-12-18T10:24:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 16, 2022, 10:25am UTC](https://forum.arduino.cc/t/iot-monitoring-system-using-esp32/934353/9 "2022-06-16T10:25:38Z")

</div>

Closed on June 16, 2022, 10:25am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
