Newbie here doing an e-textile project during a 4-week training on wearables. So, didn't even know the existence of Arduino 2 weeks ago. Trying to figure out how to make the VibeBoard work in all of this. Ive read that we would need a resistor? It seems to compile fine but not sure why its not working. The temperature variables can be changed. The idea is the hotter it gets, the LED will too. Any advice will help.
Thanks.
/*
This code reads the input of the temperature sensor and compares it to
a five set thresholds.
If temperature is above or between the Alert threshold, the associated colored LED will turn on.
The vibe board will shake (or pulsate at different speeds) if yellow or red Alerts are reached.
******************************************************************************/
// Set colored threshold variables to check against. If TEMP reading is above/below
// this number in Celsius, it will turn different LEDs on.
float whiteAlert = 10.0; //
float blueAlert = 15.0; //
float greenAlert = 20.0; //
float yellowAlert = 25.0; //
float redAlert = 30.0; //
// Temperature sensor pin needs to be analog-capable
int sensorPin = 2;
// The LEDs (digital pins)
int ledPinW = 4; // Output pin for WHITE LED
int ledPinB = 5; // Output pin for BLUE LED
int ledPinG = 6; // Output pin for GREEN LED
int ledPinY = 7; // Output pin for YELLOW LED
int ledPinR = 8; // Output pin for RED LED
// The vibe board
int vibePin = 9; // Needs a resistor
void setup()
{
// INPUT: temperature sensor pin
pinMode(sensorPin, INPUT);
// OUTPUTS: All LEDs + VIBE board
pinMode(ledPinW, OUTPUT); // Between 35o and 36,9o
pinMode(ledPinB, OUTPUT); // Between 37o and 38,9o
pinMode(ledPinG, OUTPUT); // Between 39o and 39,4o
pinMode(ledPinY, OUTPUT); // Between 39,5o and 39,9o
pinMode(ledPinR, OUTPUT); // From 40o and +
pinMode(vibePin, OUTPUT);
// Initialize Serial, set the baud rate to 9600 bps.
Serial.begin(9600);
}
void loop()
{
// Variable to store raw temperature
long rawTemp;
// Variable to store voltage calculation
float voltage;
// Variable to store Celsius value
float celsius;
// Read the raw 0-1023 value of temperature into a variable.
rawTemp = analogRead(sensorPin);
// Calculate the voltage, based on that value.
// Multiply by maximum voltage (4.2V for USB power) and divide by maximum ADC value (1023).
voltage = rawTemp * (4.2 / 1023.0);
Serial.print("Voltage: "); // Print voltage reading to serial monitor
Serial.println(voltage);
// Calculate the celsius temperature, based on that voltage.
celsius = (voltage - 0.5) * 100;
Serial.print("Celsius: "); // Print celcius temp to serial monitor
Serial.println(celsius);
// Wait 5 seconds between readings
delay(5000);
// Turns on associated LED based on temperature
if (celsius >= whiteAlert and celsius < blueAlert)
{
digitalWrite(ledPinW, HIGH); // Led is ON
digitalWrite(ledPinB, LOW); // Led is OFF
digitalWrite(ledPinG, LOW); // Led is OFF
digitalWrite(ledPinY, LOW); // Led is OFF
digitalWrite(ledPinR, LOW); // Led is OFF
}
else if (celsius >= blueAlert and celsius < greenAlert)
{
digitalWrite(ledPinW, LOW); // Led is OFF
digitalWrite(ledPinB, HIGH); // Led is ON
digitalWrite(ledPinG, LOW); // Led is OFF
digitalWrite(ledPinY, LOW); // Led is OFF
digitalWrite(ledPinR, LOW); // Led is OFF
}
else if (celsius >= greenAlert and celsius < yellowAlert)
{
digitalWrite(ledPinW, LOW); // Led is OFF
digitalWrite(ledPinB, LOW); // Led is OFF
digitalWrite(ledPinG, HIGH); // Led is ON
digitalWrite(ledPinY, LOW); // Led is OFF
digitalWrite(ledPinR, LOW); // Led is OFF
}
else if (celsius >= yellowAlert and celsius < redAlert)
{
digitalWrite(ledPinW, LOW); // Led is OFF
digitalWrite(ledPinB, LOW); // Led is OFF
digitalWrite(ledPinG, LOW); // Led is OFF
digitalWrite(ledPinY, HIGH); // Led is ON
digitalWrite(ledPinR, LOW); // Led is OFF
// Turn motor ON/OFF as extra alert, forever or
// until falls under treshold or stop button pressed
digitalWrite(vibePin, HIGH); // Turn the motor ON to shake as an extra alert
delay(1000); // Wait 1 second
digitalWrite(vibePin, LOW); // Then turn the motor OFF
digitalWrite(vibePin, HIGH);
delay(1000);
digitalWrite(vibePin, LOW);
digitalWrite(vibePin, HIGH);
delay(1000);
digitalWrite(vibePin, LOW);
}
else // celsius < whiteAlert or celsius >= redAlert
{
digitalWrite(ledPinW, LOW); // Led is OFF
digitalWrite(ledPinB, LOW); // Led is OFF
digitalWrite(ledPinG, LOW); // Led is OFF
digitalWrite(ledPinY, LOW); // Led is OFF
digitalWrite(ledPinR, HIGH); // Led is ON
// Turn motor ON/OFF as extra alert, forever or
// until falls under treshold or stop button pressed
digitalWrite(vibePin, HIGH); // Turn the motor ON to shake as an extra alert
delay(250); // Wait 1/4 second
digitalWrite(vibePin, LOW); // Then turn the motor OFF
digitalWrite(vibePin, HIGH);
delay(250);
digitalWrite(vibePin, LOW);
digitalWrite(vibePin, HIGH);
delay(250);
digitalWrite(vibePin, LOW);
}
}