Arduino Ladder · Bozoma Innovation Hub

Band 4  ·  Night Guard

Practice  The dimmable lamp

A knob and a light, with three traps in it you can find with a pen before you find them with the board. One of them is Band 6 arriving two bands early.

Time
35 min
You need
1 LED on a ~ pin, 1 resistor, 1 potentiometer, 7 jumper wires (plus the light sensor and its 10kΩ if you do the Silver)
At once
Everybody at once
Before this
Finish Band 2 and Band 4 up to Part 6. No sketch is given.

Sketches for this project

Every file opens with a plain-English header saying what it does and how to wire it, hole by hole.

The job

A lamp you can turn down

A knob and a light. Turn the knob and the light follows, smoothly, over the whole travel. Right down means off. Right up means full.

That sounds like the easiest thing on this page and it has three traps in it, all of which you can find with a pen before you find them with the board.

You have built a version of this already. b4_02_pot_dim_led.ino, in Band 4 Part 6, is a knob-driven lamp. Do it from scratch this time without opening that file, and the three traps below are exactly the ones that sketch quietly solved for you while you were reading it.

You needYou already did it in
analogWrite and why the pin needs a ~Band 2, Parts 2 and 5
analogRead, and the 0 to 1023 it gives youBand 4, Parts 3 and 5
map, for turning one range into anotherBand 4, Part 6
Think first

Three traps, on paper

10 min
  1. The two ranges are not the same size. analogRead hands you 0 to 1023. analogWrite wants 0 to 255. Feed one straight into the other and only the first quarter of the knob behaves.

    Predict what the other three quarters do, and write your prediction down before you build it. Does the lamp just stay bright once it passes 255? Something stranger? Then build it and turn the knob slowly from stop to stop, counting how many times the light goes from full bright to dark. Most people's prediction is wrong, and the real answer tells you something true about how the board stores a number.
  2. Your knob probably does not reach both ends. Most do not quite make 0, and most do not quite make 1023. If yours stops at 12, your lamp never goes fully off. You will have to measure your own knob, exactly as Band 4 made you measure your own room.
  3. Your eye is not a straight line. Going from 0 to 60 looks like an enormous change. Going from 195 to 255 looks like almost nothing. So a knob that is mathematically even will not feel even, and no amount of careful code fixes that, because the unevenness is in you.
Build

Build it, measure it, then fix what you find

25 min
Wiring, and use these two parts and not the ones you might expectBand 4 Part 5 for the knob, and Band 4 Part 6 for the light. Both hole by hole, both inside what you have already done.

Both bring rail wires with them, and so does the wire nobody counts: one from the − rail to a GND pin, and one from the + rail to 5V for the knob's power leg. Band 4 Part 5 names them. Rebuild without them and the knob reads nonsense rather than nothing, which is harder to spot.

Not Band 1 Part 5 for the light, even though that is the one you remember. Band 1 puts its LED in f5 and f6, and Band 4 puts the knob's legs in f5, f6 and f7. Same holes. Band 4 Part 6 already moved the light out of the way, to f20 and f22, and it already put it on pin 9, which has the ~ this build needs. It also uses the same top − rail as the knob.

First, print your knob before you drive anything with it. Turn it slowly all the way from one stop to the other, watching the serial monitor.

Write down two numbersThe lowest it ever shows and the highest it ever shows. These are yours and nobody else's. Somebody at the next table will have different ones.

Now drive the lamp, using your two measured numbers rather than 0 and 1023.

The checkRight down, the light is completely off. Not a faint glow. Right up, it is full. Everywhere in between it moves.
If it will not go fully offYour bottom number is wrong, or you used 0 when your knob's floor is 12. Two ways out and they are not the same: widen the range you mapped from, or add a line that says below some reading, write a real zero. The second is more honest about what you want, and it is the same shape as the deadband you meet in Band 6.

Hold the knob completely still and watch the light for thirty seconds.

Watch the serial monitor first, not the light. The reading wanders by a count or two with nothing touching the knob. That is the thing that is real.

Then look at the lamp. You may see a faint shimmer in the dim third, and you may see nothing at all: two counts out of 1023 is under half a step out of 255, which is often invisible. Either way the wobble is there and it is being written to the light on every round.
Fixing that is optional here and compulsory in Band 6The fix is to ignore any change smaller than a few counts. It has a name, and Band 6 spends a whole part on it, because on a servo the same wobble makes an arm buzz instead of a lamp shimmer. You have just met the problem two bands before the lesson. Write down what you saw so you recognise it when it is named.
Change it

Two ways further

Bronze
Make the bottom half of the knob's travel cover the bottom quarter of the brightness, so the dim end gets more room. Your eye will thank you. Then say in one sentence why that is a better lamp and a worse instrument.
Silver
Swap the knob for the light sensor, so the lamp gets brighter as the room gets darker. Careful: that is not just reversing the numbers, because a lamp that lights the room it is measuring will chase itself. Point it away, and write down what happened when you did not.
Done

Keep

  • Your knob's two real numbers, lowest and highest
  • Your prediction for trap 1, written before you built it
  • What you saw when you held the knob still, in your own words

Ship it

This one is yours. Nobody handed you a sketch for it, so the code in your video is code you wrote. Say that in the post, because it is the difference between somebody who can follow a tutorial and somebody who can build a thing, and it is the difference an employer is looking for.

The four shots as usual, and make the fourth one count: the check this page asked you to run, or the version that did not work first. Put a line of your own code on screen for three seconds. Almost nobody does, and it is the most convincing three seconds in the video.

Show your work has the template. Tag it #BozomaBuilds.