Hello. I'm new to the Arduino but have a background in c/c++ programming. I want to interface an existing circuit to the Arduino. Please see the attached for a picture of the circuit diagram. Basically it is an opto-isolator in an existing piece of equipment that drives a led via a 1k resistor from 5v. When certain events happen in the equipment, the led flashes briefly. I want to interface this to a digital pin (configured as an input) on the Arduino so that I get an interrupt everytime the led flashes. Programming-wise at the moment all I want to do is to display on the serial monitor a count of how many pulses have been received when one arrives.
Please would some kind person advise as to how I should interface this circuit to the Arduino. Can I just connect a lead to one end of the resistor (which one?) to say digital pin 2 and take 5v and ov from the Arduino board? I can change the layout of the resistor/led but can't change the opto-isolator. I would like to keep the led for a visual indication that events are happening.
Hook the bottom of the resistor(s) to the Arduino. If you want to count both LEDs, hook one to pin 2 (INT0) and the other to pin 3 (INT1). Remember to connect the equipment ground to the Arduino ground. Detect the interrupts with the attachInterrupt() function as fungus has indicated. A negative-going pulse will occur each time an LED illuminates, so set the interrupt(s) to detect falling edges.
The leds are red and green. Is that OK without the 10k parallel resistor because as suggested I've used
pinMode (pinX, INPUT_PULLUP);
for the 2 data lines (pin 2 and pin 3) to which I have them connected. It's now been running for a couple of hours and everything seems OK. I'm powering the opto-isolators and the leds from 0 & 5v on the Uno board.
Now to the next phase! I'm adding an RTC so that I can log the date/time of the pulses, an ethernet/sd shield so that I can log to the sd and retrieve the data over the network (local) for analysis.
One further question if I may. If I power the Arduino from a power pack and then unplug the USB connection, does the program still run? And if the power is switched off does the program resume running when power is re-applied even if not connected to a computer via a USB lead? Once I have the data being written to the sd card and accessed via the network I don't need a computer attached anymore. Is this possible?