Random output to simulate faulty lamp

Hi There,
A friend would like to construct a lamp that flickers randomly so that it appears faulty.
(Not a cycling on/off)
Can the arduino directly drive a 12VDC relay?
Could someone help with code to cause random flickering?

Hello and welcome,

What kind of lamp is it?

If you want to drive the relay with Arduino, then you need a 5VDC relay. Else, you need an external 12VDC power supply

These are cheap:

The code could be as simple as:

const uint8_t relayPin 3

void loop()
{
  digitalWrite( relayPin, HIGH ); // turn relay on
  delay( random( 100, 1000 ) ); //wait a random amount of milliseconds
  digitalWrite( relayPin, LOW ); // turn relay off
  delay( random( 10, 200 ) ); //wait a random amount of milliseconds
}

It is possible that your relay will be active low, in which case to turn on the relay you must write a LOW and to turn off you must write a HIGH

Newbie's first post, so don't forget to setup the output pin:

void setup(){
  pinMode(relayPin,OUTPUT);
}

I'd probably go for a solid-state relay myself, as it'll last much much longer than a mechanical/solenoid type with this sort of flickering.

Mark_Grass:
Newbie's first post, so don't forget to setup the output pin:

void setup(){

pinMode(relayPin,OUTPUT);
}

Yep, sorry I forgot this

toxibunny:
I'd probably go for a solid-state relay myself, as it'll last much much longer than a mechanical/solenoid type with this sort of flickering.

True

For effect a 12v downlight and a mosfet would do the job nicely....

For 110/240

A Triac or SSR or you'll wear out the mechanical contacts quickly....

l

I plan on using a 12V 15W incandescent lamp with an external power supply- so that's a fair amount of current.

Any suggestions for the interface?
How would I connect a mosfet?
Cheers

Sorry for the crude attached image, but it was quick. N channel mosfet. Make sure it's a logic level. IRL####

Unlike a regular inductor (be an electromagnetic or door lock) does the influence of the fact the light bulb turns it all to heat and light? mean there's no kickback in the forum of inductance? if so....

The mosfet lacks a diode?.

A standard incandescent light bulb is not inductive. A fluorescent bulb ballast is. So you don't need a diode.