Input devices

Building on the past electronics weeks it is now time to make a input device. In this weeks recitation we learned about different commonly used sensors. I've played around with phototransistors, distance sensors, hall sensors and pir-sensors in the past. It was the first time I heard about a step response sensor and I thought it was quite interesting since it can have a wide range of applications. Also with some more research I think I can use it for my final project and use it as a galvanic skin response sensor.
To start the week Henk shared this really fun video about kids who learn about computers.


Input devices

Hardware
USB drive
Modela MDX20 Soldering iron - Weller WS 81 (SMD tip)
Osciloscope
USB Logic Analyzer Device Set Compatible to Saleae 24MHz 8CH for ARM FPGA M100

Software
FabModules
KiCad

Tools
1/32 inch milling bit
1/64 inch milling bit
Scraper

Materials
FR-1 PCB blanks (1.8 mm thickness)
Double sided tape (good quality)
Rubbing alcohol


Group assignment

For the group assignment we measured data comming in from the sensors with an oscilloscope. We chose to measure the HC-SR04 Ultrasonic sensor. The sensor works with two little transducers, a speaker and a microphone. One sends a signal and the other listens for it to bounce and come back again. The time of this transmission can be converted to distance with a simple calculation. The connection between the microcontroller and the sensor is made with four different pins: ground, 5v, trig and echo. Trig and echo are used as a output and input for the signals.

Reading signals from a distance sensor

This week we were taking a deep dive with the oscilloscope. We all attended a demonstration in one of the earlier weeks but none of us had any usefull experience. We started with a premade assembly of a arduino + ultrasonic sensor that had a simple sketch on it to measure distance and print it in the monitor.

We connected the probes to the sensor board (trig and echo) and the ground clips to ground. At the first glance nothing happend in the display so We played around with the buttons trying to figure things out. After a few minutes of this it was clear that this was not going to be the most effective nor intelligent way to get a reading. To be clever we jumped to our instructors documentation to see if he had documented the correct settings for the oscilloscope, altough he used the same sensor we couldn't quite get the same results since he was measuring from a different pin (one of the board pins connected to the amplifier). At this point we realised that we couldn't outsmart the the oscilloscope by directly trying to measure signals from the sensor. So we followed this super quick, fun and usefull explanation and followed allong.


Measuring the probe

  1. Set the probes to 10x (both were at 1x).
  2. Connect the probes to osciloscope on the metal ring sticking out of the osciloscope and the ground to the ground of one of the available probe connections.
  3. Set osciloscope to channel 1.
  4. Change settings to 500 mV and 250 μs.
  5. Moved the trigger line to get a stable signal (try to center it in the reading).

Conclusions, the metal ring generates a square wave constant pulse, this was easy to read via the automatic settings. It's a easy way to quickly check probes or find your first signal.


Measuring a analog signal

  1. Point the sensor in a direction where it measures a long range. Since the signal takes more time to come back it will be easier to read.
  2. Connect the echo pin to the channel one probe, trig to the other.
  3. Press run on the osciloscope this starts the reading. When the oscilloscope detects a peak it takes a snapshot of that reading. Try changing the time, vertical allignment, trigger and voltage to get a better reading.

Conclusions, we were able to to read what happens to the signal. We first saw 8 pings on trig followed by a change in the echo pin reading (from low to high) when the ping comes back the signal goes back to low. The closer something is the narrower the reading is on the echo pin (less time).


Measuring a digitital signal

  1. Connect the logic analizer between your microcontroller and computer.
  2. Open the software of the logic analizer, Logic 1.1.16 Beta.
  3. Check for the signal on the RX.

The signal that is being displayed are bits. High and low signals are alternated to communicate ones and zeroes. We are sending the sensor data to the serial monitor (for example 10 cm) via RX. Above the reading in Logic we can also see these characters being displayed. If we google for ASCII binary alphabet we can also check this ourselves.


GSR Sensor

This week I chose to attempt making a galvanic skin response sensor aka a lie detector. After the lecture and some initial research I realised it's actually a step response sensor. The sensor measures resistance inbetween two different probes. As your hands become more sweaty there is less resistance, when the sweat evaporates the resistance goes back up. This sensor can be used as a lie detector but is also a relativly simple, non intrusive way to get bio feedback. This might make it a good fit for my final project.

First descission to make this week was on the basis of the controller board. I thought it was fun to trie my hand at the Satshaboard or the Fabkit. I couldn't find good matches for all the parts in Kicad (BTW Kicad now works for me in Mojave, version 5.1.0) and since it was close to midnight I couldn't reach out for a helping hand. Pragmaticly I chose to go back to a much simpler version and drew a ATTINY85 board.

Next it was time to figure out the sensor and add it to the schematic. I found some good recourses online where I could build from. My favourite example was the Galvactivator. Down side was that the used parts were not at hand in the lab. Than I found a few similar ones from Chris3000, Makezines: Truth meter,Norma Deseke and Cwwang's GSR reader. I combined Norma's reader (2x 249k resistors) with Cwwangs (resistors with additional capacitor) one to see if I could get the best of both. Since Cwwang didn't document his parts I found the correct (hopefully) value from the comments.

Components used
1x ATTINY85
2x ISP header pins
1x FTDI connection pins
1x 10k resistor
1x 1k resistor
1x 0 ohm resistor
1x 1uf capacitor
1x 0.1uf capacitor

I milled the board and soldered all the components and gave it a try. Inmediatly the board started to smoke when I connected it to a power supply, this told me there was a short somewhere. Using a multimeter I located the short to be between mosi and gnd. I took of one of the ISP headers and the problem was solved. Unfortunatly I also took of one of the copper pads.

Since I didn't have time to go back to the lab to fix things I connected the parts to a ESP and made sure my code was working.

The code was working fine with my make shift solution. I was able to read some date unfortunatly it behaved more like a galvanic skin response sensor than a galvanic skin response sensor. You can see in the serial plotter from Arduino IDE that everytime the electrodes are touched it just droppes down abruptly.

/*
 * This code is written by Anne Vlaanderen for Fabacademy week 11 input devices 
 * This is a simple code to read data from a galvanic skin response sensor and print in in the serial monitor.
 * GRSmin and GSRmax are the lowest and highest reading of the session. This shows the range of response that the sensor is getting.
 * You can find the schematic and build instructions on on http://anne.vlaanderen/
 * April 1 - 2019 v0.1
 */

//GRS
int grsSensor = A0;
int gsrVal = 0;
int GSRmax = 0;
int GSRmin = 0;

void setup()
{
  //init seriale
  Serial.begin(9600);
}

void loop()
{
  //Value GSR
  gsrVal = analogRead (grsSensor);

 // remember highest value from sensor 
  if (GSRmax < gsrVal) {
    GSRmax = gsrVal;
  }

 // remember lowest value from sensor 
   if (GSRmin > gsrVal) {
    GSRmin = gsrVal;
  } 

 //send to serial monitor
  Serial.println("-------------");
  Serial.print("GSR:");
  Serial.println(gsrVal);
  Serial.print("GSR MAX:");
  Serial.print(GSRmax);
  Serial.print("GSR MIN:");
  Serial.println(GSRmax);

// wait 800 milliseconds for next reading
  delay(800);

}

Compared to a different GSR sensors the biggest difference is the amplifier that some boards have. I bought a GSR sensor from Groove. Briefly I looked into replicating this design but it has a few parts that are not in our inventory (amplifier and regulated resistor). I connected the sensor to the board of my final project and ran the code from their Wiki page. Inmediatly the results were much better than the previous attempt.

Black wire to GND
Red wire to VCC
Yellow wire to A0

The sensor comes with a special grove cable. I cut one of the connectors off and connected the Black wire to GND, Red wire to VCC and the Yellow wire to A0. The white wire is a NC (not connected).

The electrodes are also connected with a special connector.

The results should look more like this now:

The analog pin reads an analog voltage from the board that ranges between 0 and 512. 0 means very low resistance and 512 very high. If you don't toch the electrodes it's at 512. If you hold the electrodes together it's 0. If you put them on your fingers it's somewhere in the 280 - 380 range, 280 being a stressed person with sweaty hands and 380 being a relaxed person with less sweaty hands. Rapid declines can be seen quite visible, for example when somebody has a stress full thought, it can be seen inmediatly.

Finally I also connected a OLED screen (described in networking week) to the board and made a little script that shows a live graph of the GSR results.

   /*
  OLED graph test

  This example shows how to display a graph from a analog input on a 128x64 px i2c oled display.

  A0 is connected to a Groove GSR sensor.

  Sources:
  http://wiki.seeedstudio.com/Grove-GSR_Sensor/
  https://www.how2electronics.com/pulse-sensor-with-oled-arduino/

  by Anne Vlaanderen 2019
*/


#include <Adafruit_SSD1306.h>
#define OLED_Address 0x3C        // 0x3C device address of I2C OLED. Few other OLED has 0x3D
Adafruit_SSD1306 oled(128, 64);  // create our screen object setting resolution to 128x64

int a=0;
int lasta=0;
int lastb=0;
int LastTime=0;
int ThisTime;
bool GSRTiming=false;
int GSR=0;
#define UpperThreshold 560
#define LowerThreshold 530

void setup() {
  oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
  oled.clearDisplay();
  oled.setTextSize(1.6);
}


void loop() 
{
  if(a>127)               //width of display
  {
    oled.clearDisplay();
    a=0;
    lasta=a;
  }

  ThisTime=millis();
  int value=analogRead(0);
  oled.setTextColor(WHITE);
  int b=50-(value/16);    //height of display
  oled.writeLine(lasta,lastb,a,b,WHITE);
  lastb=b;
  lasta=a;


  oled.writeFillRect(0,50,128,16,BLACK);
  oled.setCursor(0,50);
  oled.print("GSR:");
  oled.print(value);

  oled.display();
  a++;
}

Files

GSR schematic
GSR cutout
GSR traces