Ship model controlled using Arduino

Hello guys,

I'm new to this forum and to Arduino. A few years ago I did intern ship at a shipyard, and as I enjoyed my intern ship I decided to build a model of the ship I was working on. I always liked to make everything working that works on the real thing, and as the ship I'm referring to above has quite some working stuff fitted I'm able to go such far that normal radio control systems get to their limits, and then only through using decoders for which I would need to remember 16 functions per switch. As that would make it hard to use all functions to their full extent I decided that a different system was needed to do the job, especially seeing the fact that I like to go further with every new model. A friend of mine told me about Arduino, so I decided to try it out. At first it appeared to be easy, but as soon as I tried to get further then simply Hello World I got stuck with a not properly working set-up. Mostly I don't even get the codes to pass the test, let alone make more then just 1 LED go on and off. Therefore I decided to join this forum, hoping you guys could tell me how to start. The load of information is simply way too big to start finding out where to start myself.

The problem starts with my lack of knowledge of any kind of programming. I simply don't know how I can start programming, how the codes work. Therefore I can't find a way to get any further then the basic codes that Arduino provides in the software. My first question therefore is: is there a list of what code does what? Then: how can I get started with some proper programming, starting with turning on and off some LED's separately?

Right now I only have 1 Arduino Uno starter kit. I would prefer to use Wifi for communications between transmitter (laptop or tablet) and Arduino aboard the model. In order to keep the wiring as short as possible I intent to build several "board computers" as I like to call them, each having there own set of functions to control, or having a larger job to do, like handling all communications, controlling the propulsions to keep the model at her position under the name Dynamic positioning.

For those of you interested in the model I'll add a link to the build log here:http://www.shipmodels.info/mws_forum/viewtopic.php?f=13&t=45744

Thanks in advance.

Greetings Josse

Welcome to the forums. Have you looked at the Learning page http://arduino.cc/en/Tutorial/HomePage or the reference page http://arduino.cc/en/Reference/HomePage yet? The Reference page has lots of code examples on it.

I would start simple first and do 1 thing at a time. First make 1 led blink, then make 2 leds blink, then try adding a switch to turn them on and off.

Good luck!

Hello Pauly,

Thanks for the help. I thought I tried to find what I was looking for, but didn't find it then. I'm reading it now, and it seems to be helping already.

I just found out that I forgot to ask a question: would Wifi work for a range of up to 100m, and would it not be all too hard to set up a WiFi connection for controlling the Arduino? Or is the range of Wifi in open field (read water) too limited to be of any use? My current normal transmitter has a range of about 100m, and I haven't reached the limit of its range yet. Next question: would Wifi take more electric power then other wireless communications (such as blue tooth)? I want to be able to sail at least 6 hours with only the batteries of my laptop and the lead acid batteries of the model (the last one can be backed up by an additional battery). The battery of my laptop gives enough power to be on internet for some 4 hours, but that is not in power saving mode, so that endurance can probably be extended a bit. Would a tablet get a better performance for this matter?

Greetings Josse

Just a moment ago I managed to write my first properly working program!!! I started with the Blink program, and expanded that to make 2 LED's blink, though the second LED blinks shorter, and starts with off rather then on. Now that I've done this I can make the next step.

Can there be several void loops in 1 program?

What would be the next logical step? Could that be trying to control a servo? That is a function that I will be using quite a lot.

In the main mast of the ship are about 20 lights that are used to "tell" other vessels what condition the vessel is in (like "diver in the water", "limited manoeuvrability", etc.). I want to make the software on the transmitter such that I will just need to select the condition of the ship, and that the Arduino will know which of the 20 lights will need to be turned on (most conditions require several lights). Would I need to adjust the command code in the transmitter (transmitter knows which lights should be turned on, and Arduino gets the order to turn several lights on), or would it be better to tell the Arduino which lights should be turned on when a single code comes in (that single code would trigger several pins on the Arduino)?

Greetings Josse

would Wifi work for a range of up to 100m

Maybe, given that you'll have unobstructed line of sight to the model, but it's likely at the edge of its range. I would not risk it. XBee is an alternative, but make sure you get one of the models that has a one mile (or more) range - the lesser ones have much the same range as the wifi shield.

Hello Wildbill,

An unobstructed line of sight is highly likely, as I'm having her sail on the water, which is usually unobstructed. Can Xbee be attached to a laptop or tablet? That is what I want to use as transmitter. 100m of range is more then enough, a mile is overkill, when the model is at that range she'll be barely visible by then. The model isn't quite small (1,76m long), but most waters I sail in aren't even 100m long, so even if I want to get beyond that range I won't be able to do so due to lack of range. I can't imagine that a model or fellow model builder would limit the range noticeably, not when I bear in mind that there would most likely be a slightly longer way around that small obstruction. Would it help to have an antenna placed high in the model? There is a tower that gets as much as 55cm above the water, so would that make at least a slight difference in range when opposed to placing the antenna near the waterline?

