Hi,
Arduino noob here. I've been researching this for a few days with no luck, so I apologize if my answer is already here and I just can't find it.
Short background. I'm building a system that stops an operator from using a compressed air assembly press in the wrong order. Just a few positional dip switches to make sure they don't forget what they did last. And a Power Tail II to cut off the power to the machine if they get out of order.
Arduino Uno Rev. 3
The serial output on my Uno freezes after anywhere from 30 seconds to 3 hours of usage. The TX light stays lit and the serial output stops feeding to the Serial Monitor in the IDE. The UNO continues to read the sensors and operates the program accordingly. I assumed it's power related so I tried running an extension cord for the Uno and Computer but it didn't improve the results at all. It seems very related to the machine firing (Even though it's an air powered piston). I want to rule out coding errors before I beat my head against the wall chasing down ground issues on the machine.
The serial output is just 3 numbers that are interpreted by Processing.org
#define Button 8
#define Switch 10
#define Connect1 5
#define Connect2 8
#define VertConnect 12
int Marker = 1;
boolean pushState = false;
boolean lastPush = false;
boolean lastSwitch = LOW;
void setup()
{
pinsInit();
Serial.begin(9600);
}
void loop()
{
int POS1 = digitalRead(Connect1);
int POS2 = digitalRead(Connect2);
int VERT = digitalRead(VertConnect);
if(POS1 == 1){
Serial.print(F("1"));
if(lastSwitch != HIGH) {
lastSwitch = HIGH;
}
}
else if(POS2 == 1) {
Serial.print(F("2"));
if(lastSwitch != HIGH) {
lastSwitch = HIGH;
}
}
else {
Serial.print(F("0"));
if(lastSwitch != LOW) {
digitalWrite(Switch, LOW);
lastSwitch = LOW;
}
}
if(VERT == 1) {
pushState = true;
Serial.print(F(" 1"));
}
else pushState = false;
if(lastPush != pushState && pushState == true) {
if(Marker == 1) Marker = 2;
else Marker = 1;
}
lastPush = pushState;
if(Marker == 1) {
if(POS1 == 1) {
Serial.println(F(" 1."));
digitalWrite(Switch, HIGH);
}else {
Serial.println(F(" 2."));
digitalWrite(Switch, LOW);
}
} else if(Marker == 2){
if(POS2 == 1) {
Serial.println(F(" 3."));
digitalWrite(Switch, HIGH);
} else {
Serial.println(F(" 4."));
digitalWrite(Switch, LOW);
}
} else {
Marker = 1;
digitalWrite(Switch, LOW);
}
delay(500);
}
void pinsInit()
{
pinMode(Connect1, INPUT);
pinMode(Connect2, INPUT);
pinMode(VertConnect, INPUT);
pinMode(Switch, OUTPUT);
}
Thanks for a wonderful product, and your help!
Follow up question. If my sensors have direct contact with the machine being fired, do I need to ground the Arduino circuit back to the machine(110v)?