Things used in this project

Hardware components:
Adafruit industries ada161 image 75px
Photo resistor
A specific photo resistor is not required.
×1
Resistors
You'll need three resistors. Read more to figure which ones you'll need for your project.
×3
12002 04
Breadboard (generic)
×1
Teensy31
Teensy 3.1
This is just one of the many platforms you can use for this simple tachometer.
×1
Texas instruments lm358ap image
Texas Instruments General Purpose Dual Op-Amp
×1
Software apps and online services:
Ide web
Arduino IDE
Whatever IDE you like to use, you'll just need a serial monitor.

Schematics

Op-Amp Comparator
This op-amp circuit digitizes the change in resistance of a photo resistor. This simplifies the tachometer code and produces more reliable results than an analogRead().
Comparator schematic sjlsjtzl53

Code

Teensy TachometerArduino
The output from the op-amp is attached to pin 13 on a Teensy 3.2. This digital input has an attached LED so troubleshooting can be easier. Using an interrupt when the pin goes high, a boolean variable is set to true and then the RPM is calculated in the main loop, output to serial and the boolean variable is set back to false.
void setup()
{                
  Serial.begin(38400);
  
  pinMode(13, INPUT_PULLUP);
  
  /* Depending on the board you're using, the interrupt declaration might have
   * a different syntax
   */
  attachInterrupt(13, tick, RISING); 
}

long rev; //T
long prevRev = 0;
bool change = false;
int changeCount = 0;
double rpm;
double prevRPM;

void loop()                     
{
  if (change == true) {
    rev = millis();
    rpm = 60000/(rev - prevRev);
    if (rpm != prevRPM ) {
      Serial.println(String(millis()) + "~" + String(rpm));
      prevRPM = rpm;
    }
    prevRev = rev;
    change = false;
  }  
}

void tick() {
  change = true;
}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Raspberry Pi and any ARM devices Gaming Emulator
Easy
  • 267
  • 1

Protip

Play your favorite PC games on Raspberry Pi (or any ARM) - Might and Magic 6, Stronghold Crusader, Pharaoh and Cleopatra and more.

Charlieplexing with Freescale
Easy
  • 384
  • 7

Full instructions

Charlieplexing uses the tri-state logic capabilities of microcontrollers in order to gain efficiency over traditional multiplexing.

Setting Up GPIO, PWM, I2C for K82 Freedom Board in KDS
Easy
  • 1,240
  • 10

Protip

A helping hand for the novices like me to set up Output on other available pins of K82 Freedom

Jack and Coke Bot
Easy
  • 286
  • 5

Pour the perfect Jack and Coke every time.

Automatic Temperature Based Fan Control (for Media Cabinets)
Easy
  • 2,436
  • 13

Full instructions

Media cabinets often get very hot. This project combines a temperature sensor with a fan to cool them down.

Octoblu and Wunderbar: Baby Monitor that texts you updates
Easy
  • 2,212
  • 16

Full instructions

By using Relay's Wunderbar on Octoblu's IoT platform, it was easy to create a simple baby monitor that texts you updates about your baby.

Sign up / LoginProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlog