Basic Circuits Redux

Introduction to Physical Computing

14 Sep 2018

Today I wanted to take another look at last week’s lab and see if I could push it further. Last week I made a simple circuit to light an LED and I gave myself a challenge of seeing how many ways I could make the LED blink.

Analog Circuit

I first started by making an analog circuit using an LM555 timer. El-Pro-Cus was really useful for this section.

Circuit Diagram

![LM555 Setup][basic1]

I followed this diagram and I received mediocre results. While the LED blinked, it was blinking really fast that it barely appeared to blinking. I think it is because I used the wrong resistors. (I couldn’t locate 1KΩ resistors so I grabbed what the closest ones I could find)

Arduino

Basic Circuit

Excuse my extremely poor image quality.

With LM555

The next challenge was to make it blink using a microcontroller. (Earlier iterations only used my ‘duino to power my breadboard) Having already made the circuit, it was trivial to load it and get blinking.

It was based the built-in example.

// set LED pin
#define LED_BUILTIN 13
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}


void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   
  delay(1000);             
  digitalWrite(LED_BUILTIN, LOW);   
  delay(1000);               
}

Interface with Processing

guide

My next challenge was to use Processing to make my little light blink. Basically the major step was to create a Serial Connection between Processing and Arduino. This step is not so complicated, but kind of a lot to keep track of whats going on. You basically have to send signals back and forth through your serial port.

Arduino:

char val;
int ledPin=13;

void setup(){
    pinMode(ledPin, OUTPUT);
    Serial.begin(9600);
}

void loop() {
    if (Serial.available()) 
    { to read,
        val = Serial.read(); 
    }
    if (val == '1') 
    { 
        digitalWrite(ledPin, HIGH);
    } else {
        digitalWrite(ledPin, LOW);
    }
    delay(10);
}

Processing (only showing the serial event function):

void serialEvent( Serial myDuino){
  val = myDuino.readStringUntil('\n');
  if(val!=null){
    val = trim(val);
    println(val);
    
    if(firstContact == false) {
      if(val.equals("A")){
        myDuino.clear();
        firstContact = true;
        myDuino.write("A");
        println("contact");
      }
    } else {
      println(val);
      if(mousePressed == true){
        myDuino.write('1');
        println('1');
      }
        myDuino.write("A");
      
    }
  }
}

Next

This was a pretty fun challenge for myself. I’m still thinking about more things I would like to do, but I think next would be to use different boards since I have an ESP8266 and a Raspberry Pi. I’ll try blinking with other languages as well especially: micropython, c++, OpenFrameworks, and javascript.