Introduction: Configuring the Sensor

Picture of Configuring the Sensor

The following information is a single lesson in a larger project. Find more great projects here.

Return to Previous Lesson: Writing the Code

Lesson Overview:

Now we'll configure the temperature sensor!

Step 1: The Simulated Circuit (1)

In the previous step, you might have noticed that it's hard to adjust the input temperature over a really narrow range. If you want to see a more obvious change in bar graph lights, you can increase the range that you are looking at by changing the arguments in the if() and else if() statements.

How would you modify the code to do the following:

Turn on one LED if the temperature is between 20 and 40 degrees C (20 degrees above baseline).

Turn on two LEDs if the temperature is between 40 and 60 degrees C.

Turn on all three LEDs if the temperature is between 60 and 80 degrees C.

  1. Try changing the code using the suggestion above.

  2. Continue to the next step to see our solution!

Step 2: The Simulated Circuit (2)

Our example code for the if() and else if() statements is below!

  1. if(temperature < baselineTemp){ digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); } else if(temperature <= baselineTemp+20 && temperature < baselineTemp+40){ digitalWrite(2, HIGH); digitalWrite(3, LOW); digitalWrite(4, LOW); } else if(temperature <= baselineTemp+40 && temperature < baselineTemp+60){ digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, LOW); } else if(temperature >= baselineTemp+60){ digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); }

  2. Upload the code while the simulator is running and try moving the slider on the temperature sensor again.

  3. After trying the above code in the Code Editor, you can try creating your own if()...else statements!

  4. Continue to the next step.

Step 3: Your Arduino Kit

Picture of Your Arduino Kit

If you have the physical Arduino kit, you can try to activate the sensor using your fingers. In our example photo below, we customized our LED color!

The bar graph output might not work exactly as you might expect. Follow the instructions below to calibrate the temperature sensor to fit your room's baseline temperature and the temperature of your skin.

  1. Place your fingers around the sensor while it is plugged into the breadboard and see what happens to the values in the serial monitor. Make a note of what the temperature is when the sensor is left in the open air by referring to the serial monitor.
  2. The project might not do what you want it to if the room temperature is really cold or really warm, or if your fingers are cold!
  3. Close the serial monitor and change the baselineTemp constant in your program to the value to what you observed for the room temperature. Upload your code again, and try holding the sensor in your fingers. As the temperature rises, you should see the LEDs turn on one by one.
  4. Continue to the next step.

Step 4: Think About It...

Can you think of a way to create an interface for two people to test their compatibility with each other? You get to decide what compatibility means, and how you’ll sense it. Perhaps they have to hold hands and generate heat? Would you need two sensors? What do you think?

You can also expand the types of inputs you can read! You have used the analogRead() and the serial monitor to track changes inside your Arduino. You will use other types of sensors in future projects!

  1. Continue to the next step.

Step 5: Review

Congratulations on completing the Love-o-Meter!

In this project, you interpreted data from an analog temperature sensor that outputs a varying voltage. Using a datasheet is a good way to map your voltages to a physical property that you want to measure, like temperature. However, you still might need to go through a calibration process when you project is complete to make sure it works exactly the way that you want it to!

  1. Continue to the next step to learn how to customize your Love-o-Meter.

Next Lesson:Love-o-Meter Template


About This Instructable




Bio: Learn electronics and Arduino with Tinkercad Circuits!
More by circuits:IntroductionProject 15: Hacking ButtonsProject 14: Tweak the Arduino Logo
Add instructable to: