Week 8 | Untoolkit - Electronic Outputs

This week we continue to untoolkit technological making processes. Besides designing our own inputs, we will now increase our coding prowess by building our own outputs too.

First some new theory

Diodes The key function of an ideal diode is to control the direction of current-flow. Current passing through a diode can only go in one direction, called the forward direction. Current trying to flow the reverse direction is blocked. They're like the one-way valve of electronics.

If the voltage across a diode is negative, no current can flow, and the ideal diode looks like an open circuit. In such a situation, the diode is said to be off or reverse biased.

As long as the voltage across the diode isn't negative, it'll "turn on" and conduct current. Ideally a diode would act like a short circuit (0V across it) if it was conducting current. When a diode is conducting current it's forward biased. Source: https://learn.sparkfun.com/tutorials/diodes/all Transistors The Arduino can only provide 40mA at 5V on its digital pins. Most motors require more current and/or voltage to operate. A transistor can act as a digital switch, enabling the Arduino to control loads with higher electrical requirements. The transistor in this example completes the motor's circuit to ground. This example uses a TIP120, which can switch up to 60V at 5A.

When PWMing a transistor, it's similar to pulsing an LED. The higher the PWM value, the faster the motor will spin. The lower the value, the slower it will spin.

Transistors have three pins. For Bipolar Junction Transistors (BJT), like the one used used in this example, the pins are called base, collector, and emitter. A small amount of current on the base pin closes a circuit between the collector and emitter pins. BJTs come in two different types, NPN and PNP. The TIP120 is a NPN-type transistor, which means the collector will connect to the motor, and the emitter will connect to ground. Source: https://www.arduino.cc/en/Tutorial/TransistorMotorControl

LED circuit with button

To connect the LED I used the example on DLO. I tested the analog and digital code. They both work.

DC motor circuit without button

Above, without code. Later this week, I made the circuit again and attached some code to experiment with the motor.

int motorPin = 10;

void setup() {
   pinMode(motorPin, OUTPUT);
   Serial.begin(9600);
   while (! Serial);
   Serial.println("Speed 0 to 255");
}

void loop() {
   if (Serial.available()) {
      int speed = Serial.parseInt();
      if (speed >= 0 && speed <= 255) {
         analogWrite(motorPin, speed);
      }
   }
}

I used the code above to speed the motor up and and down. By writing a number between 0 and 255 in the Serial Monitor.

Below, I turned the motor on and off with HIGH an LOW, with a very simple code.

int motorPin = 9;
void setup() {
 pinMode(motorPin, OUTPUT);
}
void loop() {
 digitalWrite(motorPin, HIGH);
 delay(1000); 
 digitalWrite(motorPin, LOW);
 delay(1000);
}

The used the code above to let the motor go on and off.

Processing: yellow LED on/off with a computer mouse

My first sketch with Processing 3 is based on this tutorial found on Youtube.

First, I wrote the following code in Arduino IDE

const int ledPin = 13;

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

}

void loop() {
if(Serial.available() > 0) {
  char ledPinState = Serial.read();
  if (ledPinState == '1'){
    digitalWrite(ledPin, HIGH);
  }
    if (ledPinState == '0'){
      digitalWrite(ledPin, LOW);
    }
    
  }
}

As you can see, I defined pin 13, then I made sure that pin 13 is the output (the LED). Next, I used an if statement to let the circuit do what it has to do when the value is 1 or 0. I uploaded this on the Arduino board.

After uploading, I set up the circuit on the Arduino board as you can see below.

Thereon, I opened Processing 3. I searched a png-image on google of a yellow LED and added this in the same map of the sketch I was coding.

My sketch on Processing 3 consisted the following code:

import processing.serial.*;

Serial myPort;

PImage bg;

void setup(){
  size(320, 240);
  bg=loadImage("Yellow-LED.png");
  
  myPort = new Serial (this, "/dev/cu.usbmodem1421", 9600);
}

void draw(){
  background(bg);
  if(mousePressed && (mouseButton == LEFT)){
    myPort.write('1');
  }
  if(mousePressed && (mouseButton == RIGHT)){
myPort.write('0');
  }
}

In the first line, i'm importing the library for a serial communication. In the third line, i'm defining a name for the serial: I used myPort.

Then, a background image. This will be the png-image I added in the map. In the void setup(), I'm defining the size and pick the image. Also I pick the USB-port where my Arduino board will get the power of.

Void draw() works almost the same as void loop() known in Arduino. Here I use if statements which will work when you click (right or left) with the computermouse on the background (png-image of the LED).

If its clicked, it will send a 1 to the other code (Arduino IDE). This code says: If the state is 1, the LED will go HIGH (on).

Plugging the Arduino board in the port devined in the code, plugging in the mouse in the computer and clicking on the 'play' button will bring the result below.

How can you make hardware look interesting/appealing/evocative?

I tried to make a wheel out of the DC motor.

With that wheel, I want to make something that can drive or maybe something else. I didn't had good and sturdy materials at home so it didn't workout well.

I had an empty toilet roll and an empty sprinkles pack. I made wheels of the toilet roll (too weak and not sturdy at all) but it's for the idea.

I carried the Arduino, breadbord and powerbank in the empty sprinkles pack which should present the deck.

I think the wheel will work with better materials. Maybe I can make it with wood. The only question then is if it wouldn't get too heavy.

Reflection

The experiments with the DC motor helped me understanding Arduino IDE better. In the future I want to experiment more with processing because I saw a lot of beautiful artwork that's made of it. Unfortunately I didn't have enough time for that because I also had to finish the other assignments of the other weeks.

Last updated