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.

REED relay speed

Status
Not open for further replies.
Hello. I did electric scooter myself, and i have one problem with speed measurement

Recently i successfully programmed speed sensor on my scooter with reed relay. Max speed is 30kmph, so relay is fast enough (0.26m is diameter of the wheel). It worked very well until glass of that relay broke down.

Now i dont have exactly the same code, but here is what i have and how i think it should work:
Code:
/SPEED
  if (time > 0) {
      period = (time)/1000;
      speedmps = 0.8/period;
      speedkmph = speedmps*3.6;
            lcd.setCursor(0,1);    lcd.print ("Speed:"); 
           // if (speedkmph < 1) lcd.print (" ");            
           // if (speedkmph < 10) lcd.print (" ");
           // if (speedkmph < 100) lcd.print (" ");
            lcd.print (speedkmph);
                        }
            else {lcd.setCursor(0,1);  lcd.print ("Speed:   0"); }
  delay (10);
and this:
Code:
void fan_interrupt()
{
  time = (millis() - time_last); 
  time_last = millis();
 
}

So on every rising edge, time and time_last should be stored, and speed printed out.

When i short 2 pins that are usually connected to reed relay, it does work. Every "tap" i get new speed. But when i connect my reed relay it usually show "Speed: 0" or 2880.

I have tested relay with multimeter if it works, and it does what it should. I really don't understand what is happening here so please help me.

