Relay shield for arduino problems

ebeowulf17

Joined Aug 12, 2014
3,274
Hopefully if I can get the sketch uploaded it should work. The motors actually came from this car kit so it should all work together
In terms of power consumption, yes. But in terms of electrical noise that crashes the Arduino, this may be a very different situation.

The car kit probably had more sophisticated circuitry driving the motors, and probably had buffering capacitors, potentially some current limiting, etc. which would reduce the impact of the motors on the Arduino itself.

Your relay kit would provide even better isolation and protection if you used separate power supplies, but when trying to run it all off of one battery, it's probably creating a worse situation for the Arduino than the car kit motor drivers did.
 

Thread Starter

Killerbee65

Joined May 15, 2017
243
Why should it work together?

Have you tried the diode?

It's should work because the motors I use I pulled from the kit that the car is from. I'd assume the company developed it so the motors could work together with the board. As for the diode I currently do not have one so this is the next best thing.
 

djsfantasi

Joined Apr 11, 2010
6,837
@ebeowulf17 made some excellent comments. Instead of just a diode, you might need an RC snubber circuit across the motor contacts.

I’ve attempted to address this noise problem in previous posts. I’ve called it EMF, but generally it’s just electrical noise.

When I posted my “why do you think...” comment, what I had in mind is exactly what ebeowulf17 pointed out. There likely is additional circuitry in the car such as a snubber circuit.

A motor connected to an Arduino directly can and often does produce electric spikes that will lock up the Arduino.
 

Thread Starter

Killerbee65

Joined May 15, 2017
243
@ebeowulf17 made some excellent comments. Instead of just a diode, you might need an RC snubber circuit across the motor contacts.

I’ve attempted to address this noise problem in previous posts. I’ve called it EMF, but generally it’s just electrical noise.

When I posted my “why do you think...” comment, what I had in mind is exactly what ebeowulf17 pointed out. There likely is additional circuitry in the car such as a snubber circuit.

A motor connected to an Arduino directly can and often does produce electric spikes that will lock up the Arduino.
So my best bet would be to just use the car board correct?
 

djsfantasi

Joined Apr 11, 2010
6,837
So my best bet would be to just use the car board correct?
If that is all you want to do... will it do what you wanted to do with the Arduino? Are you interested in learning how to identify the problem and learning how to fix it?

I ask those questions, because if you’re re-wiring the car even with the original board, what happens if it doesn’t work?
 

Thread Starter

Killerbee65

Joined May 15, 2017
243
If that is all you want to do... will it do what you wanted to do with the Arduino? Are you interested in learning how to identify the problem and learning how to fix it?

I ask those questions, because if you’re re-wiring the car even with the original board, what happens if it doesn’t work?
Yea this is all I want to do, if I run into problems then I'll let you know but for now I just want to get over this uploading sketch problem
 

Reloadron

Joined Jan 15, 2015
5,646
If the sketch upload is giving an error post the error. I know the original sample code uploads and works but I am sure there is more to your code. When code gives an error it hasn't uploaded. I thought you said all of everything worked fine less having the motor(s) connected?

Ron
 

Thread Starter

Killerbee65

Joined May 15, 2017
243
If the sketch upload is giving an error post the error. I know the original sample code uploads and works but I am sure there is more to your code. When code gives an error it hasn't uploaded. I thought you said all of everything worked fine less having the motor(s) connected?

Ron
I'll upload the sketch and error code soon
 

Thread Starter

Killerbee65

Joined May 15, 2017
243
char t;

void setup() {
pinMode(13,OUTPUT); //left motors forward
pinMode(12,OUTPUT); //left motors reverse
pinMode(11,OUTPUT); //right motors forward
pinMode(10,OUTPUT); //right motors reverse
pinMode(9,OUTPUT); //Led
Serial.begin(9600);

}

void loop() {
if(Serial.available()){
t = Serial.read();
Serial.println(t);
}

if(t == 'F'){ //move forward(all motors rotate in forward direction)
digitalWrite(13,HIGH);
digitalWrite(11,HIGH);
}

else if(t == 'B'){ //move reverse (all motors rotate in reverse direction)
digitalWrite(12,HIGH);
digitalWrite(10,HIGH);
}

else if(t == 'L'){ //turn right (left side motors rotate in forward direction, right side motors doesn't rotate)
digitalWrite(11,HIGH);
}

else if(t == 'R'){ //turn left (right side motors rotate in forward direction, left side motors doesn't rotate)
digitalWrite(13,HIGH);
}

else if(t == 'W'){ //turn led on or off)
digitalWrite(9,HIGH);
}
else if(t == 'w'){
digitalWrite(9,LOW);
}

else if(t == 'S'){ //STOP (all motors stop)
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
}
delay(100);
}


error:
Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"

