Created
February 9, 2015 03:51
-
-
Save commak/b83d7838fd2748f16da9 to your computer and use it in GitHub Desktop.
Code for sensitive wearable project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Kama Kaczmarczyk #2483626 | |
//GDES3B16 Kate Hartman | |
//Sensitive Wearable | |
// Button with LED | |
int ledPin = 6; // LED is connected to digital pin 6 | |
int switchPin = 5; // button is connected to digital pin 5 | |
int switchValue; // a variable to keep track of when switch is pressed | |
//Temperature Sensor | |
float supplyVoltage = 3.7; // Voltage | |
int tempSensorPin = A3; // Temperature Sensor is connected to pin A3 | |
int tempSensorValue = 0; | |
int threshold1 = 8; // Value for readings | |
float tempSensorVoltage; | |
//Light sensor | |
int lightSensorValue = 0; | |
int lightSensorPin = A2; //Light sensor is connected to pin A2 | |
int threshold2 = 100; // Value for readings | |
void setup() | |
{ pinMode(ledPin, OUTPUT); // sets the ledPin to be an output | |
pinMode(switchPin, INPUT); // sets the switchPin to be an input | |
digitalWrite(switchPin, HIGH); // sets the default (unpressed) state of switchPin to HIGH | |
// initialize serial communication at 9600 bits per second: | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
switchValue = digitalRead(switchPin); | |
if (switchValue == LOW) { // if the switch is pressed then, | |
digitalWrite(ledPin, HIGH); // turn the LED on | |
} | |
else { | |
digitalWrite(ledPin, LOW); // turn the LED off | |
} | |
// read the temperature sensor value | |
tempSensorValue = analogRead(tempSensorPin); | |
// convert the reading to voltage based off the reference voltage | |
float tempSensorVoltage = (tempSensorValue * supplyVoltage)/1024.0; | |
// convert the reading to Celsius | |
// converting from 10 mv per degree with 500 mV offset | |
float temperatureC = (tempSensorVoltage - 0.5) * 100; | |
// to degrees ((tempSensorVoltage - 500mV) times 100) | |
// print in Celsius | |
Serial.print("Degrees C: "); | |
Serial.print(temperatureC); | |
// if the value is greater than threshold #1 | |
if(temperatureC<threshold1){ | |
Serial.println("cold"); | |
} | |
else{ // otherwise | |
Serial.println("warm"); | |
} | |
delay(100); | |
// read the light sensor pin and store value in a variable: | |
lightSensorValue = analogRead(lightSensorPin); | |
// print the light sensor value | |
Serial.print("Light Sensor Value: "); | |
Serial.print(lightSensorValue); | |
// get ready to print light level | |
Serial.print(", Colour: "); | |
// if the value is greater than threshold #1 | |
if(lightSensorValue>threshold2){ | |
Serial.println("WHITE"); | |
} | |
// otherwise | |
else{ | |
Serial.println("BLACK"); | |
} | |
// delay between readings: | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment