Arduino Touch sensor, Ultrasonic sensor, Heartbeat sensor

Touch sensor

https://create.arduino.cc/projecthub/Arca_Ege/how-to-use-a-touch-sensor-81b7f4

The circuit from sensor > arduino
VCC Pin > 5V
GND > GND
OUT > Pin 2
LED pin (short leg (anode) to ground, long leg to Pin 13)

int in = 2; 
int out = 13;  
int state = HIGH;  
int r;           
int p = LOW;    
long time = 0;       
long debounce = 200;
   
void setup()
{
  pinMode(in, INPUT);
  pinMode(out, OUTPUT);
}
void loop()
{
  r = digitalRead(in);
  if (r == HIGH && p == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else 
      state = HIGH;
    time = millis();    
  }
  digitalWrite(out, state);
  p = r;
}

Ultrasonic sensor

https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/
https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/

The circuit from sensor > arduino
+5 > 5V
Trigger > pin 7
Echo > pin 6
GND > GND

const int trigPin = 7; // Trigger Pin of Ultrasonic Sensor
const int echoPin = 6; // Echo Pin of Ultrasonic Sensor

void setup() {
   Serial.begin(9600); // Starting Serial Terminal
}

void loop() {
   long duration, inches, cm;
   pinMode(trigPin, OUTPUT);
   digitalWrite(trigPin, LOW);
   delayMicroseconds(2);
   digitalWrite(trigPin, HIGH);
   delayMicroseconds(10);
   digitalWrite(trigPin, LOW);
   pinMode(echoPin, INPUT);
   duration = pulseIn(echoPin, HIGH);
   inches = microsecondsToInches(duration);
   cm = microsecondsToCentimeters(duration);
   Serial.print(inches);
   Serial.print("in, ");
   Serial.print(cm);
   Serial.print("cm");
   Serial.println();
   delay(100);
}

long microsecondsToInches(long microseconds) {
   return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
   return microseconds / 29 / 2;
}

Pulse/ Heartbeat Sensor

https://www.hackster.io/Johan_Ha/from-ky-039-to-heart-rate-0abfca — The author converted the signal from the sensor into human-readable beats per minute.

The circuit from sensor > arduino
Signal (S pin) > A0
5V ( + middle pin) > 5V
GND (- pin) > GND

Note: place your finger between the IR led and the light transistor of the sensor. Make sure they are contain in a dark environment to remove noise reflecting from artificial lights. (The reason why the SpO2 probe have opaque protective covers?)

#define samp_siz 4
#define rise_threshold 4

// Pulse Monitor Test Script
int sensorPin = 0;

void setup() {
    Serial.begin(9600);
}

void loop ()
{
    float reads[samp_siz], sum;
    long int now, ptr;
    float last, reader, start;
    float first, second, third, before, print_value;
    bool rising;
    int rise_count;
    int n;
    long int last_beat;

    for (int i = 0; i < samp_siz; i++)
      reads[i] = 0;
    sum = 0;
    ptr = 0;

    while(1)
    {
      // calculate an average of the sensor
      // during a 20 ms period (this will eliminate
      // the 50 Hz noise caused by electric light
      n = 0;
      start = millis();
      reader = 0.;
      do
      {
        reader += analogRead (sensorPin);
        n++;
        now = millis();
      }
      while (now < start + 20);  
      reader /= n;  // we got an average
      
      // Add the newest measurement to an array
      // and subtract the oldest measurement from the array
      // to maintain a sum of last measurements
      sum -= reads[ptr];
      sum += reader;
      reads[ptr] = reader;
      last = sum / samp_siz;
      // now last holds the average of the values in the array

      // check for a rising curve (= a heart beat)
      if (last > before)
      {
        rise_count++;
        if (!rising && rise_count > rise_threshold)
        {
          // Ok, we have detected a rising curve, which implies a heartbeat.
          // Record the time since last beat, keep track of the two previous
          // times (first, second, third) to get a weighed average.
          // The rising flag prevents us from detecting the same rise more than once.
          rising = true;
          first = millis() - last_beat;
          last_beat = millis();

          // Calculate the weighed average of heartbeat rate
          // according to the three last beats
          print_value = 60000. / (0.4 * first + 0.3 * second + 0.3 * third);
          Serial.print(print_value);
          Serial.print('\n');
          third = second;
          second = first;
        }
      }
      else
      {
        // Ok, the curve is falling
        rising = false;
        rise_count = 0;
      }
      before = last;
      ptr++;
      ptr %= samp_siz;
    }
}

wootS! My first electronic setup with Arduino Uno and DHT 11 Temperature and Humidity Sensor

yeppp! My first project, after waiting approximately 10 days for delivery from China! Bought all the requisites, in twos, and with different sellers, because I was afraid the shipment will break some components or that the particular shipment from the seller is defective. I’m paranoid that way. Heh.

DHT 11 or DHT 22 (3 pins) to Arduino Uno

+out > 5V
middle pin > pin 2
-out > gnd

