monitor external discretes with digital IO pins.

Hello all,

I am new to the Arduino UNO. So far I like the product, but I need clarification.

I know that the UNO can sense either a high or low on the digital IO pins, but this is essentially a voltage measurement relative to the UNO's own circuit ground.

Is there a way that the digital IO pins can look for a high or low (0-5 VDC) in reference to a separate ground?

I need something to record multiple on / off states on an external system. However, this external system is not powered by the arduino. Is this possible?

Basically no, the voltage must be referanced to the Arduino's ground.

The answer is to either connect the grounds together or use an opto isolator.

Thanks for the quick reply. So, if I simply connect my external system ground to the arduino ground, it is possible?

If so, that is easily doable.

If you want complete isolation, the optoisolator is you safest way. That way there is no need to connect any voltage or ground to your Arduino.

It depends on your actual usage as to which method is best. Describe what you are monitoring.

If the external circuit signal can go above 5v, use the isolator.

Weedpharma

Yes it is simple to connect the two grounds together. Where you might want / need isolation is where for example one system is connected to a high voltage system like the mains.

i will try to post my code

I need to be able to make my readings export to excel.

Three ways to do this:-

  1. Use an Arduino Leonardo and make it look like a computer keyboard. Then when you simply write to the PC and it is as if you had typed it on the computer's real keyboard. This also works with the Arduino Micro as well.

  2. Get an SD card and write your data to that in a coma separated value way. Then transfer the SD card to your computer for reading.

  3. Write some sort of helper application on the computer in the language of your choice, Processing is a popular choice. Get this application to read from the serial port and write a CSV file to the hard drive. Then open this in the spread sheet.

OK. I will get an SD shield of some sort. I will need some help more than likely to do the comma separated values. I have read some information about it, and it confuses me. To be continued.

Thanks for the help.

I will need some help more than likely to do the comma separated values.

You write the value, then you write a comma. Continue to do this until you have written a line of spread sheet values and then you write a carriage return '\n'

Repeat for how ever many lines you want. When you create the file name it "something dot CSV"

Excel has the ability to read the CSV file directly into a spread sheet and will put each value into its own cell.

Weedpharma

That is what I understand. But, if I'm not mistaken, I need an SD shield to do this. The arduino UNO on its own can't get a csv file to my PC.

Also, look at my code above. I am not sure of how to type my 5 values into a csv format. As of now, I have the 5 values (4 voltages, and one digital). The voltages are displayed on an LCD and the serial monitor, and the digital signal is just displayed on the serial monitor.?

What are the key strokes to make these csv?

From my recollection, you would send the 5 values separated by a "," and a "CR" at the end to separate each record.

This would give 5 columns in Excel with however many readings taken. Each "CR" would start a new row on the spreadsheet.

Weedpharma

You only need an SD card with one of the three solutions I outlined.

james_airman:
That is what I understand. But, if I'm not mistaken, I need an SD shield to do this. The Arduino UNO on its own can't get a csv file to my PC.

Of course it can. You are already sending the data to the PC via the serial monitor. You just need something on the PC to write it to the file.

Please read section 7 of the instructions on how to post in the forum, then go back and modify your posting #5 so that the code can be managed properly.

Thanks for the reply. I went back to posting 5. I updated my code too. Can you take a look at my attempt at comma separated values at the end? I have tried researching it, but I am not too confident.

Thanks again

Hi, james, it is not advisable to go back to previous replies and make sketch changes.
Please post a new listing, because when you edited the sketch in reply #5 you have now made the ability of this thread to help someone else a bit difficult.
The flow of your sketch development is now not chronological.

Tom...... :slight_smile:

Thanks for correcting me. I have removed my code from post 5. Here it is. Please take a look.

Thanks for the input.  It was so simple.  I realized that I had already been doing that for some analog inputs.  I feel small.  I am monitoring if a 28 VDC signal is on or off.  I am using a voltage divider to make the voltage safe for the arduino digital IO.  I hooked it up this morning, shared the grounds and all is well.

I have one last piece of the puzzle I need help on.  I need to be able to make my readings export to excel.  Here is my code.  It is a bunch of spliced together codes from stuff that I have found online and also some simple modifications by me.  Have pity on me, I have only been looking into arduinos since Christmas.

