Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Finding This H'Arduino !!

Status
Not open for further replies.

Musicmanager

Well-Known Member
Hi Guys

Do we have a resident Arduino genius ?

I'm busy installing a CNC milling machine in my workshop at the moment .. .. a cheap chinese version that has provision for spindle speed control but it is not connected and there is some development work to do before I can attempt to achieve that.
As an interim measure I found a Tachometer circuit on the net which uses an Arduino Uno, a IR reflective sensor and an LCD panel to measure and display spindle speed .. .. great ! I thought.
I built the circuit and used my function generator to test it and it seems to work OK, so I got the Arduino Uno out, copied the program file but I can't get it to upload .. ..It compiles OK, but upload hangs after a few seconds and then I get a message 'Problem uploading to the board'

Here's the code .. ..

C:
/*
* Optical Tachometer
*
* Uses an IR LED and IR phototransistor to implement an optical tachometer.
* The IR LED is connected to pin 13 and ran continually.
* Pin 2 (interrupt 0) is connected across the IR detector.
*
* Code based on: [URL='https://www.instructables.com/id/Arduino�Based�Optical�Tachometer/']www.instructables.com/id/Arduino�Based�Optical�Tachometer/[/URL]
* Coded by: arduinoprojects101.com
*/
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)
  attachInterrupt(0, rpm_fun, FALLING);

  //Turn on IR LED
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);

  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);
}

I haven't done anything harduino before, and right now I'm concentrating on CNC stuff .. .. .. Why use harduino ? simply because I had one in the cupboard doing nothing ........mind you, it still is ! Doing nothing I mean :)

Simple question ... .. can anybody see a glaring error ??

Thanks

S
 
Last edited by a moderator:
Also ... can someone tell me why my code tags haven't worked .. ... I s'pose I've b****** that up too !

Mods .. If you can correct that, please do !


S
 
Also ... can someone tell me why my code tags haven't worked .. ... I s'pose I've b****** that up too !

Mods .. If you can correct that, please do !


S
there cannot be spaces in the tags..... bracket"code=c"bracket
 
Won't be the code... The serial connection may need tweaking.... Is it a genuine Harduino??? There will be a selection of bogus harduino rip offs...

EDIT!!!!! If the hardware is using Rxd and Txd you need to disconnect or the usb bit don't chin wag!!
 
I doubt it's genuine, but it came from a local shop who hasn't let me down before ... ... also, there's a 'blink' program on the website for novices... it does that perfectly

I'll check over the connections again, Thanks S
 
Hi

Sorry, I went away for a while ... I had to put my Nurses uniform on and care for the sick !

I think I've found a problem .. .. I seem to remember reading an article a while ago - might have been on here - about some Arduino boards with a 'one time only' programming problem .. .. .. I've checked the serial connection and it seems OK ... .. and .. ..the 'format board' doesn't work.
When I first got the board I loaded the 'blink' program from the Arduino website and had a little play with it .. .. that still works perfectly. However, it is impossible to 'format' that program off the board .. .. ..

However, the circuit I've built will be good for whatever I end up using to count the frequency, so all is not lost ..

I need to say .. please don't waste any more time with this ....

Thanks

S
 
I need to say .. please don't waste any more time with this ....
Like I said.... I can't waste any time... If I were at work, I would have tried it out... I ALWAYS have a Harduino on me bench!!
 
I have just copied the code from post 1 and programmed a (genuine) Mega 2560 with it. It compiled and uploaded with no problem.
The box at the bottom of the screen gave the following message;
"Sketch uses 3,882 bytes (1%) of program storage space. Maximum is 253,952 bytes.
Global variables use 72 bytes (0%) of dynamic memory, leaving 8,120 bytes for local variables. Maximum is 8,192 bytes."
 
Open up the Arduino proggy and upload the empty template which always shows when you start up.
That should basically wipe the Arduino.
I will try your program on a genuine Uno R3 when I get home in a bit.
 
Hi

Thanks for that .. I think that goes to prove my suspicions .. ...

I obviously have a problem Arduino ... .. ..

Guys, please don't waste a lot of your time and effort on this, I'm not going to be able to get any further until I get some genuine boards

S
 
Erased the Uno by uploading the default sketch upon opening the Arduino program.

Copied and pasted the listing from the 1st post, then uploaded. Got the following error message but the file still loaded.

"MusicManagerTacho.ino" contains unrecognised characters. If this code was created with an older version of Arduino, you may need to use Tools -> Fix Encoding & Reload to update the sketch to use UTF-8 encoding. If not, you may need to delete the bad characters to get rid of this warning.

Replaced the unrecognised characters (in the comments) with a "-" and the warning disappeared.

Added "Serial.begin(9600);" in the void setup() section and added the following after "lcd.print(rpm);"
Serial.print("RPM=");
Serial.print(rpm);
Serial.println();
to print out the RPM in the serial monitor window. Menu Bar>Tools>Serial Monitor.

As I have nothing connected to produce a signal, it just displays RPM=0, but it is working on a genuine Uno R3.

Regards.
 
Hi Mickster

Thank you for your trouble .. much appreciated .. ..

I'm pretty certain I have a 'funny' board, but I will try it out again tomorrow morning with your file .. ..

S
 
Here is your listing including the changes:

Code:
/*
* Optical Tachometer
*
* Uses an IR LED and IR phototransistor to implement an optical tachometer.
* The IR LED is connected to pin 13 and ran continually.
* Pin 2 (interrupt 0) is connected across the IR detector.
*
* Code based on: [URL='https://www.instructables.com/id/Arduino-Based-Optical-Tachometer/']www.instructables.com/id/Arduino-Based-Optical-Tachometer/[/URL]
* Coded by: arduinoprojects101.com
*/
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)
   attachInterrupt(0, rpm_fun, FALLING);
   //Turn on IR LED
   pinMode(ledPin, OUTPUT);
   digitalWrite(ledPin, HIGH);
   Serial.begin(9600);
 
   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);
   Serial.print("RPM=");
   Serial.print(rpm);
   Serial.println();
      //Restart the interrupt processing
   attachInterrupt(0, rpm_fun, FALLING);
}
 
Just had a brain fart on this one MM, check you have the correct port selected for your Uno when it is connected.
If you have it connected to a different USB port, it may have assigned a different COM port than the previous time you used it.
Check which COM port is assigned in Device Manager and make sure the same is selected in the Arduino program.

Regards.
 
Just had a brain fart on this one MM, check you have the correct port selected for your Uno when it is connected.
If you have it connected to a different USB port, it may have assigned a different COM port than the previous time you used it.
Check which COM port is assigned in Device Manager and make sure the same is selected in the Arduino program.

Regards.
I fear it may be too late Mickster!! The offending Harduino may already resemble an ashtray!!
 
I fear it may be too late Mickster!! The offending Harduino may already resemble an ashtray!!

Indeed, Indeed !!

Edit: although not an ashtray .. .. Following a 'Johnny Wilkinson' style drop kick it was last seen passing the ISS on a Mars bound trajectory .. .. .. .
 
Last edited:
Status
Not open for further replies.
Back
Top