# Week 6 - Untoolkit: Electronic Inputs

## Zine

{% embed url="https://www.notion.so/Week-6-Quarantzine-a487c54bb09f40b4ad6dd49ef05e318e" %}

![Zine week 6 - Thijs Uffen](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M4FHN6aBzA7NFGvFH2H%2F-M4FL81htAVaFmxddDlw%2Fthijs_wk6_zine.png?alt=media\&token=87434b10-63cd-424b-a9e8-a1068641da08)

## Assignment

#### Design and build two inputs:

* Create an on/off switch (tact, toggle, slide, tilt or other)
* Also create an analog sensor (potentiometer, capacitive touch, other)
* Show at least 3 iterations (drawings, prototypes) before making the final paper sensor in black cardboard
* All the nodes should work as series, none can take visual supremacy
* The sensors shown in class are the point of departure for the series.\
  **You can recreate the technical circuit but not the form**

#### Program your circuit and test your inputs

* Program a Node MCU to read the values with the serial plotter
* Change an LED’s brightness depending on switch & sensor values

## Material

![How the breadboard works](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2gt6o_vcnqtYfyw5GR%2F-M2gyYKwP8gKEIrMPUJ-%2Fthijs_wk6_breadboard.jpg?alt=media\&token=cb9d9529-a44f-4122-8d91-ad4bffe5b5ea)

For this week, we are using a Node MCU and a breadboard. The Node MCU is an open-sourced firmware development kit. You can program code to manipulate electronics. One way to connect the Node MCU to electricity, is a breadboard. A breadboard is a switchboard where electronics can be attached to.&#x20;

![The Node MCU I am using.](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2gt6o_vcnqtYfyw5GR%2F-M2gzGxvgMlJ4MN7nsQl%2Fthijs_wk6_nodemcu.jpg?alt=media\&token=22c72ab5-b86d-48ea-851f-ba4aa418214b)

The Node MCU uses digital ports and analog ports to read out information. The software we use to upload code to the Node MCU is called Arduino.&#x20;

## Pinch switch (digital)

Because Kaz and I are working seperately, I am focussing on making Switches, and Kaz on analog sensors.

Loes showed us some awesome examples of switches, and I took some inspiration of them. The goal is to make these switches with&#x20;

* black cardboard
* copper tape
* paper clip pins
* LED&#x20;

For my first switch design, I wanted to use the herring grate origami pattern to fold a piece of paper. The goal is to pinch te paper, so the planes of the origami touch. When these planes are attached to copper tape and the paper clip pins, the circuit will be completed and the LED I attached on the circuit will light up.

To make the pattern on the piece of paper, I used the laser cutter to make dotted folding lines. I used 20% of the laser capacity, and made 2mm dots with 1 mm intervals. To give the structure more rigidity, I cut out holes on the corners of the folds. I used 50% of the laser capacity to do so.&#x20;

![The origami folding pattern](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2gt6o_vcnqtYfyw5GR%2F-M2hJ1lr0Lva72LKGor5%2Fthijs_wk6_origamifold.jpg?alt=media\&token=052cf9ef-812d-4b10-9065-ac3b17dfb375)

When I tried to fold the material, I quickly discovered that the paper is too small to support the folds. The paper is also too thick, so it would break if I tried to make complex folding patterns.

Because I had no access to the makers lab anymore, I decided to simplify the design. I only used the vertical lines I made, and cut out the center planes in a rectangular shape. On both sides I attached copper tape. When the paper is pinched, the copper tapes will touch.

![The iteration I made](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2gt6o_vcnqtYfyw5GR%2F-M2hKFOvWtrNjoV152Ir%2Fthijs_wk6_iterationorigami.jpg?alt=media\&token=cce28482-8578-4bb5-8692-3b78440a265e)

This switch is an 'always open' switch, because the two sides don't touch when idle. They can only make contact when you activate the switch (pinch), and will retract when you let loose.&#x20;

Now I can attach the design to my Node MCU. It is attached to a breadboard, so I can connect the switch and LED to it.

![My installation for the first switch.](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2gt6o_vcnqtYfyw5GR%2F-M2hL3f1nI983d3oFNA8%2Fthijs_wk6_installation.jpg?alt=media\&token=a8fe6739-1be3-4133-b742-955b9e08e4eb)

To illustrate the functioning of the switch, I've made a schematic.

![The schematic I am using](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2gt6o_vcnqtYfyw5GR%2F-M2hMHq1wtj_jBBX0x9t%2Fthijs_wk6_schematic.jpg?alt=media\&token=56ea01aa-778c-43ce-bbc4-4b5fa869fa15)

Ultimately, when I attached my Node MCU to a power source, the design worked perfectly. When I pinch the paper, the two copper tapes touch and they complete the circuit, just like a switch.

![](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2gt6o_vcnqtYfyw5GR%2F-M2hMYBs91gbQInEhBmU%2Fthijs_wk6_pinchswitch.gif?alt=media\&token=209caca3-4fcf-4026-b063-43ddf50a0f15)