Sketch uses 2072 bytes (6%) of program storage space. Maximum is 32256 bytes.
Global variables use 189 bytes (9%) of dynamic memory, leaving 1859 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "\\.\COM4": The system cannot find the file specified.


Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
processing.app.SerialException: Error opening serial port 'COM4'.
at processing.app.Serial.<init>(Serial.java:147)
at processing.app.Serial.<init>(Serial.java:82)
at processing.app.SerialMonitor$2.<init>(SerialMonitor.java:131)
at processing.app.SerialMonitor.open(SerialMonitor.java:131)
at processing.app.AbstractMonitor.resume(AbstractMonitor.java:134)
at processing.app.Editor.resumeOrCloseSerialMonitor(Editor.java:2135)
at processing.app.Editor.access$1300(Editor.java:117)
at processing.app.Editor$UploadHandler.run(Editor.java:2109)
at java.lang.Thread.run(Thread.java:748)
Caused by: jssc.SerialPortException: Port name - COM4; Method name - openPort(); Exception type - Port not found.
at jssc.SerialPort.openPort(SerialPort.java:167)
at processing.app.Serial.<init>(Serial.java:136)
... 8 more
Error opening serial port 'COM4'.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
 

Reloadron

Joined Jan 15, 2015
5,646
OK, on your computer with the Arduino connected to your USB port let's see where the Arduino actually is. Open the Device Manager in Windows and look down and expand Ports (Com and LPT) . You should see your Arduino and which port it is using. Next in the Arduino IDE click Tools and from the drop down make sure the correct board shows up, as in Arduino/Genuino Uno and make sure Port reflects the correct port. Additionally make sure your port baud rate and Arduino baud rate are set the same. Looks like the IDE is not seeing your Arduino board. We need to tell the IDE where to look.

Next if looking at your code you plan to run motors in both directions FWD & REV your best bet would be your old motor board simply because it includes an H Bridge to reverse motor polarity. Also, when posting code it comes out better if you use code tags.
{code}
char t;

void setup() {
pinMode(13,OUTPUT); //left motors forward
pinMode(12,OUTPUT); //left motors reverse
pinMode(11,OUTPUT); //right motors forward
pinMode(10,OUTPUT); //right motors reverse
pinMode(9,OUTPUT); //Led
Serial.begin(9600);

}

void loop() {
if(Serial.available()){
t = Serial.read();
Serial.println(t);
}

if(t == 'F'){ //move forward(all motors rotate in forward direction)
digitalWrite(13,HIGH);
digitalWrite(11,HIGH);
}

else if(t == 'B'){ //move reverse (all motors rotate in reverse direction)
digitalWrite(12,HIGH);
digitalWrite(10,HIGH);
}

else if(t == 'L'){ //turn right (left side motors rotate in forward direction, right side motors doesn't rotate)
digitalWrite(11,HIGH);
}

else if(t == 'R'){ //turn left (right side motors rotate in forward direction, left side motors doesn't rotate)
digitalWrite(13,HIGH);
}

else if(t == 'W'){ //turn led on or off)
digitalWrite(9,HIGH);
}
else if(t == 'w'){
digitalWrite(9,LOW);
}

else if(t == 'S'){ //STOP (all motors stop)
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
}
delay(100);
}
[/code]

Ron
 

djsfantasi

Joined Apr 11, 2010
6,837
FYI, if you open and close the Arduino IDE or if you unplug or re-plug in the USB cable, the USB port connecting the Arduino and the IDE will change.

Using the IDE drop down menus, make sure that the selected port is connected to the Arduino. The port label will tell you if it’s connected.

If it’s wrong, you won’t be able to upload anything. Makes sense... if you don’t configure the connection properly, it won’t work.
 

Thread Starter

Killerbee65

Joined May 15, 2017
243
OK, on your computer with the Arduino connected to your USB port let's see where the Arduino actually is. Open the Device Manager in Windows and look down and expand Ports (Com and LPT) . You should see your Arduino and which port it is using. Next in the Arduino IDE click Tools and from the drop down make sure the correct board shows up, as in Arduino/Genuino Uno and make sure Port reflects the correct port. Additionally make sure your port baud rate and Arduino baud rate are set the same. Looks like the IDE is not seeing your Arduino board. We need to tell the IDE where to look.

Next if looking at your code you plan to run motors in both directions FWD & REV your best bet would be your old motor board simply because it includes an H Bridge to reverse motor polarity. Also, when posting code it comes out better if you use code tags.
{code}
char t;

void setup() {
pinMode(13,OUTPUT); //left motors forward
pinMode(12,OUTPUT); //left motors reverse
pinMode(11,OUTPUT); //right motors forward
pinMode(10,OUTPUT); //right motors reverse
pinMode(9,OUTPUT); //Led
Serial.begin(9600);

}

void loop() {
if(Serial.available()){
t = Serial.read();
Serial.println(t);
}

if(t == 'F'){ //move forward(all motors rotate in forward direction)
digitalWrite(13,HIGH);
digitalWrite(11,HIGH);
}

else if(t == 'B'){ //move reverse (all motors rotate in reverse direction)
digitalWrite(12,HIGH);
digitalWrite(10,HIGH);
}

else if(t == 'L'){ //turn right (left side motors rotate in forward direction, right side motors doesn't rotate)
digitalWrite(11,HIGH);
}

else if(t == 'R'){ //turn left (right side motors rotate in forward direction, left side motors doesn't rotate)
digitalWrite(13,HIGH);
}

else if(t == 'W'){ //turn led on or off)
digitalWrite(9,HIGH);
}
else if(t == 'w'){
digitalWrite(9,LOW);
}

else if(t == 'S'){ //STOP (all motors stop)
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
}
delay(100);
}
[/code]

