Combine Light and Temperature/Humdity

1. Let's try to run two sensors at the same time

2. Make sure your device is not powered

Hook your sensors as shown on the left. It doesn't matter which end of the sensor you hook to the cable, however, the cable only plugs into each of the sockets in one direction.

The order of the sensors does not matter.

3. We must combine the previous code examples, but you cannot just paste one after another. Consider the following:

  • Libraries are always imported at the beginning of the sketch

  • Don't import libraries more than once

  • Declare all variables and objects at the top of the code (before the main loop function)

  • There can only be one "While True:" loop

  • Don't repeat lines of code that you don't absolutely have to

  • "time.sleep( )" will affect how often everything happens. Use this line strategically.

Try to combine the light sensor and temperature sensor codes on your own first. If you can't get it to work, look at this example that has everything but the value printing laid out.

4. Note that your light sensor is just called "sensor" in the code. That will be confusing as we add more sensors. Change the name to something more descriptive an make sure everything still works.

Challenges:

  • Can you print all the data as a single sentence? Make it into a paragraph that really tells you about how the current conditions feel. Give it some personality!

  • Print the temperature and light value every 15 seconds but the humidity value only once every 30 seconds.