Body Temperature Sensor

A sketch to read body temperature, and respond with the RGB LED turning blue, red or somewhere in between.

  • Thermistor
Code Used:
  • analogRead
  • analogWrite
  • map

If the thermistor is made hotter or colder than the expected range, it can skip past one extreme to the wrong colour.  The constrain() function can be used to keep this from happening.

#include <Servo.h>

#define ENCODER_A 14
#define ENCODER_B 15
#define SWITCH 13
#define BUTTON 12
#define RGB_RED 11
#define RGB_GREEN 10
#define RGB_BLUE 9
#define LED 6
#define SERVO 5
#define PIEZO 3
#define RELAY 2
#define POT 2
#define HALL 3
#define THERMISTOR 4
#define PHOTOCELL 5

void setup()
    pinMode(THERMISTOR, INPUT); 
    pinMode(RGB_RED, OUTPUT); 
    pinMode(RGB_BLUE, OUTPUT); 

void loop()
    // change the thermistor's value to something more in the range of human temperature
    int iSensor = map(analogRead(THERMISTOR),475,600,0,255); 
    // more red for higher temp, more blue for lower temp
    analogWrite(RGB_RED, iSensor); 
    analogWrite(RGB_BLUE, 255 - iSensor); 

Leave a Reply

Your email is never published nor shared.

You may use these HTML tags and attributes:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>