Nicola Wrachien
Published © GPL3+

electrostatiCAT

Measure electrification when you're petting your cat.

BeginnerFull instructions provided3 hours1,019
electrostatiCAT

Things used in this project

Hardware components

ITACA Innovation uChip
Available on https://shop.itaca-innovation.com
×1
16-pin DIP IC socket
×1
14-pin DIP IC socket
You can also solder directly the displays. But this is not recommended.
×2
common cathode 7-segment display
Any. They must be with 14-pin IC-style pinout if you want to use the included layout.
×2
120 Ohm, 5%, 1/4W PTH resistor
×8
1.8 kOhm, 5%, 1/4W, PTH resistor
×1
3.9 kOhm, 5%, 1/4W, PTH resistor
×2
3.3 kOhm, 5%, 1/4W, PTH resistor
×1
100 kOhm, 5%, 1/4W, PTH resistor
×1
1 MOhm, 5%, 1/4W, PTH resistor
×1
ON Semiconductor BC337-40 NPN BJT
BC547 is fine too.
×3
BC557 PNP BJT
×3
KS-01Q-01 pushbutton
×1
47-kOhm trimmer
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematics

Layout

Full KiCAD project

Code

Sketch

C/C++
Open Arduino IDE, paste this, and upload it!
/*  electrostatiCAT: measure electrification when petting your cat. 
 *  Copyright 2019 Nicola Wrachien www.next-hack.com 
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.   
 * 
 * 
  */
#define DP 4
const uint8_t pins[7]={6, 3, 10, 14,11, 5, 2};
const uint8_t digits[11] = {0b11000000,
                            0b11111001,
                            0b10100100,
                            0b10110000,
                            0b10011001,
                            0b10010010,
                            0b10000010,
                            0b11111000,
                            0b10000000,
                            0b10010000,
                            0b11001111};
const uint8_t displayPins[2] = {9, 7};
void setup() 
{
  REG_PORT_DIRSET0 = PORT_PA15;
  REG_PORT_OUTCLR0 = PORT_PA15;  // Quickly enable 3V3 buck regulation!
  // set all pins
  for (int i = 0; i < sizeof(pins); i++)
  {
    pinMode(pins[i], OUTPUT);
    digitalWrite(pins[i], HIGH);
  }
  pinMode(LED_BUILTIN,OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
  pinMode(DP, OUTPUT);
  digitalWrite(DP, HIGH);
  pinMode(displayPins[0], OUTPUT);
  pinMode(displayPins[1], OUTPUT);
  digitalWrite(displayPins[0], HIGH);
  digitalWrite(displayPins[1], HIGH);
  pinMode(1, INPUT_PULLUP);
  // set reference to 1V
  analogReference(AR_INTERNAL1V0);
  analogReadResolution(12);
  // serial for debug :)
  SerialUSB.begin(9600);
}
void loop() 
{
  static uint8_t f =  0;
  static float electrification = 0;
  static int disp = 0;
  uint32_t valueRead;  
  int n;
  f ++ ;
  if (digitalRead(1) == 0)    // reset conter
    electrification = 0;
  disp = 1 - disp;
  valueRead = analogRead(7); // read ADC
  //
  n = 100 * (4095 - valueRead) / 4096;
  // integrate electrification
  electrification = electrification + (4095 - valueRead) / 409600.0;
  //
  digitalWrite(displayPins[ 1 - disp], HIGH);   // deselect display
  // turn off all segments
  for (int i = 0; i < sizeof(pins); i++)
  {
    digitalWrite(pins[i], HIGH);
  }
  digitalWrite(DP, HIGH);                   // turn off decimal point
  digitalWrite(displayPins[ disp], LOW);    // select display
  if (electrification < 10)
  {
    n = 10 * electrification;
     digitalWrite(DP, LOW);
    if (disp == 1)
      n = n / 10;
    else
      n = n % 10; 
  }
  else if (electrification < 100)
  {
    n = electrification;
    if (disp == 1)
      n = n / 10;
    else
      n = n % 10; 
  }
  else
    n =  11;      // signal error

  for (int i = 0; i < 7; i++)
  {
    digitalWrite(pins[i], (digits[n] >> i) & 0x01);    
  }
  
  digitalWrite(LED_BUILTIN, f > (valueRead >> 4));
  SerialUSB.println( electrification );
}

Credits

Nicola Wrachien

Nicola Wrachien

3 projects • 2 followers
I was born, then I got my master, a PhD. I forgot about all what's in between.

Comments