1 / 11

Lesson 4 : Breathing Monitors

Lesson 4 : Breathing Monitors. Breathing Monitors. In the past 3 classes, we’ve learned How to write to a digital pin How to read the value of a digital pin How to read the value of an analog pin IF statements

karl
Download Presentation

Lesson 4 : Breathing Monitors

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lesson 4: Breathing Monitors

  2. Breathing Monitors • In the past 3 classes, we’ve learned • How to write to a digital pin • How to read the value of a digital pin • How to read the value of an analog pin • IF statements • Today we’ll put these skills together to build a medical device - a breathing monitor.

  3. New Component • Thermistor • Variable resistor • Resistance depends on temperature

  4. Set Up Your Device Hook up LED: Hook up thermistor and potentiometer: to ground to digital output pin Remember: The middle leg of the potentiometer goes to analog in; one outer pin goes to ground and the other to power.

  5. What will the program do? • Turn an LED ON when we breathe out • Turn the LED OFF when we breathe in.

  6. Your Turn • Initialize variables: • Define digital pin for the LED • Define analog pin from the potentiometer • Define variable you will store analog value! • Set up: • pinMode(digitalPin, OUTPUT); • Loop: • Use analogRead • Use a conditional IF-Statement HINT: This is VERY similar to the analogRead program you wrote last time!

  7. Add an Alarm • Now we want a SECOND LED to turn on if there is no breathing for 10 s. • We need to add another variable for a 2nd LED • We need a way to measure the time that has passed in the program. • Function: millis(); • Returns the time since the program began in milliseconds • NOT an integer! New data type ..

  8. Unsigned long • millis() returns a number of type “unsigned long” • When you initialize the variable that will store the value from millis(), it will look like: • unsigned longstart_time = 0; • Now the variable start_time can be added/subtracted/multiplied to other variables ONLY if they are also unsigned long

  9. Example Program: unsigned long time = 0; // variable to store the time. Note // the different data type unsigned long alarm_time = 10000; // value in ms. Amount of time // that needs to pass before // the alarm will go void setup() { time = millis(); // initialize time } void loop(){ if ((millis() – time) > alarm_time) { //do something! } } KEY POINT: ((millis() – time) > alarm_time) What does this statement say in English? * All of the values are of type unsigned long

  10. TRANSLATE to build your final projects! There are 6 variables: an analog pin, a variable to store the analog value, a pin to make the monitor LED turn on/off, a pin to make the alarm LED turn on/off, a variable to store the time, and a variable to store the amount of time to wait until the alarm goes off! In the setup function, you’ll need to declare that the two LED pins are outputs. You’ll also need to store the initial time. In the loop, first you need to read the value from the sensor and store it in one of your variables. Next, check to see if 10 s have passed. If they have, turn on the alarm LED. If they have not, turn off the alarm LED. Then, check to see if the breathing sensor is above the threshold. If it is, turn on the monitor LED. ** At this point you’ll also have to reset the time. This way, you’ll always be measuring the time since the last time the a breath occurred **. Lastly, if the breathing sensor is below the threshold, turn the monitor LED off.

  11. Finally … Breathing Monitors!

More Related