Evan Rust
Published © CC BY-NC-ND

Hack Menopause with an Automatic Hot Flash Fighter

Automatically detect when a hot flash is occurring and turn on a fan in response, as well as log it.

IntermediateFull instructions provided4 hours1,081
Hack Menopause with an Automatic Hot Flash Fighter

Things used in this project

Hardware components

Photon
Particle Photon
×1
12v Fan
×1
Grove - GSR sensor
Seeed Studio Grove - GSR sensor
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
IFTTT Google Sheets Service

Story

Read more

Schematics

Schemtaic

Code

Particle Code

C/C++
// Connect signal pin (Yellow) to the GSR sensor
#define GSR_PIN A0
// Connect MOSFET GATE pin to D2
#define FAN_PIN D2

// How strong the fan should blow air
#define FAN_STRENGTH 150
// How long the fan should go for
#define FAN_DURATION (1000 * 60 * 2) // 2 minutes

// A difference in readings >= to the threshold triggers the event
#define CHANGE_THRESHOLD 100

// How many readings to take and average together
#define READING_NUM 400

// Change to DEBUG_SERIAL 0 to disable serial output
#define DEBUG_SERIAL 1

long threshold;
bool isFanSet = false;

Timer fanTimer(FAN_DURATION, stopFan, true);

void setup() 
{
    pinMode(FAN_PIN, OUTPUT);
    analogWrite(FAN_PIN, 0);
    
    threshold = getThreshold();
    
    if(DEBUG_SERIAL)
    {
        Serial.begin(115200);
        while(!Serial);
        Serial.printf("Threshold: %d\n", threshold);
    }
    
}

void loop() 
{
    int16_t delta;
    uint16_t readValue = analogRead(GSR_PIN) / 4;
    if(DEBUG_SERIAL) Serial.printf("Value read from GSR: %d\n", readValue);
    delta = threshold - readValue;
    if(abs(delta) > CHANGE_THRESHOLD / 2)
    {
        readValue = analogRead(GSR_PIN) / 4;
        delta = threshold - readValue;
        if(abs(delta) > CHANGE_THRESHOLD / 2)
        {
            hotFlashDetected(delta);
            // Avoid duplicate events
            delay(3000);
        }
    }

}

long getThreshold()
{
    long sum;
    for(int reading_count = 0; reading_count < READING_NUM; reading_count++){
        sum += analogRead(GSR_PIN) / 4;
        delay(5);
    }
    return sum / READING_NUM;
}

void hotFlashDetected(int16_t delta)
{
    if(DEBUG_SERIAL) Serial.printf("Hot flash detected. Delta value = %d\n", delta);
    setFan(true);
    Particle.publish("hot_flash", "Active", PRIVATE);
}

void setFan(bool state)
{
    /* Truth table: isFanSet_old | state | isFanSet_new
    0 | 0 | 0
    0 | 1 | 1       // Only start fan duration timer here
    1 | 0 | 0
    1 | 1 | 0
    */
    
    isFanSet = state && !isFanSet;
    
    if(isFanSet)
    {
        fanTimer.start();
        analogWrite(FAN_PIN, FAN_STRENGTH);
    }
    else
    {
        analogWrite(FAN_PIN, 0);
    }
}

void stopFan()
{
    isFanSet = false;
    setFan(false);
}

Credits

Evan Rust

Evan Rust

122 projects • 1091 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments