Switching the Dimmer 'on' and 'off' affects my computer

Hi. I have my dimmer connected to the 3 parallel 35W 220V halogen lamp, which is connected to the relay, which is controlled by the microcontroller. I turned on my relay, and why is it that when I switch my dimmer on & off my computer responds by making the sound (the sound when it detects something being connected to the computer). It happens indefinitely, like switching the dimmer three times (on & off) makes 1 beep sound. This becomes a problem to me because I am making a real time data logger using Matlab, and when the beep sounds, MATLAB stops logging the data. Thanks

So we now know what's happening, but have no real idea why because we haven't got any information about 1) Your circuit, power supply, etc. 2) Your code

Please read the sticky thread about how to post here and follow its guidance... It will save time in the end.

What are you powering via the USB port(s) on your computer?

What are you powering via the USB port(s) on your computer?

The dimmer is connected to the 220V plug and my Arduino is powered through the computer

Arduino Sketch

#include <dht.h>

dht dht11_sensor; 

const int dht11_pin = 15; 
const int dig_heating_pin = 14; 
int trueVal_inC; 
int readVal_inC; 
double temperature_Val; 

void setup()
{
	Serial.begin(9600);
	while(!Serial){;}
	
	pinMode(dht11_pin, INPUT); 
	pinMode(dig_heating_pin, OUTPUT);  
}
void loop()
{
	int cmd_sel; 
	int val_terminate = 0; 
	if(Serial.available() >= 2)
	{
		cmd_sel = Serial.read(); 
		delay(10); /*10 second time-delay for serial COM*/
		while(Serial.available() != 0) {Serial.read();}
		Serial.println(cmd_sel); 
		switch(cmd_sel)
		{
			case 1: 
				while(Serial.available() == 0) {;}
				trueVal_inC = Serial.read(); 
				delay(10); /*10 second time-delay for serial COM*/
				while(Serial.available() != 0) {Serial.read();}
				Serial.println(trueVal_inC);  
				break; 
			case 2:
				while(true) 
				{ 	temperature_Val = read_temp(); 
					Serial.println(temperature_Val); 
					if(temperature_Val <= trueVal_inC)
					{	digitalWrite(dig_heating_pin,1); 	}
					else
					{	digitalWrite(dig_heating_pin,0);	}
					if(Serial.available())
					{	val_terminate = Serial.read(); 
						delay(10); 
						while(Serial.available() != 0) {Serial.read();}
						if(val_terminate == 1)
						{	digitalWrite(dig_heating_pin,0); 
							break;	}
					}
				}
				break; 
			default: break;
		}
	}
}
double read_temp()
{
	double val_accumulated = 0; 
	double val_return = 0; 
	int index = 0; 
	for(; index < 5; index++)
	{
		dht11_sensor.read11(dht11_pin); 
		readVal_inC = dht11_sensor.temperature;
		val_accumulated += readVal_inC; 
		delay(200); 
	}
	val_return = val_accumulated/(index); 
	return val_return; 
}

Circuit Diagram
1Cg7Bf2sr4LMR8EwfCiKZfS7RjoAbNnEj7

Sorry i got the wrong link. Here is my circuit. Thanks

http://bayimg.com/pAPNmAafh

That circuit is obviously incomplete and uses wrong symbol for a relay.

Relays should not be driven direct from an Arduino pin since they typically take much more current than a pin can supply.

You must always use a free-wheel diode (or snubber network) when driving a relay or you'll destroy your circuit. Inductors will generate 1000's of volts if you don't provide a safe path for current to continue.

Here's how its done:

The base resistor depends on the switching transistor and load current, if in doubt use 220 ohms for an NPN BJT or logic-level n-channel MOSFET and 1k for an NPN darlington.

The freewheel diode must be able to handle the winding current (it provides a harmless path for current to flow round when the transistor switches off).

That circuit is obviously incomplete and uses wrong symbol for a relay.

https://docs.google.com/file/d/0BxdLxDCD6HidZF9JYXd0MUEtWjA/edit?pli=1

Sorry for the one I posted, this is the relay I used which I used, I bought it from a local electronic store. The Logic Input in here is the one I am referring to as connected to the Arduino I/O.

Hi, in your circuit diagram you show the coil of the relay connected to the output of the arduino and "gnd" which is part of the 220Vac supply.

Is that correct?

If so, turn it off and don't use it.

Can you post an accurate circuit diagram of the arduino, relay board connections and the lamp connections please.

Even a picture of a hand drawn diagram will be good, in jpg, png or pdf format.

Tom....... :)

Even a picture of a hand drawn diagram will be good, in jpg, png or pdf format.

http://bayimg.com/HapOCAafH

I noticed. When the computer makes that beep sound, I stopped receiving data from the Arduino in my Matlab GUI. Thanks

johnvictorlim:

Even a picture of a hand drawn diagram will be good, in jpg, png or pdf format.

http://bayimg.com/HapOCAafH

I noticed. When the computer makes that beep sound, I stopped receiving data from the Arduino in my Matlab GUI. Thanks

240v linked to ground?

Normally I'd have said the relay's emf is to blame, but the last circuit you posted suggests mains voltage is shared.

(single phase) mains circuits must run from live to neutral, not live to earth.

Any circuit directly connected to the mains supply must be treated as live. Only circuits isolated by say mains transformers or relays can be at earth potential (unless there is a fault).

In particular neutral is not the same as PE (protective earth), the symbol for which you have connected to Arduino ground.

Neutral can be at 220VAC if there is a fault in a 220V circuit, though typically would be around 0 to 20Vac (and capable of a large amount of current).

240v linked to ground?

Yes, I connected all the lowest potential to the Arduino 'gnd' pin, but I was first quite unsure whether to connect the other wire of the flat chord from the plug to the same ground . Sorry if I don't quite understand, but are you suggesting that the other wire should not be connected to the microcontroller's gnd? Should I connect this wire (referrring to the other wire of the flat chord) to the other end of the relay instead of the Arduino 'gnd'. Thanks

(deleted)

johnvictorlim:

240v linked to ground?

Yes, I connected all the lowest potential to the Arduino ‘gnd’ pin, but I was first quite unsure whether to connect the other wire of the flat chord from the plug to the same ground . Sorry if I don’t quite understand, but are you suggesting that the other wire should not be connected to the microcontroller’s gnd? Should I connect this wire (referrring to the other wire of the flat chord) to the other end of the relay instead of the Arduino ‘gnd’. Thanks

Have you read my posting above about your use of mains ??

Can you convince us you are not doing something dangerous with your
set-up??

If in the slightest doubt do not use your circuit as it stands

You appear not to know the differences between neutral, protective earth and
circuit ground.