Intro to Physical Computing (Arduino)

Albert Hodo
Bootcamp
Published in
2 min readSep 7, 2022

--

Albert Hodo — Tangible User Interfaces, Fall 2022.

Description: Set up an Arduino environment and test out the blink code. Modify the code to include any extra features. This Lab is meant to help get started and set up an Arduino programming environment on your laptop. You will learn how to upload a program to your Arduino and construct a simple circuit to blink a LED.

Blinking The Hardware LED (Arduino “Hello World”)

The Blink example is very similar to that of a “Hello World” in programing. It introduces you to the concept of using an Arduino and also allows you to get started with the components.

In this Lab, I tested the Blink program on the Arduino board and modified it to include an Photoresistor (LDR sensor) to turn the LED off when the environment is well lit. If it got darker, the LED would blink rapidly.

I set the limit of the LDR input to 200. Any reading less than 200 denoted no light and would prompt the LED to blink in quick succession.

Components Used

1. Arduino Uno

2. 5-Jump wires

3. 2- 20 omh Resisisters

4. 1-Photoresister (LDR sensor)

5. 1- LED

arduino set up with breadboard, ldr, led and wires

Arduino Blink and LDR Code

/*Blink with ldrTurns an LED on for one tenth of a second, then off for anotherone tenth of a  second, repeatedly if the place is darkand turns it off if the place is well lit*/
const int led=13;const int ldrPin = A0;// the setup function runs once when you press reset or power the board
void setup() {Serial.begin(9600);pinMode(led, OUTPUT);pinMode(ldrPin,INPUT);}
// the loop function runs over and over again forevervoid loop() {if (analogRead(ldrPin)>=200){// it is well litSerial.print("it is well lit");Serial.println(analogRead(ldrPin));//digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)delay(1000); // wait for a seconddigitalWrite(led, LOW); // turn the LED off by making the voltage LOWdelay(1000); // wait for a second}else{ //it is darkSerial.print("it is dark");Serial.println(analogRead(ldrPin));digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)delay(100); // wait for half a seconddigitalWrite(led, LOW); // turn the LED off by making the voltage LOWdelay(100);}}

Demo: When the phone gets closer to the LDR, it blocks the light source and the LED begins to blink. When the phone is taken away, the LED stops blinking.

--

--

I’m a first year MDes student at UC Berkeley. A master’s jointly run by the College of Engineering and Environmental Design. I love outer space and tangible UI.