Ron
initially I tried it with my arduino mega but this happend and I switched it out for my uno and the same thing but when I switched it back it uploaded the sketch to the arduino.

Question about the serial monitor:

If I am right the serial monitor is a form of input communication from you to the arduino yes? if this is true are the "if" statements in the code "key words" I can use to perform the action? i tried to type in the serial monitor and it did nothing.
 

AlbertHall

Joined Jun 4, 2014
10,412
The communication works both ways. You can 'Serial.print("Hello World!") and assuming you set the arduino serial and the monitor to the same baud rate then what you print will appear in the monitor window.
Things you type in the box at the top of the window (and press the send button) will be sent to the arduino. Then you have 'Serial.available()' which will tell you if a byte has been received and 'Serial.read()' which will fetch the received byte.
You have to write the code that will get the arduino to do whatever you want when anything is received.
This will get you started: https://www.instructables.com/id/HOW-TO-use-the-ARDUINO-SERIAL-MONITOR/
 

Thread Starter

Killerbee65

Joined May 15, 2017
243
The communication works both ways. You can 'Serial.print("Hello World!") and assuming you set the arduino serial and the monitor to the same baud rate then what you print will appear in the monitor window.
Things you type in the box at the top of the window (and press the send button) will be sent to the arduino. Then you have 'Serial.available()' which will tell you if a byte has been received and 'Serial.read()' which will fetch the received byte.
You have to write the code that will get the arduino to do whatever you want when anything is received.
This will get you started: https://www.instructables.com/id/HOW-TO-use-the-ARDUINO-SERIAL-MONITOR/

Thank you for the link, as for the "if" statements?
 

Reloadron

Joined Jan 15, 2015
5,646
In addition to Albert's posted data this is another good write up.

Now as to the "if" statement. this covers it well and note how if works for a single or multiple conditions. That can get you.

The Arduino monitor works fine to send and receive serial data. I don't know if you recall earlier versions of Windows included "Hyper Terminal"which also works fine for sending to and receiving from Arduino. I am using an old version of Hyper Terminal and it runs fine on Windows 10. Another good serial communication piece of software is Tera Term which should come up with a simple Google and Tera Term works fine with any Arduino I tried it with. If you or anyone has any interest in Hyper Terminal just let me know. I have a link for it.

Ron
 

Thread Starter

Killerbee65

Joined May 15, 2017
243
In addition to Albert's posted data this is another good write up.

Now as to the "if" statement. this covers it well and note how if works for a single or multiple conditions. That can get you.

The Arduino monitor works fine to send and receive serial data. I don't know if you recall earlier versions of Windows included "Hyper Terminal"which also works fine for sending to and receiving from Arduino. I am using an old version of Hyper Terminal and it runs fine on Windows 10. Another good serial communication piece of software is Tera Term which should come up with a simple Google and Tera Term works fine with any Arduino I tried it with. If you or anyone has any interest in Hyper Terminal just let me know. I have a link for it.

Ron
OK gotcha! I am still running into the error I received earlier, sometimes it uploads other times it doesn't and when it does it won't print any of my code onto the serial monitor as if the code was never really uploaded. I tried the advice before and I did find the actual arduino in my device manager but still won't upload correctly.
 

Attachments

djsfantasi

Joined Apr 11, 2010
6,837
OK gotcha! I am still running into the error I received earlier, sometimes it uploads other times it doesn't and when it does it won't print any of my code onto the serial monitor as if the code was never really uploaded. I tried the advice before and I did find the actual arduino in my device manager but still won't upload correctly.
Are you checking the port before you upload the sketch, every time for now? You can use device manager, but the IDE works just as well and you don’t have to change to another program (device manager).

Go to the “Port” drop down menu. You’ll see the active ports and you should check the one with the name of the Arduino MCU you’re using.
 

Thread Starter

Killerbee65

Joined May 15, 2017
243
Are you checking the port before you upload the sketch, every time for now? You can use device manager, but the IDE works just as well and you don’t have to change to another program (device manager).

Go to the “Port” drop down menu. You’ll see the active ports and you should check the one with the name of the Arduino MCU you’re using.
I did and it displays two "COM3 (arduino Mega or Mega 2560)"
 

Reloadron

Joined Jan 15, 2015
5,646
Getting a little strange behavior there. Normally with the correct board set, the correct port set and the correct baud rate good code will upload. What I do sometimes when I fail to get an upload I use the Copy button down on the right and just click Copy so I copy all of the error message. Then I open Notepad and just paste it. Makes it easier to read. That assumes I don't have a glaring chunk of code hilighted in red glaring at me. Sometimes I forget to properly terminate a line or forget to declare something. I am not a programmer type, if I had to rely on my programming skills to survive I would be destitute and urinating in gutters, :)

Ron
 
Top