Software reset example, using a 4N35 Opto-Isolator as the Reset gatekeeper.

This project is designed to demonstrate the use of a number of code and hardware principles, including the use of the Arduino millis() function, a custom function that  converts an analogue input into a voltage, and the use of the Serial Monitor to view the results of the conversion.  

Key to the project, however, is the use of an opto-isolator as gatekeeper for a software driven reset event. 

In this experiment, a voltage is applied to an analogue pin.  Where the voltage rises above a present value, a software driven reset is invoked.

In practice, the software reset could be driven using a number of different methods, including sensor boundary limits, as in this example, using remote control IoT events, though the use of interrupts, or through the use of watchdog timers used to reboot the Arduino if a software or hardware sequence gets out of kilter.

There are a number of ways to achieve a reset:  Using a transistor driven by an output pin (Check out ForceTronics achiveing this with a software interupt), a relay switch mechanically making an electrical circuit between the Reset pin and Ground, or using an internal register (Reset_AVR()) are a few examples.  Each of these techniques has advantages and disadvantages. 

The alternative offered in this example uses a phototransistor; a light-sensitive transistor. A common type of phototransistor, called a photobipolar transistor, is in essence a bipolar transistor encased so that when light strikes the photoelectric surface of the device, the electrons generated are injected into the base of the transistor, switching on the device and allowing electrons to flow through the transistor collector/emitter.

In the case of an opto-isolator, a phototransistor is coupled with an input LED.  When lit, the LED, creates the photons necessary to switch on the transistor.

The advantage in this application type is that the transistor, which is being used as the switch in the circuit, will only ever be 'on' if the counterpart input LED is lit.  The LED will only ever be lit long enough and bright enough to trigger the phototransistor if it is actively driven.  The only other component required is a resistor to limit the current drawn by the LED, making this a very low power, reliable, cheap, and easy to assemble alternative.

In this experiment a variable resistor provides a 0 to 5 voltage reference to analogue pin A0. The 10 bit on board ADC (Analogue to Digital Converter) converts the voltage applied into an integer (0-1023) within the Arduino script.

The getVoltage function calculates the voltage supplied from the ADC input, and prints the result to the Serial Monitor.

If the voltage supplied is greater than 4 volts, the softReset function is called.

With the D3 pin set to HIGH, a positive voltage is applied to the Anode of the Input diode in the opto-isolator. R1, a 220-ohm resistor, is placed in series to limit the current passing through the LED.

The voltage across the input LED inside the 4N35 IC rises very quickly; from 0v to approximately 1.4 volts in around 6ns. Of course, the voltage would rise further; up to 5 volts at peak, but as the input diode illuminates, the output transistor, energised by the release of photons from the input LED, is switched on.  The Collector of the 4N35 output transistor is then connected to the Emitter, effectively grounding the Reset pin on the Arduino, and resetting the board.

Once the voltage applied to A0 has been reduced to below 4 volts, the Arduino will complete a reboot cycle and continue reporting the value of the voltage applied to the serial monitor.  If the voltage applied to A0 is above 4 volts, the board will continually reset.

While in a stable running state, the script will also switch on and off (toggle) the on-board LED (Pin 13 on the Arduino Uno) for a visual indication of the state of the programme.