# Opto-Isolator Homemade (9 - 35 Volts With Arduino)

4,809

32

4

## Introduction: Opto-Isolator Homemade (9 - 35 Volts With Arduino)

Ever wanted to handle 9 - 35 Volts with arduino this opto isolator id gonna help you in doing so ...

This Home-made opto isolator will keep you from frying your Arduino Or other Stuff from High voltages and will allow you to work with voltages above 12 volts easily with arduino easily .....

Here i will measure the current taken by a 18 v dc fan using the opto isolator...

i will display it on a 16 x 2 LCD.

## Step 1: Getting Started !!

You Need :-

-- Arduino (Or Other Micro-Controller)

-- 10 K Resistor

-- 330 ohms resistor

-- LDR

-- LED

-- Wires

-- NPN Transistor(With Heatsink)

-- Motor(Or FAN)

-- 9 - 35 Volts Array of Battery

-- 16 X 2 LCD

-- 5 K Pot

## Step 2: The Circuit !

just follow the fritzing diagram and construct the circuit...

what the trick is that :-

you have a resistance ( about 10 k here ) you need to have a proportional value of the resistance with the voltage

eg:-

9 volts = 9 - 10 k resistor

12 volts = 10-15 k resistor

35 volts = 40 - 50 k resistor

you may want to try experimenting with different values

## Step 3: The Theory :-

Current Taken By Motor is inversly proportional to the current left in the wire that is reaching the LED.

This means that if the motor takes more power than the LED will shine less brightly

and if the fan is taking less power the LED will shine more brightly..

the LDR is inverted and is put on the LED to detect the amount of light falling on it.

if you want lesser (noise or signal interference) you may cover it with black tape.

the LDR will give an analog out to the arduino and it will detect it.

the LDR is in Pullup Mode so that if light is falling less then the analog reading will go high and if the Light is increasing then the reading will go low......

Hence arduino can safely detect the current by using an LED and LDR at safe 5 volt logic level...

the two circuits just have two connections :-

* one optical connection (which is inversly proportional) between LED and LDR.

* and a common Ground.

## Step 4: Code !!

the arduino uno will recieve an analog value between 0 and 5 volts and it will use that information to determine the current taken by the fan...

The code is as follows

[CODE/]

// Please Vote Me For The Sensor Instructables Contest

int fan = 9;

int minValue = 200 ;// Minimium(off) reading of the arduino

int val ; // variable for no. of times the fan has been HIGH

int times ; // variable for no. of times the fan has been LOW

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6 , 5, 4, 3, 2); // 16 * 2 lcd wiring

void setup() {

lcd.begin(16, 2); // 16 * 2 lcd configuration

pinMode(fan, OUTPUT);

Serial.begin(9600); // to caliberate the Opto Isolator

val = 0;

times = 0;

}

void loop() {

if (val < 100) {

digitalWrite(fan, HIGH);

lcd.print("Fan is ON");

lcd.setCursor(0,1);

lcd.print(val);

lcd.setCursor(3,1);

lcd.print("%");

lcd.setCursor(6,1);

sensorValue = sensorValue - minValue ; // the normal Opto-Isolator Reading

lcd.print(sensorValue); // to send the sensorvalue on LCD Screen

lcd.setCursor(10,1);

lcd.print("M-Amps");

lcd.print(val);

delay(100); //delay between reads for stability of lcd

lcd.clear();

}

else {

digitalWrite(fan, LOW);

lcd.print("Fan is OFF");

lcd.setCursor(0,1);

lcd.print(times);

lcd.setCursor(3,1);

lcd.print("%");

lcd.setCursor(6,1);

sensorValue = sensorValue - minValue ; // the normal Opto-Isolator Reading

lcd.print(sensorValue); // to send the sensorvalue on LCD Screen

lcd.setCursor(10,1);

lcd.print("M-Amps");

delay(100); //delay between reads for stability of lcd

if (times == 100) {

val = 0 ;

times = 0 ;

}

times = times + 1 ; // no of times fan was off

lcd.clear();

}

val = val + 1 ; // no of times fan was on

Serial.println(sensorValue);

}

[/CODE]

## Step 5: Caliberate the Sensor !!!

when the fan is off then a value will be displayed you just have to type that value as the minvalue in the starting.....

THE % DISPLAYED IS THE % TIME LEFT TILL THE FAN WILL ON/ OFF

THE DELAY IS ABOUT 10000 MILLIS OR 10 SECONDS FOR ARDUINO........ Participated in the 