## Analog capacitive sensor (made by Kaz)

### The following work is made by Kaz:

In class, the day before the schools closed the doors because of the corona virus, we made a crystal that is conductive. Loes showed her own crystal sensor and I really wanted to make one myself. So at first I started to build a capacitive sensor with a conductive crystal, but later on I also tried different conductive materials. This setup works with every conductive object.

### Conductive crystal

![](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2brjJA5UB5TyB1uMy7%2F-M2bs43Pfn_ojPr42SZk%2Fkaz_wk06_conductiveCrystal.jpg?alt=media\&token=20ae14df-c586-487c-99f7-a14301d3d501)

I just can't seem to get the setup to work. To my idea I've checked everything. I've checked if I've put `USB` behind every `serial` . I've checked if the I had connected the wires in the right way to setup the circuit. I've swapped the wires for other wires, to check if the wires are broken. After that I checked if the it works without the conductive crystal, so just with the paperclip. But the paperclip unfortunately doesn't work either, so I can't conclude that the crystal doesn't work.

![](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2bv5sa7-Fe3_RcRpkp%2F-M2byA9P93SsxOq8YKPV%2Fkaz_wk06_conductiveCircuit1.jpg?alt=media\&token=de22877f-46c3-4787-b5ed-a2803300790a)

The black wire looks like it isn't connected, but it is. It is connected to the same copper tape as the conductive crystal. The copper tape is one piece of tape that's also on a little bit on the back of the piece of paper. I made sure that its one piece, otherwise it wouldn't work.

```
//https://www.instructables.com/id/Capacitive-Sensing-for-Dummies/
//https://www.arduino.cc/en/Tutorial/Smoothing

#include <CapacitiveSensor.h>
// how to install libraries https://learn.sparkfun.com/tutorials/installing-an-arduino-library 
// download capsense lib here https://playground.arduino.cc/Main/CapacitiveSensor/

//send at pin 4, receive at pin 3, 1-10M ohm resistor between
CapacitiveSensor cs_3_4 = CapacitiveSensor(3, 4); // 1-10 megohm resistor between pins 4 & 3, pin 3 is sensor pin, add wire, foil

const int numReadings = 10;     // size of array/number of readings to keep track of (higher = slower)
int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average
int brightness = 0;             // initialize delay time at 0
int ledPin = 11;
int newAverage = 0;             //store values after mapping

void setup() {

  // initialize serial communication with computer:
  SerialUSB.begin(9600);           //start serial communication via USB cable
  
  cs_3_4.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example Serial.begin(9600);

  //initatialize readings array setting all values to 0
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }  
}

void loop() {

  // subtract the last reading:
  total = total - readings[readIndex];

  // read from the sensor:
  readings[readIndex] = cs_3_4.capacitiveSensor(30);

  // add the reading to the total:
  total = total + readings[readIndex];

  // advance to the next position in the array:
  readIndex = readIndex + 1;

  // if we're at the end of the array...wrap around to the beginning
  if (readIndex >= numReadings) {
    readIndex = 0;
  }

  // calculate the average:
  average = total / numReadings;

  // USE THIS TO FIND THE SENSOR RANGE (COMMENT OUT WHEN DONE)
  // send it to the computer as ASCII digits
  SerialUSB.println(average);  // if using Arduino serial >> e.g. 0 (touch), 70 (no touch)

//  // UNCOMMENT THIS TO MAP THE VALUES TO THE LED RANGE
//  // map the average value to the min and max we recorded above
//  newAverage = map(average, 70, 0, 0, 255);
//
//  //set brightness of LED to sensorValue (between 0-255)
//  analogWrite(ledPin, newAverage);  
//
//SerialUSB.print("Old Value = ");
//SerialUSB.print(average);
//SerialUSB.print("\t");   // add a tab between the numbers
//SerialUSB.print("New Value = ");
//SerialUSB.println(newAverage);

  delay(10); // arbitrary delay to limit data to serial port
}
```

When I was unwiring the circuit I still had my Serial Monitor open and it suddenly showed values. After looking at the wires one last time I saw I didn't make a mistake following the instructions. I recognized a mistake, the only thing I had to do was swap the wires connected in pin 3 and 4.

```
//send at pin 4, receive at pin 3, 1-10M ohm resistor between
```

The code works, just this comment should be changed to this:

```
//send at pin 3, receive at pin 4, 1-10M ohm resistor between
```

After this the setup worked (without the conductive crystal connected, just the paperclip) I could finally conclude that the crystal doesn't work.

![Pin \~3 as the send pin and pin \~4 as the receive pin](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2c5h1WVflHl3GLRDPT%2F-M2c7D4MR1A4rQKnAluX%2Fkaz_wk06_schematicCapacitiveSensing.jpg?alt=media\&token=d5f1e9fd-81ee-436e-bb1f-b59030596ba1)

