Back to Parent

Coding for Sweat Sensor
#include "Adafruit_GFX.h"

#include "Adafruit_SSD1306.h"

#define OLED_DC     D3
#define OLED_CS     D4
#define OLED_RESET  D5
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);


static const unsigned char logo16_glcd_bmp[] =

{ 0B00000000, 0B11000000,
  0B00000001, 0B11000000,
  0B00000001, 0B11000000,
  0B00000011, 0B11100000,
  0B11110011, 0B11100000,
  0B11111110, 0B11111000,
  0B01111110, 0B11111111,
  0B00110011, 0B10011111,
  0B00011111, 0B11111100,
  0B00001101, 0B01110000,
  0B00011011, 0B10100000,
  0B00111111, 0B11100000,
  0B00111111, 0B11110000,
  0B01111100, 0B11110000,
  0B01110000, 0B01110000,
  0B00000000, 0B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

int thresholdUp = 3500;
int thresholdDown = 250;
int sensorPin = A0;
int SweatData = 1;
int sensorValue;
bool userIsDehydrated = false;
void setup ()
{

  display.begin(SSD1306_SWITCHCAPVCC);
  display.clearDisplay();
  Particle.variable("Sweat Data", SweatData);

}
void loop ()
{
  sensorValue = analogRead(sensorPin);

  int SweatData = sensorValue;

  if (sensorValue >= thresholdUp)
  {
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(20,0);
    display.println("Hydrate Please!");
    display.display();
    /*userIsDehydrated = true;*/
    if(userIsDehydrated == true) {
      /*do nothing*/
      /*Warn again*/
    } else {
        
        userIsDehydrated = true;
    }

  }
  else
  {
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(20,0);
    display.println("All good! Keep it going!");
    display.display();

    userIsDehydrated = false;


  }
  delay(1000);

}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0