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?