MyoWare signal fluctuation

Hi all, Im also using MyoWare as an input signal control in arduino. However, when the digital output is connected to a relay module, there are some fluctuations. My codes are as below. Any idea where the fluctuation com from? I'm using the processed signal output directly. Many thanks !

Imgur

void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(30,OUTPUT);
}

void loop() {
// read the input on analog pin 3 and pin 1:
int sensorValue = analogRead(A3);
int var = analogRead(A1);

// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue* (5.0 / 1023.0);
float threshold = var* (7 /1023.0);
// print out the value you read:
Serial.print(voltage);
Serial.print(" ");
Serial.println(threshold);


if (voltage > threshold)
{
 digitalWrite(30,1);
 delay(100);
}
else
{
 digitalWrite(30,0);
 delay(100);    
}

}

Any idea where the fluctuation com from?

Probably from the hardware. Relays include coils and coils have reverse current flowing if they are turned off. If you don't take countermeasures (fly-back diode) you have these spikes in your power system and that builds the base of the internal ADC.

Post a complete wiring diagram of your setup!

sorry that I dont have a proper wiring diagram. But the brief connection is as below:

That's not a wiring diagram but a system overview, I want to see every wire. This diagram can be hand-drawn. Does the relay have a fly-back diode (so from you D-out pin to GND)? Otherwise the Arduino gets the whole fly-back current of the relay coil. You're lucky if doesn't get damaged.

That configuration doesn't provide any isolation between you and the power grid.


Is there a diode on the module?

Is there a diode on the module?

It seems. But we don't know how it's used without having the schematic of the board. Please post that boards schematics.

Your pump motors are very close to the Arduino - that only could cause interference.