Greetings Josse

You could set up your code to have to do certain code sequence defined. For example, your main loop would just look for a character to come in, then perform the code for that character.

void loop(){
if (Serial.available()>0){  // character is in the queue
commandCode = Serial.read();  // go get it
}
switch(commandCode){  // now do the code
case 'a':
// do the code for 'a'
commandCode = 0;  // clear the command if you only want it to run 1 time
// or leave it equal to 'a' if you want this section of code to run again without another character being received
break;
case 'b':
// do the code for 'b'
commandCode = 0;  // clear the command if you only want it to run 1 time
// or leave it equal to 'b' if you want this section of code to run again without another character being received

break;
:
:
case 'z':
// do the code for 'z'
commandCode = 0;  // clear the command if you only want it to run 1 time
// or leave it equal to 'z' if you want this section of code to run again without another character being received

break;
case 0:
// do nothing
break;
} // end switch
} // void loop

I've had trouble with the range of a wifi shield on a previous project where the separation was markedly less than 100m, although in that case the signal had to pass through several walls. However, since it sounds like you're sailing the model in enclosed waters, perhaps it doesn't matter - at worst you'll have to walk closer.

Could you post a picture of it?

Thanks for the help Crossroads.

@ Wildbill,

In my first post I included a link to the build log of the model, as this forum is only about electronics it doesn't seem to be appropriate to include pictures of models. The build log contains close to a thousand pictures at the moment, so I'd say that shows the project pretty well.

When the model happens to get out of range walking indeed will solve the problem. Most of the time walking is perfectly well possible, so that won't be a reason to use a different form of communication. If one can show me an easier way to communicate with the boat using a different form of communication I'd like to hear it. I do have experience with building websites, therefore it appeared to be relatively easy to make proper "software" for controlling the Arduino's aboard the vessel (the amount of functions, especially servo-driven functions, is simply to high for just 1 Arduino). My first thought is to go with 4 Arduino Mega's, 2 Arduino Nano's (for handling the communications) and 4 port expanders with each 8 pins.

Greetings Josse

My first thought is to go with 4 Arduino Mega's, 2 Arduino Nano's (for handling the communications) and 4 port expanders with each 8 pins

That's a lot of arduinos! Clearly you need a Mega - 20 pins are gone just handling the lights in the mast unless you add additional hardware, but how many other things do you need to control? Having looked at pictures of your build I suspect that a single Mega to handle it and two certainly could.

These are the functions: -throttle -rudder -bow thruster -prepare to sail (turns on cooling water pump, navigation lights and some more functions) -Mooring (turns off prepare to sail) -both anchors dropping and retrieving and cleaning (6 functions in total) -interior lighting (randomly, will need a Mega to control just this) -deck lights (2 groups, each take 1 function) - 3 different cranes (first 1 5 functions, one of 4 functions and the last one takes 3 functions) -4 lifeboats (each 2 functions, throttle and rudder) -1 hyperbaric lifeboat, also taking 2 functions -possibly 1 RHIB, also taking 2 functions -2 ROV's, each taking 10 functions (throttle, rudder, depth, arm to the left, arm to the right, up and down, videocamera, searchlight and lowering the hoist cable, or heaving it). -1 helicopter -firemonitors (taking 6 functions in total for independent control) -fire fighting equipment on the helideck -lights on the helideck -20 lights in the mast -2 searchlights on the bridge wings (each taking 3 functions to make sure I can keep them away from pointing in some-one's eyes as they're pretty bright). -Another searchlight on the bow, also taking 3 functions for the same reason -3 Panama steering lights, each taking 1 function -Dynamic Positioning, which can control each thruster unit independently

