All about ubiquitous computing!

Sketching with Hardware – More Building Blocks

How to change the intensity of an LED?

We can switch a digital output on or off – there is no analog output but we still want to set the intensity (e.g. brightness of an LED or how strong a motor creates vibrations). The simple approach for this is to switch the output on and off – and to this really fast. This is called Pulse-Width-Modulation (PWM).

Your task is to program a function call LED_PWM(time, intensity). The parameter time is the duration the LED should be on in milliseconds and the intensity is a value between 0 and 100. For example, if I call LED_PWM(3000, 50) the LED is on for 3 seconds with 50% intensity.

How fast do you need to switch between on and off that your eye cannot see a flickering light but rather a lower intensity? Try this with an LED.

Does it work with a motor? Try it out.

Servos – making things move

A servo is a motor, where you can program in what angle it points. There is a library that makes this really easy (https://www.arduino.cc/en/Reference/Servo). Connect a servo and move it (look for an example Sweep) and also link it to an input (e.g. the example knob). If you have some time try to understand what the library does – how do you communicate the value to the servo? compare this to the PWM we saw earlier.