Hi all,
I'm very new to Arduino programming and am having issues with noise interference on my digital pins.
I have an Arduino Mega and an Ethernet shield I'm trying to have a 4 micro switch Joystick (with a 5th switch for the button) control a UI in Touchdesigner via OSC messages from the Arduino. I'm doing this by having the digital input pins (23,25,27,29,31) send a 1 when it receives high voltage from the NO pin of each different micro switch. For some reason there is a lot of digital noise causing the pins to send false 1's to Touchdesigner. I'm not very good with electronics and don't have an understanding if my circuit is correct or if I need to put resistors in line before each pin to mitigate this. I also don't have a clear schematic written out but will provide pictures and my code for a clearer picture.
I have a 5v PSU sending positive to all of the common pins on the microswitch and the negative to one of the ground pins on the Arduino mega I'm not sure if this can indicate if my circuit is incorrect or not.
Another thing to note that when each pin is connect to a multimeter the voltage for switch works perfectly as in 0v for nothings and 5v when activated.
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <OSCMessage.h>
EthernetUDP Udp;
// Arduino's IP
IPAddress ip(192, 168, 1, 105);
// Destination IP
IPAddress outIp(192, 168, 1, 2);
const unsigned int outPort = 8001;
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
void setup() {
Ethernet.begin(mac, ip);
Udp.begin(8888);
// Initialize digital pins as inputs
pinMode(23, INPUT);
pinMode(25, INPUT);
pinMode(27, INPUT);
pinMode(29, INPUT);
pinMode(31, INPUT);
}
void loop() {
sendOscMessage(23, "/select");
sendOscMessage(25, "/left");
sendOscMessage(27, "/right");
sendOscMessage(29, "/up");
sendOscMessage(31, "/down");
}
void sendOscMessage(int pin, const char* address) {
OSCMessage msg(address);
int value = digitalRead(pin);
msg.add(value);
Udp.beginPacket(outIp, outPort);
msg.send(Udp); // send the bytes to the SLIP stream
Udp.endPacket(); // mark the end of the OSC Packet
msg.empty(); // free space occupied by message
// Increased debouncing delay
delay(20); // Adjusted delay to better mitigate noise.
}