![](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2hdCtOJprkbBqQJmPP%2F-M2hfxv5CiSxNlkVHiyN%2Fkaz_wk06_workingConductiveCrystal.gif?alt=media\&token=a296ac67-9e4e-445c-be1c-e826b7e1b35d)





![The capacitive sensor and LED connected to the microcontroller](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2h4TfsSKQudtU6BJn1%2F-M2h4f7-QnKkqH692l7X%2Fkaz_wk06_schematicCapacitiveSensingWithLED.jpg?alt=media\&token=3f3701eb-8f6d-4cfa-8325-8cd4c3d1cbe2)

### Copper wire

![Final sensor](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2hZOFQq1mzoVAhNEoK%2F-M2h_hgJz4Xkst2s4w-3%2Fkaz_wk06_conductiveCopperWireSensor-100.jpg?alt=media\&token=134d72bb-900b-4202-a6f9-0fe975f4698d)

At the show and tell I showed the sensor and told all the debugging I've done in the last week. After talking with Loes at the show and tell we came to the conclusion to solder the copper wire to the copper tape. So the copper wire and copper tape have better connection. In my design the copper tape makes the connection to my sensor, the copper wire. It's important to have no flaws there.

![](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M4CCUOsAPCq3POfyTbX%2F-M4CEgSm01BRF4uygFOl%2Fkaz_wk06_solderedCopperWireToCopperTape.jpg?alt=media\&token=5c115caa-f218-49e2-95e7-7c68eec149a2)

After soldering the copper wire to the copper tape I had a bit better results, but not as great as it needs to. I completely missed the part where I had to use 1 - 10M ohm resistance. The whole time building the multiple capacitive sensors I used 40k ohm. 40k ohm was the maximal amount of resistance I could create with the resistances I took with me before the school was closed, because of the corona virus.

### All iterations

![](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M2h6wlK7-xpaWPhQo5n%2F-M2hU68fyXQGKTeQqjgA%2Fkaz_wk06_conductiveSensorsAllIterations.jpg?alt=media\&token=2a4aeefa-3f00-4f1c-b9e2-6ef41f3f3b05)

## Attaching a LDR sensor

I had many problems with attaching my LDR sensor to my Node MCU. To begin; I didn't have a regular LDR sensor. Luckily, I had some older sensors from a previous course I followed. When I tried to attach my node MCU to my pc, I got various errors. My serial write wouldn't work, and my board wouldn't connect. I asked Loes for help, and after some resets it appeared to work again.

![My board wouldn't connect anymore - Thijs Uffen](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M4FErHpIrOQDCP38i3P%2F-M4FGUSSiKtniM1KZF9c%2Fimage.png?alt=media\&token=f38ded25-c4bb-4549-9141-d2290cdaa9a2)

After some iterations in my code, it stopped working again. Then I decided to use my Grove Node MCU. This one worked perfectly. I attached a light sensor to the AO, and found some code on a forum to make it work:&#x20;

```
/*
/* Grove - Light Sensor demo v1.0
* 
* signal wire to A0.
* By: http://www.seeedstudio.com
*/
#include <math.h>
const int ledPin=12;                 //Connect the LED Grove module to Pin12, Digital 12
const int thresholdvalue=10;         //The threshold for which the LED should turn on. 
float Rsensor; //Resistance of sensor in K
void setup() {
  Serial.begin(115200);                //Start the Serial connection
  pinMode(ledPin,OUTPUT);            //Set the LED on Digital 12 as an OUTPUT
}
void loop() {
  int sensorValue = analogRead(0); 
  Rsensor=(float)(1023-sensorValue)*10/sensorValue;
  if(Rsensor>thresholdvalue)
  {
    digitalWrite(ledPin,HIGH);
  }
  else
  {
  digitalWrite(ledPin,LOW);
  }
  Serial.println("the analog read data is ");
  Serial.println(sensorValue);
  Serial.println("the sensor resistance is ");
  Serial.println(Rsensor,DEC);//show the light intensity on the serial monitor;
  delay(1000);
}
```

I could read the values of the sensor in the serial monitor. I set it manualy to 115200 baud. Here are the values I received:

![The analog read data - Thijs Uffen](https://2472482582-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LzaCPWnWmmX17D0w0O3%2F-M4FErHpIrOQDCP38i3P%2F-M4FGNs73bBM7MV1evdU%2Fimage.png?alt=media\&token=a3c74a6c-2e4b-44c7-873a-fbbfc9cd3c38)

## Reflection

This assignment was really annoying for me. I've worked with Arduino and node MCU's before, and it always worked perfectly. This time around, I faced many unforeseen problems. Luckily Loes could help me out at some of my problems, but most of them kept reappearing for no clear reason. Then I decided to use my grove MCU board, and this one worked perfect. I really like to work with the hardware and to experiment with different pieces of code, but debugging really sucks. I learned to be patient and to carefully look for the root of the problem.&#x20;