Here is the full code is someone needs to help me, controler is arduino uno
Code:
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <math.h>

 Servo esc;
 int throttlePin = 0;
 int LED = 8;
 unsigned int rpmilli;
 float speedmps = 0;
 float speedkmph = 0;
 double Thermistor(int RawADC) {
   long Resistance;  double Temp; 
   Resistance=((10240000/(1024-RawADC)) - 10000);  // 10k Thermistor, in lower part
   Temp = log(Resistance); 
   Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));   
   Temp = Temp - 273.15;                                     
   return Temp;  
 }
 
 volatile float time = 0;
 volatile float time_last = 0;
 volatile float period = 0;

 LiquidCrystal_I2C lcd(0x20, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
 
void setup()
{
  pinMode(LED, OUTPUT);
  esc.attach(3);
  Serial.begin(9600);  // Used to type in characters
  attachInterrupt(0, fan_interrupt, RISING);
  #define ThermistorPIN 1   // Analog Pin 0
  double temp;

  lcd.begin(20,4);       
  lcd.backlight();   
  lcd.setCursor(2,1);   lcd.print("Electric Scooter");
  lcd.setCursor(4,2);   lcd.print("Version: 1.0");
  esc.write(0);
  delay(200);
  lcd.clear();
}

void fan_interrupt()
{
  time = (millis() - time_last); 
  time_last = millis();
  //speedkmph++;
}

void loop()
{

  digitalWrite(LED, 0); 
  lcd.home ();
  
  //THROTTLE
  int throttle = analogRead(throttlePin);
  throttle = map(throttle, 0, 1023, 43, 128);
  esc.write(throttle);
  int throttlePercent = analogRead(throttlePin);
  throttlePercent = map(throttle, 57, 115, 0, 100);
            lcd.setCursor(0,2);   lcd.print ("Throttle:"); 
            if (throttlePercent < 1) lcd.print (" ");            
            if (throttlePercent < 10) lcd.print (" ");
            if (throttlePercent < 100) lcd.print (" ");
            lcd.print (throttlePercent);
  
  //SPEED
  if (time > 0) {
      period = (time)/1000;
      speedmps = 0.8/period;
      speedkmph = speedmps*3.6;
            lcd.setCursor(0,1);    lcd.print ("Speed:"); 
           // if (speedkmph < 1) lcd.print (" ");            
           // if (speedkmph < 10) lcd.print (" ");
           // if (speedkmph < 100) lcd.print (" ");
            lcd.print (speedkmph);
                        }
            else {lcd.setCursor(0,1);  lcd.print ("Speed:   0"); }


                   
  //TEMPERATURE    
  double temp=Thermistor(analogRead(ThermistorPIN)); 
  lcd.setCursor(0,0); lcd.print ("Temp: ");
  lcd.print (temp); lcd.print ("C");
 
delay (10);
}
 
If it worked once (until the glass broke).. then why don't you fix the sensor. Assuming that the "broken glass" is a broken reed relay. You can not fix that kind of problem with software.
 
Last edited:
is the magnet that trips the reed switch still properly positioned, is it strong enough, is it close enough?
 
Of course, i replaced reed relay with a new one. I thought then that something is wrong with that one too so i bought next one. And it is all the samw.
For the testing i removed reed from my scooter and i hold it in my hand while tiping with the magnet. I can hear that reed is working, and it really do because i have tested it with multimeter
Is my code allright? Unfortunatelly i lost my first version of the code thats why i am not sure now, but it is wierd that without reed, just with regular switch, it is working jhst fine..
 
Of course, i replaced reed relay with a new one. I thought then that something is wrong with that one too so i bought next one. And it is all the samw.
For the testing i removed reed from my scooter and i hold it in my hand while tiping with the magnet. I can hear that reed is working, and it really do because i have tested it with multimeter
Is my code allright? Unfortunatelly i lost my first version of the code thats why i am not sure now, but it is wierd that without reed, just with regular switch, it is working jhst fine..

hi,

Look thru this PDF for magnet/reed alignment.

E
 

Attachments

  • ReedMagnet.pdf
    314.9 KB · Views: 164
Thank you, alignment may be the reason why it didnt work. Now i get my impuls 80% of time. But im putting magnet near reed with my own hand. I will put this on my scooter again to see if it work then
 
They use reed switches on bicycle computers, allthough the wheel is much bigger therefore rotates slower they are still good for 50+ mph so I think a reed will do what you want.
I've messed with reeds recently and yes at least the one I messed with is very directional to the actuating magnetic field, even down to north and south poles, the application rotates up to 12k rpm.
 
Don't forget to bargain in the contact bounce - reed relays can still have quite some bounce to them.
 
Yep.. alignment was a problem but not the only one. Now i am testing it again. But even without debounce, it was giving me correct speed value (top speed is 30kmph)
 
No... i think there is something in the code. Reed is working just perfectly. I have positioned magnet and reed just like ericgibbs said. And measured with multimeter it is working without any problem. When i put it to scooter, my display shows me the speed very rarely. Thats why i thought that my code isnt right? I dont know..

EDIT:

WOW WOW WOW
Now, when magnet passes near the reed, my whole board and display turn off. Like gnd and + are shorten. But i dont understand why this is happening because it is only a signal, it can be whatever it wants and board should be on all the time of course...
 
Last edited:
hi ra,
Do you have a connection diagram you could post.?

E
 
Yep, here it is
ScooterV1.jpg

Please tell me if you see something wrong

The last problem i had (reseting) is gone. Wire that connects REED, R3 and pin 4 on arduino is really a wire and when i moved it with a finger, the problem was gone.
Also note that R6 is not connected to REED part.
 
hi,
The output of the 7805 seems to be wired incorrectly , as shown on the diagram.???

E.
 
Why? Now i see that diode D1 is turned incorrectly, but the rest is ok, isnt it? On board that diodes is turned ok.. (and after + of battery)
 
The whole 7805 seems to be incorrectly wired (apart from the input). The ground is connected to AVCC and both sides of the power on LED :D The output of the 7805 isn't effectively connected to anything :rolleyes:

And D1 appears to be the wrong way round.
 
:D now i am confused. I think my schematic is not good. Here is PCB. Power part is ok, because everything is working besides REED relay. Note that on this pcb R14 (from REED) is connected to pin 4 of atmega 328P..
BoardV1.png
 
They use reed switches on bicycle computers,

This might be on some bike computers, but the one I put on my bike uses a Hall sensor. Wouldn't a Hall sensor be a better option for this circuit? No worry of switch bounce then, either.
 
Status
Not open for further replies.

Latest threads

Back
Top