Logging RPM

Hi people,
i'm working on a datalogger project here that sends data
to cosm. I have got part of it working already, but I want
to measure rpm too. I'm have got a reed contractor laying
around somewhere over here that I am willing to use. The contractor
gives a voltage of 1.3 and when you hold a magnet in front of it
it drops to 0. I am using an Arduino Mega, but I have no idea how
to implement the rpm bit into my code. Also, I'm not that good of
a programmer, so if you have some suggestions, feel free to tell me.
Here is my code:

#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Cosm.h>

// MAC address for your Ethernet shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Your Cosm key to let you upload data
char cosmKey[] = "XXXXXX";

unsigned long lastConnectionTime = 0;                // last time we connected to Cosm
const unsigned long connectionInterval = 1000;      // delay between connecting to Cosm in milliseconds

// Define the strings for our datastream IDs
char sensor0Id[] = "voltage_current_monitor";
char sensor2Id[] = "current_motor_controller";
char sensor1Id[] = "voltage_motor";
char sensor3Id[] = "vermogen";
CosmDatastream datastreams[] = {
  CosmDatastream(sensor0Id, strlen(sensor0Id), DATASTREAM_FLOAT),
  CosmDatastream(sensor1Id, strlen(sensor1Id), DATASTREAM_FLOAT),
  CosmDatastream(sensor2Id, strlen(sensor2Id), DATASTREAM_FLOAT),
  CosmDatastream(sensor3Id, strlen(sensor3Id), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
CosmFeed feed(XXXXX, datastreams, 4 /* number of datastreams */);

EthernetClient client;
CosmClient cosmclient(client);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  
  Serial.println("Starting double datastream upload to Cosm...");
  Serial.println();

  while (Ethernet.begin(mac) != 1)
  {
    Serial.println("Error getting IP address via DHCP, trying again...");
    delay(15000);
  }
}

void loop() {
  if (millis() - lastConnectionTime > connectionInterval) {
    int sensorPin0 = analogRead(A0);
    float voltagePin0 = (sensorPin0 * (5.0 / 1023.0)) * 2;
    datastreams[0].setFloat(voltagePin0);
    Serial.print("Read sensor value pin 0 ");
    Serial.println(datastreams[0].getFloat());
    
    int sensorPin1 = analogRead(A1);
    float voltagePin1 = (sensorPin1 * (5.0 / 1023.0)) * 11;
    datastreams[1].setFloat(voltagePin1);
    Serial.print("Read sensor value pin 1 ");
    Serial.println(datastreams[1].getFloat());
    
    float amperePin0 = voltagePin0 * (30.0 / 3.90);
    datastreams[2].setFloat(amperePin0);
    Serial.print("Read ampere pin 0 ");
    Serial.println(datastreams[2].getFloat());
      
    float vermogenPin1 = amperePin0 * voltagePin1;
    datastreams[3].setFloat(vermogenPin1);
    Serial.print("Read watt ");
    Serial.println(datastreams[3].getFloat());
    
    Serial.println("Uploading it to Cosm");
    int ret = cosmclient.put(feed, cosmKey);
    Serial.print("cosmclient.put returned ");
    Serial.println(ret);
    
    Serial.println();
    lastConnectionTime = millis();
  }
}

Anyone willing to help with this?

What exactly is the contactor and where does it get the 1.3volts from?
Magnetic reed switches are just two pieces of springy iron in a sealed glass tube. Bringing a magnet near to it will cause the pieces of iron to attract each other and make a contact. Some are biased the other way, the two pieces of iron are in contact and bringing a magnet near will make them repel each other, breaking the contact. They don't usually supply any voltage.

How fast is your wheel rotating?

After failing to get an IP address, your arduino will not do anything else. It'll just sit there for 15 seconds!

Hi Heny,
thanks for the reply. I'm using a contractor from a bike computer which is powered by a 1.3V battery. When no magnet is present, it gives
out a steady 1.3 volts. When you hold a magnet in front of it, the voltage drops to zero. I'm not sure what the rpm is, that's why I want to
measure it, but it is a standard bike wheel, and it should probably speed up to about 60 km/hour (powered by electromotor). I already have
the correct IP and it logs quite good, just figured I should leave out the IP, wouldn't want anyone messing with my data stream now would I xD. I'm still not sure how I should write the software.

A standard 27" bicycle wheel has a circumference of ~2.2 metres.
Your wheel, at 60KPH = 1KPM, will be turning at about 450RPM.

Thanks for the calculation,
but I still want to measure it with the arduino
and I don't know how to do that, so can anyone
please help me with that?

If you connect your "contractor" (whatever that is) to an analog pin, you should be able to read the drop in voltage when the magnet comes by. That's the first step.

The next step is to determine how long that low lasts, so that you can determine when the low pulse is complete.

Then, you have an idea when a pulse has been received. Count them for a period of time, or compute an instantaneous rpm based on the time between two pulses.

Once you have an RPM value, you can do what you want with it. There are plenty of threads about reading RPM.