Gentlemen,
I removed the muxShield (the multiplexer) and wrote a similar code with only 2 sensors and I used digital pins 5 and 6. This works just fine. See the code below.
I think the pin conflict is what's causing the problem. Look at the code below. Can you please suggest a solution?
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
const int pinNumber1=5;
const int pinNumber2=6;
byte dataBuff[2];
int sensorVal1;
int sensorVal2;
byte arduinoMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress arduinoIP(192, 168, 1, 192); // desired IP for Arduino
unsigned int arduinoPort = 8888; // port of Arduino
IPAddress receiverIP(192, 168, 1, 135); // IP of udp packets receiver
unsigned int receiverPort = 6000; // port to listen on my PC
EthernetUDP Udp;
void setup() {
Ethernet.begin(arduinoMac,arduinoIP);
Udp.begin(arduinoPort);
pinMode(pinNumber1, INPUT);
pinMode(pinNumber2, INPUT);
Serial.begin(9600);
}
void loop(){
int dataChanged=readData();
if(dataChanged){
ProcessData();
}
}
int readData() {
int dataChanged=0;
sensorVal1=digitalRead(pinNumber1);
sensorVal2=digitalRead(pinNumber2);
if (sensorVal1 != 1 || sensorVal2 != 1) {
dataChanged=1;
}
return dataChanged;
}
void ProcessData() {
Serial.println("Process");
dataBuff[0] = (char) sensorVal1;
dataBuff[1] = (char) sensorVal2;
Udp.beginPacket(receiverIP, receiverPort);
Serial.println("UPD Recieved");
Udp.write(dataBuff, sizeof(dataBuff));
Serial.println("UPD Written");
Udp.endPacket();
Serial.println("UDP Ended");
}