Hi, I’m REALLY NEW to PIC’s but I’m downright fascinated by what can be done with them. For the past month or so I’ve been fooling with my UNO and a bunch of stuff I’ve picked up. I’ve made LED’s blink (Yay!) controlled some servos (Neat!) tinkered with DC motors and PWM (Cool!) got some SR04 sensors doing stuff (Awesome!) and controlled some old steppers from CD drives (Truly, Truly, Awesome!).
I’m OK on the hardware side but most of my tinkering has been copy/paste code. Seems once I get something working I can tinker with the code and get close to what I want but I really want to complete something.
I’ve been working on an LED bar graph tachometer project that I may actually use on my old diesel beater if I can get something working.
I have a 9 LED “bar” that I put together, an UNO and some Hall Effect sensors. The HE sensors are the linear type and I did manage to figure them out enough to get an LED illuminated when I swing a magnet in front of it (Pretty neat!)
I also built a little test stand with a variable speed motor so I can do some testing.
Here’s a little vid of the LED display with the RPM “test stand” on the right. (I started out with an IR rec/emitter but figured HE would be better)
http://www.youtube.com/watch?v=WPP-mijqj1I&feature=plcp
The LED graph is just being switched by simple on/off. No actual I/O stuff is going on I just wanted to make it blink. Maybe the vid will give an idea about what I want to accomplish. The vid is sort of simulating revving the engine.
I found this code: http://arduino.cc/playground/Main/ReadingRPM
Which I believe holds the key, along with using pinmode to switch the LED’s based on the input. I also think I’ll need to change the 301000 to 601000 for my single HE sensor.
Any help/hints/suggestions would be most welcome! Sadly, very little is “clicking” regarding this code stuff. I’m hoping I can hit a “tipping point” where things will clear up but it hasn’t happened yet :?
Thanks,
Jon
I figured I’d update this since I’ve made a little progress.
I found this code:
//code by Crenn from http://thebestcasescenario.com
//project by Charles Gantt from http://themakersworkbench.com
/*To disable interrupts:
cli(); // disable global interrupts
and to enable them:
sei(); // enable interrupts
*/
//Varibles used for calculations
int NbTopsFan;
int Calc;
//The pin location of the sensor
int hallsensor = 2;
int ledPin = 4; //$STUFF I ADDED$
int ledPin1 = 5;
int ledPin2 = 6;
int ledPin3 = 7;
typedef struct{ //Defines the structure for multiple fans and their dividers
char fantype;
unsigned int fandiv;
}fanspec;
//Definitions of the fans
fanspec fanspace[3]={{0,1},{1,2},{2,8}};
char fan = 1; //This is the varible used to select the fan and it's divider, set 1 for unipole hall effect sensor
//and 2 for bipole hall effect sensor
void rpm () //This is the function that the interupt calls
{
NbTopsFan++;
}
//This is the setup function where the serial port is initialised,
//and the interrupt is attached
void setup()
{
pinMode(hallsensor, INPUT);
Serial.begin(9600);
attachInterrupt(0, rpm, RISING);
pinMode(ledPin, OUTPUT);////$STUFF I ADDED$$
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void loop ()
{
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv); //Times NbTopsFan (which is apprioxiamately the fequency the fan is spinning at) by 60 seconds before dividing by the fan's divider
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" rpm\r\n"); //Prints " rpm" and a new line
//$STUFF I ADDED$/////////////////////////////////////////////////////////////////////////////
if (Calc > 40)
{
digitalWrite (4, HIGH);
delay (100);
}
if (Calc < 40)
{
digitalWrite (4, LOW);
}
if (Calc > 100)
{
digitalWrite (5, HIGH);
delay(100);
}
if (Calc < 100)
{
digitalWrite (5, LOW);
}
//////
if (Calc > 240)
{
digitalWrite (6, HIGH);
delay(100);
}
if (Calc < 240)
{
digitalWrite (6, LOW);
}
/////
if (Calc > 300)
{
digitalWrite (7, HIGH);
delay(100);
}
if (Calc < 300)
{
digitalWrite (7, LOW);
}
}
And added the “pinMode” stuff to it along with a few “if’s” and it seems to be doing what I want it too! I know the code is quite clunky but I’m really new to this. I need some small magnets in order to test it properly but it seems to work with just passing a large magnet over the HE sensor at different speeds. I can get the 4th light to work if I run it back and fourth really fast and the display seems to respond well.
I’m amazed at the size of the HE sensor and I can think of a zillion (Well, maybe 3 or 4…) ways to use them.
Anyway, I’m stoked that I accomplished my goal for the weekend
A picture of the rats nest:
http://i711.photobucket.com/albums/ww11 … ry-178.jpgAny input would be most welcome! I want to do a permanent install without using my UNO board. It would be cool to make my own board and get into the “bootloader” stuff 8) I figure I’d need a crystal, power supply as well as a usb or something for programming.