low voltage on output pins

i have built a reed switch tachometer to measure the rpm of a bike wheel. depending on the rpm i the arduino to switches on different outputs via relays.

the trouble i am having is that when the output pins (pins 12-9) read HIGH they only give a voltage of 1.2v. , enough to light an led, but not enough to power the relay.

i built the relay circuit following this diagram: http://www.arduino.cc/playground/uploads/Learning/relays.pdf

the relay im using is a rayex leg-6. with an operating voltage of 4.5v -7.8v with a current draw of 60Ma.

i tested the relay circuit works by using the blink sketch (on the same pins 12-9) and it worked fine, with the pins giving a full 4.9v

I tested the output of the pin without the relay circuit plugged in and it made no difference to the pin voltage.

this is the code i am using

//-----------------------------------------------

 volatile byte rpmcount;

 unsigned int rpm;

 unsigned long timeold;
 
 int ledPin1 = 12;
 int ledPin2 = 11;
 int ledPin3 = 10;
 int ledPin4 = 9;
 int ledPin5 = 8;
 
 void setup()
 {
   Serial.begin(9600);
   attachInterrupt(0, rpm_fun, RISING);

   rpmcount = 0;
   rpm = 0;
   timeold = 0;
   
   pinMode(ledPin1, OUTPUT); 
   pinMode(ledPin2, OUTPUT);
   pinMode(ledPin3, OUTPUT);
   pinMode(ledPin4, OUTPUT);
   pinMode(ledPin5, OUTPUT);
   
 }
 

 void loop()
 {
   if (rpmcount >= 10) { 
     //Update RPM every 20 counts, increase this for better RPM resolution,
     //decrease for faster update
     rpm = 10*1000/(millis() - timeold)*rpmcount;
     timeold = millis();
     rpmcount = 0;
     Serial.println(rpm,DEC);
   }

 
 if((rpm >= 60) && (rpm < 99)){
    digitalWrite( ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
 }
 
 else{ 
  digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
 }
  
  
 if((rpm >= 100) && (rpm < 199)){
    digitalWrite( ledPin1, LOW);
    digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
 }
 
 else{ 
  digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
 }
  
 if((rpm >= 200) && (rpm < 299)){
    digitalWrite( ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, LOW);
 }
 
 else{ 
  digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
 }
  
 if((rpm >= 300) && (rpm < 480)){
    digitalWrite( ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, HIGH);
 }
 
 else{ 
  digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
 }
  }
  
  

 void rpm_fun()
 {
   rpmcount++;
   //Each rotation, this interrupt function is run twice
 }

has anyone else encountered this problem of lower voltage on output pins?

You may be PWM'ing inadvertently.

If you turn a pin on and off really fast .. you are really providing less voltage (PWM works like this).

You may be seeing the fact that your counter moves so fast that your pin is not on long enough to attain the full voltage.

Try adding a delay in your loop and see if anything changes.

hi chopeone1.

Could it be that the if( ) {} else {} statements should be if( ) {} else if( ) {}else if( ) {} with all ouputs low in the last {}

At the moment in one loop you set outputs high once and low 3 times. Simply put you've made a pwm at 25% duty.

Jeroen

that was the problem, thanks Jeroen. :-) The relay turns on fine now. i am also powering it off an external supply.