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 !
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);
}
}
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.
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.