comment 0

Physical Computing [Lab 03.a]: Servos and LEDs and Motors, Oh My!

This week we started experimenting with a bunch of different components, from DC motors…

Week 3 Servo

…to servos…

Week 3 Servo

…and light dependent resistors!

Week 3 LDR

The above motor and servo experiments were created using code from the Arduino examples, and the automatic night light was built from this article.

After getting these components to work, we had a couple of tasks to complete. First of all, was to solder three LEDs and resistors to some perf board, then make them blink randomly. I busted the leftmost LED at some point, but can demonstrate that the circuit works by holding a fresh one to the back of the perf board.

Week 3 LED Random Flash

To make the LEDs blink randomly, I decided to use a random number generator. A random number between 0 and 299 was rolled; if it was between 0-99, the LED on pin 13 would flash; between 100-199 and pin 12 would flash; etc. Here it is in the code:

int rand = random(0,299);
int pin;
 if (rand >= 0 && rand <= 99){
   pin = 13;

 else if (rand >= 100 && rand <= 199){
   pin = 12;

 else if (rand >= 200 && rand <= 299){
   pin = 4; 

digitalWrite(pin, HIGH);
digitalWrite(pin, LOW); 

I’m not certain that this is the most elegant way of solving this problem (in fact I’m sure it’s not), but it works. And at this point, that’s all we can really hope for.

The final task for this week was to create a circuit by which a servo and LED could be controlled with one component. I chose to use the potentiometer, as I liked the direct relationship between the position of the servo and the pot; it seemed less gimmicky and more practical.

Week 3 Servo LED

Playing with this new toy, it suddenly struck me. As I turned the potentiometer, the servo began to point at me, and the LED lit up, almost like some kind of….human detector? So I decided to throw practicality to the wind and fully embrace gimmickry, and start building a fully-fledged human detector as my lab submission. See the results next time…

And, as always, you can see the code for this week on my GitHub.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s