Go Down

Topic: Very bizarre serial port communication loss (Read 158 times) previous topic - next topic

harryarmst

Aug 05, 2014, 01:10 am Last Edit: Aug 05, 2014, 01:36 am by Coding Badly Reason: 1
I am having a very bizarre serial port communication problem. I have written the sketch below which monitors a small voltage input from two 3VDC solar cells on analog ports 1 and 2. if the voltage difference between the solar cells is more than 30 one way, it brings digital pin 2 low, if more than 30 the other way, it brings digital pin 3 low. Digital pins 2 and 3 go to a normal 8 relay 5V input relay board. I then use a 9VDC power supply switched through the contacts of the relays to drive a motor one way or another. I connect a UNO R3 board to a computer and upload the sketch with no problem. I then start the serial monitor and it shows me the delta between the two voltages on analog pins 1 and 2. I can shade one solar cell and the delta changes accordingly. Everything works fine and as expected until every time I turn on the 9VDC power supply. Once the motor fires up to move back and forth I loose the serial communication to the arduino board. The program continues to run and the motor works fine but every time I turn the 9vdc power supply on I either get the "serial port in use" or the computer totally forgets the serial port assignment. This is readily repeatable with two different arduino boards and three different computers (two XP and one Windows 7). Since the 9VDC running through the relay contacts is totally isolated from the arduino board and associated electronics, this makes no sense at all to me. Once I reboot the computer everything is back to normal until I power up the 9VDC power supply.  HELP......

Code: [Select]
int analogPin1 = 1;     // read voltage for UP
int analogPin2 = 2;     // read voltage for DOWN
int upPin = 2;
int downPin = 3;

int up = 0; // variable to store the value read
int down = 0;

long lastMillis=0; // for serial write timer

void setup()
{
   
 Serial.begin(9600);          //  setup serial
 pinMode(upPin, OUTPUT);
 pinMode(downPin, OUTPUT);
 digitalWrite(upPin, HIGH);
 digitalWrite(downPin, HIGH);
     }

void loop()
{  
 up = analogRead(analogPin1);    // read the input pin
 down = analogRead(analogPin2);
 
if (millis()>lastMillis+1000) {
 
 Serial.print(" up-down delta= ");
 Serial.print(up-down);
 Serial.println(" ");
 
lastMillis=millis();
}
   
 // UP PIN LINES --------------------------------------------------------------------------

 if ((up-(down))>30) {digitalWrite(upPin, LOW);} else {digitalWrite(upPin, HIGH);};  //move up
 
 if (((down)-up)>30)  {digitalWrite(downPin, LOW);} else {digitalWrite(downPin, HIGH);};  //move down
   
}


Thanks,
Harry

Moderator edit: [code] [/code] tags added.

Peter_n

#1
Aug 05, 2014, 01:46 am Last Edit: Aug 05, 2014, 10:49 am by Peter_n Reason: 1
What about the relay ? Is it a module ? A cheap one from Ebay ? Are there non-etched copper hairs that connect the Arduino to the 9V ?

Robin2

Almost certainly the 9v battery can't provide enough current and when the voltage drops the Arduino resets causing the serial connection to be broken.

...R

harryarmst

Just to clarify a few things:

- Yes the relay board is a cheap eBay (Amazon actually) board:
http://www.amazon.com/Kootek-Channel-Module-Arduino-Raspberry/dp/B00C8O9KHA/ref=sr_1_2?ie=UTF8&qid=1407326732&sr=8-2&keywords=relay+board
- I could understand the comment on the voltage drop, however I am using a separate 9VDC power supply to run through the relay contacts to power the motors. I tried a 5VDC power supply and it does the same thing.
- The communication loss actually occurs after the relays are energized. I can turn the power on to the relay contacts and everything is fine until the relays start energizing.

Thanks,
Harry

PaulS

Quote
everything is fine until the relays start energizing.

Do you have caps across the relay to prevent voltage spikes?

Quote
Yes the relay board is a cheap eBay (Amazon actually) board

I'm guessing no.

Peter_n

A spark from the Relay output pins that crosses the gap and bounces back to the Arduino ? I still think that a very thin copper line between output of the relay and the rest of the board is a realistic option. However there seems to be no cap on the relay board at all, at least a capacitor to the 5V and GND is needed.
Can you check the board very good with a magnifier ? For solder that shortcuts or copper traces that shortcut? Or use a multimeter and measure the resistance from the relay output to the rest of the board.

Robin2


I could understand the comment on the voltage drop, however I am using a separate 9VDC power supply to run through the relay contacts to power the motors. I tried a 5VDC power supply and it does the same thing.


Draw a diagram showing how everything is connected and post a photo of it.

...R

Go Up