I thought that was pretty much it, totalling the number of functions to about 120, so yeah, I'll need several Arduino's. Then there will be more then just a few inputs: -positions of all the smaller craft (at least lifeboats, hyperbaric lifeboat, RHIB and helicopter, the ROV's camera will do the job of navigating, and when I'm using does I'll have the ship either at anchor or in DP-mode. -throttle and heading of all thruster units -light-meter for telling the interior lights to go on more often, and to turn on more lights -2 gyroscopes to tell the DP if the ship is moving, the second 1 will be back-up for added accuracy. -1 camera inside the main crane, 1 in each ROV, maybe also 1 on the bridge. -position of the crane, as there are some objects that are within it's reach, and I don't want it to hit any of those objects, even if it would be by accident.

This is pretty ambitious, but I know it can be done, so I will at least try, but actually I'm pretty much determined to make it happen, even if it means I'll be working on this model for quite some years. Actually, before I started building this model I had another ship in mind to build a model of, but my intern ship made me change my mind. The model I had in mind then is still to be the successor to this model. I have a bit of a tradition that every next model should be build better, and should also have more, or at least more complex, functionality. As soon as I figured out how to do this I will be able to improve the system for use in the next model. After that it's again a matter of small adjustments to make the next model working.

Greetings Josse

Wow, that is a lot to control. I withdraw my earlier remark :wink:

Going to be quite a coding effort.

Hi Wildbill,

It indeed will be quite some job to make all the codes :blush:
Fortunately I’ll be able to build it up step by step, that gives the opportunity to use parts of the system even when it isn’t completely finished.
I guys using comments will be quite useful here, one might easily get lost in such a huge amount of codes :grin:

Greetings Josse

I would guess a lot of those functions will need more thatn 5V/23-30mA to make them happen.
I’m doing (have done) a circuit card for another user with 12 TPIC6B595 shift registers to provide 96 outputs.
I think you would need something similar to provide higher curent/voltage control than straight-up Arduino’s could provide.
That would allow you to reduce the # of arduino’s and cut down on arduino-arduino comm’s, with maybe just a mega and its 4 comm ports for comms, and a bank of drivers/shift register to complement the 50+ IO lines the Mega has.

Hi Crossroads,

Thanks for the advice.

One of the reasons I want to use at least 4 Arduino's is that I can then place each Arduino as close to it's functions as possible. Would that also be possible with the 12 TPIC6B595 shift registers? Otherwise I would need quite some connectors to get the functions in the superstructure attached to they're controller.

Greetings Josse

Well, you’re not talking critical high speed communications here, so running pairs of CAT5 type wire from the control board to each component might be all you need.
You do have a lot of things to control; how many things are actually happening at once, and how many happen as you push buttons on your wireless controller to make something happen in display mode?

Yes, you could have a couple of the boards, 1 fore & 1 aft, maybe 3, so you’d have lots of current/voltage control options.

Hi Crossroads,

Does that mean that board can be placed anywhere in the boat, no matter where the Adruino is placed? In that case it indeed could be a good option. The CAT 5 wire is what I had in mind to connect the Arduino to other Arduino's or boards. From the Arduino/ board to the engines, LED's and servos that actually power the functions does take up a little more wires then there are functions.

Greetings Josse

The board as designed is like an Arduino with all the shift registers on the same card, you can see where the power comes in the bottom left, also along the bottom are the '328 and its capacitors, crystal, LED & stuff. I'll get one built up with a few parts to make it more clear. Then yes, you could mount it where ever you'd like, with the RF connected to the FTDI connector to make the connections to the serial port.

You could have a main card receive serial commands, and pass those along to the second card, and on to a 3rd card if needed.

I’d guess a lot of the functions of the mother-ship could be done with one large arduino + extra port-expanders/shift-registers. Instead of having 96 long wires in the boat, should you go for a single board with 12 shift-registers, 12 separate smaller boards with single shift-registers is also a possibility. That way you would need 1 long cable to control all the registers and could place each board as close as possible to the function(s) they’re designed to handle.

You still may need a lot of micro controllers though, 4 lifeboats, 1 RHIB and 1 hyperbaric lifeboat, If you want to have full control to sail those as well, they each may need a controller + wireless solution.
The ROVs may… also be controllable by wire, as in real life. I wonder whether you’ll be able to find ~1:75 scale cable that reels in and out easily and also has a lot of individual wires though. That’s what you’ll need in case you should not use a separate micro controller inside the ROVs. Should you use a single cable instead of a towing cable plus slightly longer control-cable, it will need to be quite strong to survive a few voyages as well.

In terms of speed and computing power needed an arduino is more then capable to handle 99 out of 100 functions you want. Don’t expect one to take care of camera-signals though. Although not completely correct, computing power of an arduino is comparable to 20-25 year old PCs and video is beyond its grasp. You may there for want to send video signals to shore wireless and record/show 'm there. Although it won’t give you real-time pictures while standing ashore, pan & tilt will also be quite difficult, having an arduino control start/stop-recording-“buttons” on a camera with sd-card is also a possibility.

Hello Simpson,

Thanks for the advice.

I indeed want to have some sort cable connected to the ROV's. I think the ROV's are too small for a micro controller. I even don't yet know if it will be possible to make the grip arm working, it does require some very tiny motors or servos.

I do want live video footage, but if Arduino isn't going to bring me there I'll find a different way. I only need 1 stream of video footage, and it doesn't have to be HD ready or even full HD, VGA will do the job too.

What would be the advantage of using only 1 Arduino and a few port expanders and shift registers? Is that easier to set up and control? If not I'd rather save on wiring length, even if that would still be more expensive. Besides, having several Arduino's makes it easier to build the system up part by part rather then needing to get everything (or nearly everything) working at once.

Greetings Josse