Sunday, December 13, 2015

Week 6 Adventures in Making - LCD RPM Project


This week I developed my final project using an LCD screen to read RPM readings taken from an Infrared LED Emitter and Detector.  I got the original design and code from arduinoprojects101.com  This is a picture of the original diagram.

I originally intended to create a working model of the above diagram after which I would try some modifications.  To construct this project I needed a larger breadboard than the standard one that came with the Arduino kit.  To accommodate this  larger breadboard, I had to construct a larger base to hold the breadboard and Arduino Uno.

 
 
 
The larger breadboard has 64 rows (I called them pins in the video which was incorrect).  The larger breadboard has 840 tie points for connections.
 
 

 
 
The newly constructed base with larger breadboard and Arduino circuit board came out quite nicely (if I do say so myself)  :-)
 
 

 
 
Next, I did all of the jumper connections as shown on the arduinoproject101.com diagram and powered the board up.
 
 

 
 
 
I then compiled and loaded the code from arduinoproject101.com. which is based on code from instructables.com/id/Arduino-Based-Optical-Tachometer.
 
 
int ledPin = 13;   // IR LED connected to digital pin 13
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
 
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
 
void rpm_fun()
 {
   //Each rotation, this interrupt function is run twice, so take that into consideration for
   //calculating RPM
   //Update count
      rpmcount++;
 }
 
void setup()
 {
   lcd.begin(16, 2);  // intialise the LCD
 
   //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
   //Triggers on FALLING (change from HIGH to LOW)
   pinMode(ledPin, OUTPUT);
   digitalWrite(ledPin, HIGH);
   attachInterrupt(0, rpm_fun, FALLING);
 
   //Turn on IR LED
   rpmcount = 0;
   rpm = 0;
   timeold = 0;
 }
 
 void loop()
 {
   //Update RPM every second
   delay(1000);
   //Don't process interrupts during calculations
   detachInterrupt(0);
   //Note that this would be 60*1000/(millis() - timeold)*rpmcount   if the interrupt
   //happened once per revolution instead of twice. Other multiples could be used
   //for multi-bladed propellers or fans

   rpm = 30*1000/(millis() - timeold)*rpmcount;
   timeold = millis();
   rpmcount = 0;
 
   //Print out result to lcd
   lcd.clear();
   lcd.print("RPM=");
   lcd.print(rpm);
 
   //Restart the interrupt processing
   attachInterrupt(0, rpm_fun, FALLING);
  }
 
 
 

 
 
 
 
 
After compiling and loading (and connecting my missing LCD read jumper), my LCD was responding properly with a RPM=0 display.  The next step was constructing my motor with a blade that I could pass between the infrared diodes to get a RPM reading.  Unfortunately, the motor that came with the Arduino kit did not come with a blade that I could attached to it for this project.  So I visited a couple if the local electronics stores that I knew carried Arduino kits and parts.  Neither Microcenter nor Radio Shack carried a DC motor with a blade attachment that I could use for this project.  Consequently, not letting this stop me, I had to resort to other measures.... I borrowed my wife's little portable fan she keeps in her purse for emergency cool offs ......
 
  
 
 
Now.  With a small motor in hand to test my project, I check for readings.  However, there was a problem.  My LCD was not displaying any readings.
 
 

 
 
So there was something amiss.  I proceeded to recheck all of my jumper connections in accordance with the arduinoprojects.com diagram.  I check and rechecked.  I changed the infrared diodes (I had purchased a couple of extra sets).  After reexamining the diagram, I determined that I may have the wrong type of infrared diodes.  I researched and found the exact same type of diodes that are pictured in the arduinoprojects.com website.  Eureka!  This must be the problem.  I immediately ran back to Radio Shack and purchased 2 sets of the exact ones.  I ran back to the house plugged them in and....... no joy.  :-(  So, I thought to myself, just maybe there is a different way to configured to jumpers.  So I started experimenting with different jumper configurations for just the infrared diodes (which would have been the next step in my project anyway).  The LCD display was functioning properly.  So there must be another way to configure the infrared diode jumpers.  After several different configurations, I found the right one and Success!  I had a working LCD RPM reader....
 
 

 
 
One of the problems I noted from the original arduinoprojects.com configuration was that there seem to be a double ground for the infrared diode configuration.  Every time I plugged the second ground lead for the infrared diodes into the breadboard, the LCD display would dim and the pin 13 light for that jumper would go out.  This indicated to me that this extra ground was grounding my whole circuit out.  So I eliminated that extra ground jumper and repositioned the other ground jumper so that there was a complete circuit without the double ground and it worked.  Here is a picture of the working circuit without the double ground.


 
 
 
 
This has been a fun and rewarding project.  I have learned more about using libraries in code and using infrared diodes.  Also, here is a note about infrared diodes.
 


 


 Thanks for reading and following the journey!

David

No comments:

Post a Comment