Published © LGPL

Arduino 101 Clothes Recommender

Arduino 101 that tells you the inside and outside temperature and recommends what clothes to wear.

BeginnerFull instructions provided1 hour3,927
Arduino 101 Clothes Recommender

Things used in this project

Hardware components

Arduino 101
Arduino 101
×1
Temperature Sensor
Temperature Sensor
×1
Seeed Studio Grove - RGB Backlight LCD - 16x2
×1
Seeed Studio Grove - Temperature Sensor
×1
Seeed Studio Grove - Button
×1
Seeed Studio Grove - Touch Sensor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Clothes recomender setup

Code

Clothes recomender

Arduino
#include <Wire.h>    //include 2 libraries
#include "rgb_lcd.h"//for rgb lcd

#include <math.h>//include a library for math that will be done with the thermistor.

rgb_lcd lcd;

const int b1 = 2; //this is the button for the background
const int bc = 3; //this is the touch button that switches between fahrenheit and celsius

const int ot = A0;//this is the pin for the outside temp

float R;  //set the variables
float G; //for the color
float B;//of the background

int background = 4;//different values will make the rgb lcd a different color

int a;//original thermosistor value
int base = 3985;//base value of the thermistor
float c;//float for celsius
float f;//float for fahrenheit
float oc;//float for outside celsius
float of;//float for outside fahrenheit

int cf = 0;//0 for celsius, 1 for fahrenheit

float resistance;//float for the resistance of the thermistor

int i;//var for calling on function to find inside temp
int o;//var for calling on function to find outside temp

int cb;//int for calling on function to check the buttons

int count = 50;//int for looping the part that checks the color 50x

char* rec[]={"wear warm jacket","wear light coat","wear sweatshirt","wear long-sleves","wear a T-shirt"};//string for the cloathing recomendation
int re;//a var that will be used to determine which rec string to use

void setup() {
  lcd.begin(16, 2);// set up the LCD's number of columns and rows:

  pinMode(b1, INPUT); //define the buttons as input
  pinMode(bc, INPUT);
}



void loop() {
  cb = checkButtons(b1, bc);


  while (count > 0) {
    if (background == 1) { //if the background int is 1:
      R = 255; //set the variables for the background
      G = 0;
      B = 0;
    }
    else if (background == 2) { //else if the background int is 2:
      R = 0; //set the variables for the background
      G = 255;
      B = 0;
    }
    else if (background == 3) { //else if the background int is 3:
      R = 0; //set the variables for the background
      G = 0;
      B = 255;
    }
    else if (background == 4) { //else if the background int is 5:
      R = 255; //set the variables for the background
      G = 255;
      B = 255;
    }
    lcd.setRGB(R, G, B);//set the background color of the lcd screen
    count--;
    delay(20);//delay 5 milliseconds
  }


  int w =wetherRec(oc);
  
  if (cf == 0) {
    i = findC();
    o = findOC();
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(c);
    lcd.print("c");
    lcd.setCursor(8, 0);
    lcd.print(oc);
    lcd.print("c");
    lcd.setCursor(0, 1);
    if (re=1){
      lcd.print(rec[1]);
    }
    else if (re=2){
      lcd.print(rec[2]);
    }
    else if (re=3){
      lcd.print(rec[3]);
    }
    else if (re=4){
      lcd.print(rec[4]);
    }
    else if (re=5){
      lcd.print(rec[5]);
    }
  }

  if (cf == 1) {
    i = findF();
    o = findOF();
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(f);
    lcd.print("f");
    lcd.setCursor(8, 0);
    lcd.print(of);
    lcd.print("f");
    lcd.setCursor(0, 1);
    if (re=1){
      lcd.print(rec[1]);
    }
    else if (re=2){
      lcd.print(rec[2]);
    }
    else if (re=3){
      lcd.print(rec[3]);
    }
    else if (re=4){
      lcd.print(rec[4]);
    }
    else if (re=5){
      lcd.print(rec[5]);
    }
  }
  count=50;
}



int findF() { // function to find fahrenheit
  a = analogRead(A1); //find the original reading of the thermistor
  resistance = (float)(1023 - a) * 10000 / a; //get the resistance of the sensor;
  c = 1 / (log(resistance / 10000) / base + 1 / 298.15) - 273.15; //convert to Celsius
  f = (c * (9 / 5) + 32); //convert to fahrenheit
  return c;
  return f;//return the fahrenheit
}

int findC() { // function to find celsius
  a = analogRead(A1); //find the original reading of the thermistor
  resistance = (float)(1023 - a) * 10000 / a; //get the resistance of the sensor;
  c = 1 / (log(resistance / 10000) / base + 1 / 298.15) - 273.15; //convert to Celsius
  return c;//return the celsius
}

int findOF() { //function to find the outside fahrenheit
  int t = analogRead(ot);//create a variable to store the value of the outside tmp36 module
  float voltage = (t / 1024.0) * 5.0;//convert the ADC reading to voltage
  // the sensor changes 10 mV per degree celsius
  // the datasheet says there's a 500 mV offset
  oc = (voltage - .5) * 100;//convert to celsius
  of = (oc * (9 / 5) + 32); //convert to fahrenheit
  return oc;
  return of;//return the outside fahrenhiet
}

int findOC() { //function to find the outside fahrenheit
  int t = analogRead(ot);//create a variable to store the value of the outside tmp36 module
  float voltage = (t / 1024.0) * 5.0;//convert the ADC reading to voltage
  // the sensor changes 10 mV per degree celsius
  // the datasheet says there's a 500 mV offset
  oc = (voltage - .5) * 100; //convert to celsius
  return oc;//return the outside celsius
}

int wetherRec(int oc){
  if(oc<-5){//if the outside temp (in c) is less than -5
    re=1;//change re to "wear warm jacket"
  }
  else if(oc<12){//etc...
    re=2;
  }
  else if(oc<16){
    re=3;
  }
  else if(oc<21){
    re=4;
  }
  else{
    re=5;
  }
}



int checkButtons(int b1, int bc) {
  int b = digitalRead(b1);//make the variable b what is read on b1
  if (b == 1) { //if b (the reading of b1) is HIGH (pressed)
    if (background < 4) {
      background++;
    }
    else if (background == 4) {
      background = 1;
    }
  }

  b = digitalRead(bc);
  if (b == 1) {
    if (cf == 0) {
      cf = 1;
    }
    else if (cf == 1) {
      cf = 0;
    }
  }
  return background;// return the background int
  return cf;//return the celsius/fahrenheit int
}

Credits

Comments