Thanks,

[code]/*--------------------------------------------------------------
  Program:      voltmeter_LCD

  Description:  4 channel DC voltmeter with voltages displayed
                on LCD to 1 decimal place
  
  Hardware:     Arduino Uno with voltage dividers on A2 to A5.
                2 x 16 LCD connected to standard pins used in
                Arduino example sketches from IDE.
                
  Software:     Developed using Arduino 1.0.5 software
                Should be compatible with Arduino 1.0 +

  Date:         27 May 2013
 
  Author:       W.A. Smith, http://startingelectronics.com
--------------------------------------------------------------*/
#include <LiquidCrystal.h>

// number of analog samples to take per reading, per channel
#define NUM_SAMPLES 10
// voltage divider calibration values
#define DIV_1    11.1346
#define DIV_2    11.1969
#define DIV_3    11.0718
#define DIV_4    11.0718
// ADC reference voltage / calibration value
#define V_REF    4.991

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int sum[4] = {0};                // sums of samples taken
unsigned char sample_count = 0;  // current sample number
float voltage[4] = {0.0};        // calculated voltages
char l_cnt = 0;                  // used in 'for' loops
int DSC1 = 8;
void setup()
{
    lcd.begin(16, 2);
    pinMode(DSC1, INPUT);
    Serial.begin(9600);
}

void loop()
{
    // take a number of analog samples and add them up
    while (sample_count < NUM_SAMPLES) {
        // sample each channel A2 to A5
        for (l_cnt = 0; l_cnt < 4; l_cnt++) {
            sum[l_cnt] += analogRead(A2 + l_cnt);
        }
        sample_count++;
        delay(10);
    }
    // calculate the voltage for each channel
    for (l_cnt = 0; l_cnt < 4; l_cnt++) {
        voltage[l_cnt] = ((float)sum[l_cnt] / (float)NUM_SAMPLES * V_REF) / 1024.0;
    }
    // display voltages on LCD
    // each voltage is multiplied by the resistor network
    // division factor to calculate the actual voltage
    // voltage 1 - A (pin A2)
    lcd.setCursor(0, 0);
    lcd.print("A ");
    lcd.print(voltage[0] * DIV_1, 1);
    lcd.print("V ");
    // voltage 2 - B (pin A3)
    lcd.setCursor(8, 0);
    lcd.print("B ");
    lcd.print(voltage[1] * DIV_2, 1);
    lcd.print("V ");
    // voltge 3 - C (pin A4)
    lcd.setCursor(0, 1);
    lcd.print("C ");
    lcd.print(voltage[2] * DIV_3, 1);
    lcd.print("V ");
    // voltage 4 - D (pin A5)
    lcd.setCursor(8, 1);
    lcd.print("D ");
    lcd.print(voltage[3] * DIV_4, 1);
    lcd.print("V ");
    // reset count and sums
    sample_count = 0;
    for (l_cnt = 0; l_cnt < 4; l_cnt++) {
        sum[l_cnt] = 0;
    }
    int read1 = digitalRead(DSC1);
    Serial.println("read1,");
    delay(300);

    Serial.print("A,(voltage[0] * DIV_1, 1),V");
    delay(300);

    Serial.print("B,(voltage[1] * DIV_2, 1),V");
    delay(300);
    
    Serial.print("C,(voltage[2] * DIV_3, 1),V");
    delay(300);
 
    Serial.print("D,(voltage[3] * DIV_4, 1),V");
    delay(300);
    
}

[/code]

Why the delay(300) after each print?

The line

Serial.print("A,(voltage[0] * DIV_1, 1),V");

Will print the string "A,(voltage[0] * DIV_1, 1),V" to the serial terminal, it will not print the values of any of the variables nor will it print the result of the calculations it contains. It might as well just say:-
"this is just some random crap".

This is what I am talking about. I was told that comma separated values would work, but for some reason I am not understanding on how to set it up. I have no programming experience. Looking at my code, how would you take my 4 voltages, and 1 digital signal and have it print to the serial monitor in such a way that I could use that data in a program such as PLX-DAQ?

Because everything is in quote marks it prints out everything exactly as it is within the quote marks.
Just print the diffrent elements sepratly just like you did with the LCD only to the serial port.