In your Arduino code, make sure you include library adafruit and DHT sensor for it to work

#include <DHT.h>
#define DHTPIN 2     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22   // DHT 22 or DHT 11 change DHT accordingly
DHT dht(DHTPIN, DHTTYPE);


void setup() {
  Serial.begin(9600);
  Serial.println(F("DHT22 test!"));

  dht.begin();
}


void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
}

And how I setup my basic env on a new macOS when the previous one died.

Open Terminal in MacGo to home brew —> download brew sh (Package manager for MacOS)
brew install git —> https://medium.com/@katopz/how-to-upgrade-git-ff00ea12be18

brew cask search iterm2
brew cask install iterm2
brew cask install spectacle // functionality
brew cask install visual-studio-code // code editor
brew search vim
brew install vim
brew search nvm 
brew install nvm
brew install postgres

after installing nvm follow instruction on screen

mkdir ~/.nvm

check bash profile

vim ~/.bashprofilevim // program that runs iterm

I probably need to do some editing to make it readable… but for now personal notes. 😀

What Tor Browser taught me about signature verification

What I wanted was to download Tor Browser into macOS, along the way, I found what it means to verify a signature/ fingerprint of the downloaded application. And I should never trust anything I downloaded…

So first I headed to https://www.torproject.org/projects/torbrowser.html.en and click on download tor browser.

I had to select my operating system, macOS, english. At this point if you hover over the links, you will notice 2 files –  .dmg and .asc links.

  1. Click and download the .dmg file (but DO NOT open it yet)
  2. Download also the .asc file
  3. To make sure you have never downloaded Tor before. You can cd ~/Library/Application\ Support/ Tor-Browser DataIf Tor-Browser Data exist, remove and trash it. (reference from https://www.reddit.com/r/TOR/comments/7gguoy/tor_will_not_run_on_my_mac/)
  4. Next for mac users, you will need to install GPG Suite https://gpgtools.org/. This allows you to verify that the package that you’ve downloaded has the same digital signature as the developers who have signed the package
  5. Interestingly if you are thinking of verifying your tor browser, you might probably also wish to verify the gpg tools suite installer is authentic :D, you can read this https://bitzuma.com/posts/how-to-verify-an-electrum-download-on-mac/
  6. Once your GPG is setup, go to the directory where you downloaded both the .dmg and .asc file and run gpg --keyserver pool.sks-keyservers.net --recv-keys 0x4E2C6E8793298290to use GnuPG to import the key that signed the package
  7. Next, according to https://www.torproject.org/docs/verifying-signatures.html.en, after importing  the key above, run gpg --fingerprint 0x4E2C6E8793298290
  8. To verify the signature of the package downloaded, run gpg --verify TorBrowser-8.0.6-osx64_en-US.dmg{.asc*,}
  9. The output should say ‘good signature’ https://www.torproject.org/docs/verifying-signatures.html.en

.

.

That’s it. Some questions I have are,

Do all developers sign their packages and upload their public key to key server?

What is the difference between an undefined or unknown

***The fingerprints and signatures are dated when I downloaded Mar 3 2019. They may change as the packages are updated***

Setting up website from scratch

Setting up a wordpress site on your own server. Follow the instructions. 😀

  1. purchase a domain (namecheap)
  2. Generate your ssh keys for later when you are required to add your public key in digital ocean and to ssh into your server. https://medium.com/risan/upgrade-your-ssh-key-to-ed25519-c6e8d60d3c54
    • cd to your ssh folder  ~/.sshto generate the keys directly there
  3. setup a server (digital ocean)
    • Create a droplet – Ubuntu 18.04.2, Standard, cheapest@$5/month
    • Add a domain (which you’ve purchased) enter example.com and create a new type `A` record. This will generate name servers which you can then add back in namecheap.com
  4. in Namecheap.com, navigate to the domain above and select manage
    • Under nameservers tab, select CustomDNS and add all the `NS` value generated by digital ocean
  5. You need to update your nameservers with your domain registrar for the records below to take effect.
  6. set your nameservers to point to your custom dns (digital ocean)
  7. Now ssh into your server! ssh root@example.comor ssh -i ~/.ssh/nameoffile root@example.com
  8. In your server follow the instructions for mariadb and php. https://websiteforstudents.com/install-wordpress-on-ubuntu-18-04-lts-bata-with-nginx-mariadb-and-php-fpm/
  9. a note with chown -R www-data:www-data /var/www/html sets permissions for the default web root, so the files are owned by the user account used by your web server. WordPress will ask for these FTP credentials if it detects that it does not have permission to write the needed files itself.
  10. Emphasing password for root user on login https://serverfault.com/questions/795290/admin-password-of-mariadb-doesnt-seem-to-work
  11. https://www.nginx.com/blog/installing-wordpress-with-nginx-unit/
  12. unlink /etc/nginx/sites-enabled/default
  13. At this point nginx conf is not yet complete, so let’s head to letsencrypt https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04

.

.

.

.

.

Took me 2 years to understand what I’m doing, but I could still be wrong. Hah.