Lab1 – Weather Detector

COS436 – Lab 1 Blog

COS436 – Human computer Interface

Lab 1 – Resistance is Not Futile Blog

Kevin Lee, Saswathi Natta, Andrew S. Boik, Brian W. Huang

Group Number 16

Description:

We built a weather detector using various sensors to detect different weather conditions. We use a flex sensor for detecting wind as it blows on it, an FSR for detecting hail as it hits it, a photocell for detecting sunlight, a Variable You-sistor for detecting rain when electricity is conducted between the two bare ends of the jumper wires through water on the ground, and a thermistor for detecting temperature. The temperature is printed to the screen, while the other sensors have LEDs that correspond to them. The LED will turn on if the corresponding sensor reads a value that exceeds a threshold, in which case, the appropriate weather condition has been detected. We selected this project because we believe each sensor naturally has a corresponding component of weather that it is suited for detecting, and being able to detect weather conditions is a very useful, practical application of the tools provided in this lab.  In our opinion, the project was largely a success. We liked how our light sensor, flex sensor, photocell, and themistor all detect their weather components accurately. We however think that our FSR is not well suited as a hail sensor. This is because it seems to require a fair bit of weight to be on top of it to register any significant readings, so it is uncertain whether ice will be detected on top of it.. Realistically, the FSR would also probably break if hail were to fall directly on top of it. Had we had time, we also would have designed a container for our device so that the device doesn’t become damaged under intense weather conditions.

Sketches of Early Ideas

A weather detector that detects various weather conditions.

A weather detector that detects various weather conditions.

A primitive instrument with continuously changing pitch and volume.

A primitive instrument with continuously changing pitch and volume.

A version of the bop-it game.

A version of the bop-it game.

Storyboard for Weather Detector:

Storyboard for weather detector.

Storyboard for weather detector.

Final System – Weather Detector:

Our weather detector with design sketch in view.

Our weather detector with design sketch in view.

Close up view of our weather detector.

Close up view of our weather detector.

Photo of our weather detector with sail for wind detection in view.

Photo of our weather detector with sail for wind detection in view.

List of parts:

– Arduino

– 4 LEDs

– 9 10k Resistors

– FSR

– Flex Sensor

– Thermistor

– Photocell

– Cardboard and paper

– Jumper wires

Instructions:

1. Setup LEDs and sensors

-Place the long end of each of the 4 LEDs to the chosen Arduino digital output pin and the shorter end to ground through 10k resistor

-Setup FSR, Flex sensor, Thermistor, Photocell, and Variable You-sistor (two jumper wires). All sensors are wired with a voltage divider, using 10k resistor to ground, between one pin connected to 5V power and the other pin connected to an Arduino analog input pin to detect the resistance. Each sensor gets its own analog input. Tape cardboard to the base of the flex sensor for flexibility and a paper sail to the top of it to make it sensitive to wind.

2. Test baseline for sensors and adjust thresholds as necessary

-Once the sensors are connected, with the proper (~10K) voltage divider connected to power on one pin and the other pin connected to the Arduino, the Arduino software will display it’s reading of the input. For each sensor, test it with appropriate weather conditions to see how the readings change to determine appropriate thresholds.

-FSR, Flex sensor, Photocell, and Variable You-sistor all have corresponding LEDs that will turn on when threshold is passed. FSR LED signifies hail, flex sensor LED signifies wind, photocell LED signifies sunlight, and Variable You-sistor LED signifies rain.

Code:

/* Weather sensor for L2
 * Lab Group 16 (old 21):
 * Andrew Boik (aboik@)
 * Brian Huang (bwhuang@)
 * Kevin Lee (kevinlee@)
 * Saswathi Natta (snatta@)
 */

// pin inputs
int thermistor_pin = A0;
int flex_pin = A1;
int photo_pin = A2;
int fsr_pin = A3;
int wet_pin = A4;

// led outputs
int wind_led = 13;
int sunny_led = 12;
int hail_led = 11;
int rain_led = 10;

// thresholds for led light-up
int wind_thresh = 300;
int sunny_thresh = 800;
int hail_thresh = 10;
int rain_thresh = 10;

// led max brightness
int led_max_val = 255;
// led min brightness
int led_min_val = 0;
// delay time
int delay_time = 500;

// timeouts for hail/rain and time since last event
unsigned long hail_timeout = 5000;
unsigned long rain_timeout = 5000;
unsigned long time_since_last_rain;
unsigned long time_since_last_hail;

void setup(void) {

 time_since_last_rain = rain_timeout;
 time_since_last_hail = hail_timeout;

 Serial.begin(9600); 
 pinMode(wind_led, OUTPUT);
 pinMode(sunny_led, OUTPUT);
 pinMode(hail_led, OUTPUT);
 pinMode(rain_led, OUTPUT);
}

void loop(void) {

  // get readings
 int temperature = analogRead(thermistor_pin);
 double true_temp = (temperature - 345.684) / 5.878;
 int wind = analogRead(flex_pin);
 int sunny = analogRead(photo_pin);
 int hail = analogRead(fsr_pin);
 int rain = analogRead(wet_pin);

// print out vals from sensors
 Serial.print("Temperature = ");
 Serial.println(true_temp);
 Serial.print("Wind = ");
 Serial.println(wind);
 Serial.print("Sunny = ");
 Serial.println(sunny);
 Serial.print("Hail reading = ");
 Serial.println(hail);
 Serial.print("Rain reading = ");
 Serial.println(rain);
 Serial.println();

 // led light-up
 if (wind > wind_thresh)
   digitalWrite(wind_led, led_max_val);
 else
   digitalWrite(wind_led, led_min_val);
 if (sunny > sunny_thresh)
   digitalWrite(sunny_led, led_max_val);
 else
   digitalWrite(sunny_led, led_min_val);
 if (hail > hail_thresh) {
   time_since_last_hail = 0;
   analogWrite(hail_led, 255);
 }
 else if (time_since_last_hail < hail_timeout) {    Serial.print("time_since_last_hail = ");    Serial.println(time_since_last_hail);    time_since_last_hail += delay_time;    analogWrite(hail_led, 255);  }  else {    time_since_last_hail += delay_time;    analogWrite(hail_led, 0);  }  if (rain > rain_thresh) {
   time_since_last_rain = 0;
   analogWrite(rain_led, 255);
 }
 else if (time_since_last_rain < rain_timeout) {
   Serial.print("time_since_last_rain = ");
   Serial.println(time_since_last_rain);
   Serial.println();
   time_since_last_rain += delay_time;
   analogWrite(rain_led, 255);
 }
 else {
   time_since_last_rain += delay_time;
   analogWrite(rain_led, 0);
 }

 delay(delay_time);
}