Due at the start of Class 4
Your homework for Monday has two parts:
1) Build an adjustable nightlight. (~4 hours)
Inputs: a photoresistor (tutorial), a potentiometer, and a button or switch. Outputs: an LED and some
Nightlight operation: when it gets darker in the room, the LED should turn on. When it gets brighter, it should turn off.
Turning the potentiometer should adjust the “setpoint,” i.e. the threshold at which the light turns on/off.
Reverser switch/button: there is a button or switch (your decision), that, when you push/switch it, changes the nightlight to a daylight. That is to say, it turns on when it’s bright out, and off when it’s dark out. The potentiometer still adjusts the setpoint just as it did before.
Serial feedback: in order to help understand what the Arduino is seeing, and how bright the room is, add some
Serial feedback that looks like this:
room brightness: 320; setpoint is: 300; switch is: NIGHTLIGHT; LED is: OFF room brightness: 100; setpoint is: 300; switch is: NIGHTLIGHT; LED is: ON room brightness: 100; setpoint is: 300; switch is: DAYLIGHT; LED is: OFF
Recommended general plan of attack for this assignment: add only one component at a time. Maybe start with only the photosensor, make sure it’s working (the
Serial feedback will help a lot with that), make sure it’s working, etc. Build towards the goal, and stop at ~4 hours (or keep going if you want!). If you complete the assignment, great, and if not, any progress is good progress. We’re at the learning-a-lot-very-quickly stage of the course, which is coincidentally also the this-is-too-much-at-once stage.
You will be showing your work at the start of class on Monday.
Some code hints to help you get started if you’re not sure where to begin
First, begin by gathering data about the world. In the
setup(), use the
pinMode() commands to tell the Arduino where everything is plugged in, and what things are inputs and what things are outputs. Also, in the
setup(), don’t forget to add the command to begin
Then, in the
loop(), begin by gathering information like this:
Now you have to write the instructions that will turn the LED on or off. It’s a simple question that the code needs to run: is the brightness value lower than the potentiometer value? If so, turn on the LED. If not, turn off the LED.
This will set you on your way, but there’s things I left out. For instance, I haven’t told you how to add the logic to make it so that the switch reverses the behavior of the LED to make it into a daylight. The exercise is left to the reader!
Remember to use the built-in reference system in the Arduino software if you’re confused about how to use any functions. For instance,
if() is something we haven’t talked about in class so check out the reference page for information about how to use it.
2) Coordinate with your partner to begin working on Project 1. (~2 hours)
You are free to do this as you like, but at the least, each partner should independently sketch out 5 simple doodles of ideas they have for this project, with a sentence or two of explanation, and share them with the other. This first project is as much about ideation as it is about the technical build and settling on an interesting idea early on will give you time to build an iteration or two and change your path along the way. So don’t put it off!