# Can arduino be used as a switch?

Hello I have had zero luck with finding anything related to this problem. Lets take the most basic circuitry: switch that turns on the light

• The values on the sketch are not accurate, couldn't change the values

How can I "replace" the Switch with Arduino? Do I need Zener Diode to achieve that?

I want to use it to light up a 225V, 330Watts Lamp (I'm in Europe) that is used in my room.

• do you want to use incandescent lamp.if so then lamp is AC/DC and mention power rating too – yogece Nov 2 '13 at 14:34

If you use Arduino directly as a switch for AC supply then this is not going to work although it would cause a catastrophe because 225V across Arduino's pins are going to damage a lot.

So the solution is to use Isolation of two Arduino and the Lamp. Isolation can be done as @yogece said using a Relay and Relay driver.

Relay is kind of current operated switch i.e. if sufficient amount of current flows through Relay coil then a switch will be CLOSED otherwise remains OPENED. The current driven by a typical relay at its rated voltage is between 25mA to 70mA.

As the I/O pins of Arduino can provide maximum 40mA current (According to ATMEGA 328 Current Specifications) it is not a good idea that you directly connect it to a Relay and if you do so it may burn the Arduino. This is why you need a relay driver.

Here is a typical circuit,

simulate this circuit – Schematic created using CircuitLab

• +1 for the article and great explanation. Do I use a DC power source for arduino and AC source separately for the lamp? – Gasim Nov 2 '13 at 20:29
• Use DC power for Arduino as always. And on the "switch side" of the relay you can use any power source which is suitable to the load. Here load is an AC lamp so obviously AC mains is the suitable power source. – Parth Parikh Nov 2 '13 at 21:36
• After reading and understanding the article you have posted, I calculated an theoretical estimate of R1 based on random values and the result. The result I got is 7.57kOhms. Lets say in practice I encountered a value that is not standard value. My question is, should floor the value to 7.5kOhms or lower? I hope I made sense. Thanks – Gasim Nov 2 '13 at 22:27
• The goal of that resistor is that you must keep it low enough to provide minimum base saturation current and high enough that it won't pass extreme amount of current that would cause damage to transistor or the Arduino. Here as you said you got 7.57K calculated resistor then you may lower to 5K and it would be sufficient if it satisfies those conditions. – Parth Parikh Nov 3 '13 at 4:27

You can use the Arduino to drive a relay that switches the high voltage circuit.

There are relay boards and daughterboards ("shields") for this purpose. Look for one with proper protection - isolation of high voltage side of circuit from low-voltage side.

As you are in a 230V AC country (or region) make sure the relay is not 110 V rated.

• I don't know if its an appropriate question in this forum, but can I rely on Sainsmart for relays? – Gasim Nov 2 '13 at 20:31

There are two possible solutions 1)Using TRIAC(with/without isolation) 2)using Relay(with/without isolation)

Look at this circuit diagram . It uses 5V relay(if you use +12v relay it would save you few cents but you have to have +12v supply too;if you have 12v you can use 12v relay). If you want to isolate the HV and LV side you could use a simple optocoupler like PC817 with this existing circuit.