Skip to content

Kid-Friendly 60 cm Foam RC Boat

A tough foam boat that floats, steers with a rudder and runs from a hobby RC transmitter, with a gentle speed mode for kids.

Try it

Simulated time

Behavior simulation: shows what it should do. It does not run the code.

Try this: Push the throttle to full with Kid mode on and watch power creep up to 50%, then switch the transmitter off and see the motor stop after 1 second.

Controls

  • Throttle stick (back = reverse, forward = go)0 %
  • Steering stick (left / right)0 %
  • Battery charge90 %
  • Waves / wind10 %

What it does

Motor / propeller spin
Propeller spin
Rudder angle
Servo arm angle
Motor power
Boat speed
Boat heading
Rocking in the waves
Status light
What the boat is doing

What it does

A 60 cm closed-cell foam hull carries a sealed electronics box, a brushed motor driving a small guarded propeller, and a servo-driven rudder at the back. The hobby RC receiver sends stick signals to a small Arduino Nano, which limits top speed in Kid mode, starts the motor smoothly, stops it if the radio signal is lost, and slows the boat when the battery gets low so it can still come back to shore. Power comes from a NiMH battery pack, which is tougher and more forgiving than lithium cells in a child's hands. It is also unsinkable, because the foam floats even if water gets inside.

Try it above: Push the throttle to full with Kid mode on and watch power creep up to 50%, then switch the transmitter off and see the motor stop after 1 second.

Safety

  • The spinning propeller can cut fingers. It has a guard, but the boat must be switched off before anyone picks it up or reaches near the back.
  • Children near water can drown. An adult must always supervise, and nobody should wade or swim out to fetch the boat.
  • A short-circuited battery can get very hot. Only charge it with the supplied charger, under adult supervision.
  • Water inside the electronics box can stop the boat. Check the seal and dry the hull after every run.
  • Don't use it near swimmers, boats or fast-moving water

What’s inside

35 parts. We buy, make and put these together for you.

Brain

Runs the program and makes the decisions.

$117.47
  • Arduino Nano1×

    $25.70

    The boat's small brain: reads the radio, caps speed in Kid mode, stops on signal loss and watches the battery.

    • 18 × 45 × 8 mm
    • Firmware: arduino-cpp, pre-loaded
    • Runs on: 5 to 12 V
    • Draws: about 20 mA
    • Weight: 7 g
    list price, checked Oct 5, 2026 at a generic supplierView
  • FlySky FS-i6X 2.4 GHz transmitter + FS-iA6B receiver1 sets

    $59.99

    The hand controller the child holds, plus the receiver in the boat that picks up its stick signals.

    • 17 × 9.2 × 19 cm
    • Failsafe: set to no-pulse on loss
    • Mode switch: SwA set as Kid / Full switch on CH5
    • Runs on: 4 to 6.5 V
    • Draws: about 40 mA
    list price, checked Oct 5, 2026 at AmazonView
  • Brushed ESC for RC boats/cars, 320 A, 6-12 V1×

    $23.79

    Turns the board's speed signal into real motor power, forward and reverse, and powers the board and receiver.

    • 46 × 33 × 18 mm
    • Bec: 5 V for Nano + receiver
    • Battery type: set to NiMH
    • Runs on: 6 to 12.6 V
    • Draws: about 5000 mA

    Pack of 2, you use 1, the spare is yours.

    list price, checked Oct 5, 2026 at AmazonView
  • LM2596 adjustable buck converter (step-down), 3 A1×

    $7.99

    Gives the rudder servo its own steady power so it can't disturb the board.

    • 43 × 21 × 14 mm
    • Output: set to 5.5 V
    • Runs on: 4 to 40 V
    • Draws: about 1000 mA

    Pack of 5, you use 1, the 4 spares are yours.

    list price, checked Oct 5, 2026 at AmazonView

Controls

What you press, turn or flip.

$4.00
  • Waterproof toggle switch with rubber boot, 10 A1×

    $4.00

    Main on/off switch on the deck so the boat can be turned off before handling.

    • 14 × 14 × 22 mm
    • Rating: 10 A, IP65 boot
    estimate

Lights, sound and screen

How it tells you what it is doing.

$0.50
  • 5 mm LED, diffused red1×

    $0.50

    Shines through the lid to show the boat is on, and blinks when the battery is low.

    • 6 × 6 × 9 mm
    • Runs on: 1.85 to 2.5 V
    • Draws: about 15 mA
    list price, checked Oct 5, 2026 at SparkFunView

Motion

Everything that moves.

$76.42
  • 380-size brushed DC motor, 7.2 V1×

    $8.00

    Spins the propeller to push the boat along.

    • 38 × 38 × 38 mm
    • Size: 380 can, 2.3 mm shaft
    • Voltage: 7.2 V
    • Noise caps: 3 x 100 nF soldered on
    estimate
  • RC boat drive set: 130 mm shaft, sleeve, 36 mm propeller1 sets

    $9.79

    Carries the motor's spin through the hull to the propeller without letting water in.

    • 13 × 3.6 × 3.6 cm
    • Propeller: 36 mm, 3-blade
    • Weight: 50 g
    list price, checked Oct 6, 2026 at AmazonView
  • Flexible shaft coupler 2.3 mm to 4 mm1×

    $4.00

    Joins the motor's 2.3 mm shaft to the 4 mm propeller shaft; the drive set's own coupler only fits 4 mm motor shafts.

    • 18 × 12 × 12 mm
    • Bore: 2.3 x 4 mm
    estimate
  • Waterproof digital servo, 25 kg·cm1×

    $28.66

    Swings the rudder left and right to steer.

    • 40 × 20 × 41 mm
    • Travel: limited to ±35° in firmware
    • Runs on: 4.8 to 6.8 V
    • Draws: about 800 mA

    Pack of 2, you use 1, the spare is yours.

    list price, checked Oct 5, 2026 at AmazonView
  • RC boat rudder, 110 mm aluminum, with mount1×

    $20.97

    The fin at the back that turns the boat when the servo moves it.

    • 3 × 4.5 × 11 cm
    • Weight: 90 g
    list price, checked Oct 5, 2026 at AmazonView
  • Rudder pushrod with ball links, 100 mm1 sets

    $5.00

    Connects the servo arm to the rudder arm.

    • 77 × 2 × 2 mm
    • Rod: M2 stainless, 100 mm
    estimate

Power

Where its energy comes from.

$23.00
  • NiMH battery pack 7.2 V 2000 mAh with XT601×

    $20.00

    Stores the energy that runs the boat; NiMH is safer than lithium for kids.

    • 70 × 45 × 30 mm
    • Cells: 6 x AA-size NiMH
    • Connector: XT60
    • Voltage range: 6.0-8.4 V
    estimate
  • Inline blade fuse holder with 10 A fuse1×

    $3.00

    Cuts the power if a wire ever shorts, so the battery cannot overheat.

    • 16 × 28 × 10 mm
    • Rating: 10 A
    estimate

Small electronics and wiring

Resistors, connectors and cables that join it all up.

$39.34
  • Resistor 10 kΩ, 1/4 W, 5 %1×

    $0.75

    Two of these scale the battery voltage down so the board can check how full it is.

    • 6 × 3 × 3 mm
    • Value: 10 kOhm, 2 used
    • Runs on: 0 to 300 V

    Pack of 25, you use 1, the 24 spares are yours.

    list price, checked Oct 5, 2026 at AdafruitView
  • Ceramic capacitor 0.1 µF (104), 50 V1×

    $1.95

    Quiet electrical noise from the motor and smooth the battery reading.

    • 4 × 3 × 4 mm
    • Value: 100 nF
    • Runs on: 0 to 50 V
    • Weight: 0.15 g

    Pack of 10, you use 1, the 9 spares are yours.

    list price, checked Oct 5, 2026 at AdafruitView
  • Resistor 220 Ω, 1/4 W, 5 %1×

    $0.75

    Limits the current so the status light doesn't burn out.

    • 6 × 3 × 3 mm
    • Value: 220 ohm
    • Runs on: 0 to 300 V

    Pack of 25, you use 1, the 24 spares are yours.

    list price, checked Oct 5, 2026 at AdafruitView
  • Perma-Proto half-size solderable breadboard PCB1×

    $4.50

    The board everything is fixed to, so there are no loose wires.

    • 81 × 51 × 2 mm
    • Weight: 12 g
    list price, checked Oct 5, 2026 at AdafruitView
  • Silicone wire 14 AWG, red + black1 m

    $1.50

    Thick flexible wire for the battery and motor power.

    • 1 × 0 × 0 m
    list price, checked Oct 5, 2026 at a generic supplierView
  • Hook-up wire 22 AWG solid core, 6 x 25 ft1 sets

    $15.95

    Thin wire for signals between receiver, board, ESC and servo.

    • 25 × 5.1 × 5.1 cm
    • Weight: 340.7 g
    list price, checked Oct 5, 2026 at AdafruitView
  • XT60 connector pairs1 packs

    $8.99

    Safe, keyed plug so the battery only connects the right way.

    • 16 × 20 × 8 mm
    list price, checked Oct 5, 2026 at a generic supplierView
  • Heat-shrink tubing assortment1 packs

    $4.95

    Covers every wire joint so nothing can short.

    • 15 × 0.5 × 0.5 cm
    list price, checked Oct 5, 2026 at AdafruitView

Body and structure

The case, frame and panels.

$124.46
  • IP67 waterproof box, 150 x 100 x 60 mm, clear lid1×

    $12.00

    Keeps the electronics and battery dry inside the hull.

    • 15 × 10 × 6.4 cm
    • Rating: IP67 with gasket
    • Size: 150 x 100 x 60
    estimate
  • Closed-cell polyethylene foam plank, 25 mm (610 x 2290 mm)1 sheets

    $39.85

    Cut and stacked into the 600 mm hull, which floats even if water gets in.

    • 0.6 × 2.3 × 0 m
    • Material: closed-cell polyethylene
    • Hull size: 600 x 200 x 100, 4 layers
    • Weight: 2268 g
    list price, checked Oct 5, 2026 at AmazonView
  • HDPE sheet, 6 mm (305 x 610 mm)1 sheets

    $26.99

    Stiff plates that hold the motor, rudder and box firmly in the soft foam.

    • 30 × 61 × 0.6 cm
    • Material: 6 mm HDPE
    • Weight: 1121 g
    list price, checked Oct 5, 2026 at AmazonView
  • PE foam contact adhesive (polyolefin-safe)1×

    $12.00

    Bonds the foam layers and HDPE plates into one solid hull.

    • Type: polyolefin contact cement, 250 ml
    estimate
  • 3M 5200 marine adhesive sealant1×

    $19.98

    Seals the stuffing tube and rudder mount so they stay watertight.

    • 13 × 5.1 × 23 cm
    • Weight: 140 g
    list price, checked Oct 5, 2026 at AmazonView
  • PETG filament 1.75 mm0.2 kg

    $13.64

    Printed motor mount, propeller guard, servo bracket and switch plate.

    • 20 × 20 × 6.5 cm
    • Parts: motor mount, prop guard, servo bracket, switch plate
    • Weight: 1000 g
    list price, checked Oct 5, 2026 at AmazonView

Fixings

Screws, bolts and ties that hold it together.

$35.81
  • Cable gland PG7, waterproof3×

    $3.00

    Seal where the motor, servo and switch wires leave the box.

    • 10 × 62 × 12 mm
    • Size: PG7, 3-6.5 mm cable
    estimate
  • Brass heat-set insert, M3 x 4 mm12×

    $5.95

    Strong metal threads inside the printed parts for the screws.

    • 4 × 4 × 4 mm

    Pack of 50, you use 12, the 38 spares are yours.

    list price, checked Oct 5, 2026 at AdafruitView
  • M3 socket head screw (6-30 mm)20×

    $9.99

    Hold the motor mount, guard, servo and board in place.

    • 6 × 6 × 13 mm
    • Material: stainless

    Pack of 1120, you use 20, the 1100 spares are yours.

    list price, checked Oct 5, 2026 at AmazonView
  • VELCRO Brand Extreme Outdoor strips, 4 x 2 in2×

    $4.98

    Holds the battery firmly in the box but lets it come out for charging.

    • 10 × 5.1 × 0.4 cm

    Pack of 3, you use 2, the spare is yours.

    list price, checked Oct 5, 2026 at AmazonView
  • Cable ties, 8" UV-resistant black10×

    $7.89

    Keep the wires tidy and away from the propeller shaft.

    • 0.5 × 0.1 × 20 cm
    • Weight: 1.13 g

    Pack of 100, you use 10, the 90 spares are yours.

    list price, checked Oct 5, 2026 at AmazonView
  • Rubber hatch straps with hooks2×

    $4.00

    Hold the electronics box down in its hull pocket.

    • 10 × 11 × 6.8 cm
    • Length: 250 mm
    estimate

Other

$3.00
  • Waterproof vinyl label set1 sets

    $3.00

    Clear labels: on/off switch, 'keep fingers away from propeller', and charging instructions.

    • 60 × 30 × 1 mm
    Made by usestimate

Parts total (35 lines)

$424

$346 from supplier list prices, $78.00 estimated. Preparation and shipping are added when you order.

How it goes together

The step-by-step instructions that come with your order, 3 steps. Try them here first.

Before you start

Kid-Friendly 60 cm Foam RC Boat goes together in 3 steps, about 20 min in all. No soldering and no coding.

Already done in our workshop

  • Cut and glue the foam hull
  • Print the motor mount, servo bracket, propeller guard and switch plate
  • Fit the drive, motor and rudder
  • Build the control board
  • Wire and seal the electronics box
  • Program and bench test
  • Water tank test and pack

Have these ready

  • Smart NiMH charger

3 steps

Code

The code it runs1 file, 350 lines. We load it onto the board for you.

Uses: Servo

BoatController/BoatController.ino
/*  ===================================================================  TINKERLY - Kid-safe RC foam boat : main controller program  Board: Arduino Nano (ATmega328P)  ===================================================================   WHAT THIS PROGRAM DOES (in plain words)  ---------------------------------------  The hobby radio receiver sends three "stick signals" to the Nano:    - Steering stick (receiver CH1)  -> Nano pin D9    - Throttle stick (receiver CH2)  -> Nano pin D3    - Kid / Full switch (CH5)        -> Nano pin D10   The Nano then:    1. Drives the motor (through the waterproof ESC on pin D5).       Stick forward = forward. Stick back = slower reverse (half).    2. Swings the rudder servo (pin D6) up to about 35 degrees each way.    3. Kid mode: top speed limited to 50 % and the motor speeds up       gently (about 40 % per second), so there is never a jerk.       Full mode: 100 % and a quicker (but still smooth) speed-up.    4. Safety lock at power-on: the motor will NOT run until the       throttle stick has been put back to the middle (zero).    5. Signal lost for more than 1 second: motor stops, rudder centres.    6. Battery low: power is limited to 30 % so the boat can still       limp back to shore, and the status light blinks.   STATUS LIGHT (red LED on pin D4)  --------------------------------    Solid ON            = all good, ready to drive    Fast blink (4x/s)   = waiting: put throttle stick to zero to start    Medium blink (2x/s) = LOW BATTERY: 30 % power, head to shore    Slow blink (1s/1s)  = NO SIGNAL: motor stopped, rudder centred   WORKSHOP NOTES  --------------  - Battery sensing: pin A6 reads the battery through a 10k / 10k    divider (10k from switched battery + to A6, 10k from A6 to GND),    so A6 sees half the battery voltage.  - Receiver failsafe: on the FS-i6X set failsafe so the receiver stops    sending pulses (or set CH2 to centre). This program ALSO detects    loss by itself if no fresh pulses arrive for 1 second.  - Kid mode switch: CH5 assigned to switch SwA. Switch UP (short pulse)    = Kid mode. Switch DOWN (long pulse) = Full speed. If CH5 is not    received at all, the boat stays in Kid mode (the safe choice).  - Only the standard Arduino "Servo" library is used.  - Serial monitor at 115200 baud prints a status line twice a second.  ===================================================================*/ #include <Arduino.h>#include <Servo.h> // ------------------------- Pin assignments -------------------------const uint8_t PIN_THROTTLE_IN = 3;   // receiver CH2 (external interrupt INT1)const uint8_t PIN_STEER_IN    = 9;   // receiver CH1 (pin-change interrupt)const uint8_t PIN_MODE_IN     = 10;  // receiver CH5 (pin-change interrupt)const uint8_t PIN_ESC_OUT     = 5;   // ESC signal wireconst uint8_t PIN_SERVO_OUT   = 6;   // rudder servo signal wireconst uint8_t PIN_LED         = 4;   // red status lightconst uint8_t PIN_BATTERY     = A6;  // battery voltage (through divider) // ------------------------- Tuning values ---------------------------const unsigned long SIGNAL_TIMEOUT_MS = 1000; // radio lost after 1 sconst int   PULSE_MIN_VALID   = 800;    // anything outside is ignoredconst int   PULSE_MAX_VALID   = 2200;const int   PULSE_CENTRE      = 1500;   // stick in the middleconst int   PULSE_SPAN        = 500;    // 1000..2000 us = -100..+100 %const float STICK_DEADBAND    = 5.0;    // % : counts as "zero" const float LIMIT_FULL        = 100.0;  // % top power, full modeconst float LIMIT_KID         = 50.0;   // % top power, kid modeconst float LIMIT_LOWBATT     = 30.0;   // % top power, low batteryconst float REVERSE_FACTOR    = 0.5;    // reverse is half as strongconst float RAMP_KID          = 40.0;   // % per second speed change, kidconst float RAMP_FULL         = 150.0;  // % per second speed change, full const float RUDDER_MAX_DEG    = 35.0;   // rudder swing each wayconst float SERVO_US_PER_DEG  = 11.1;   // ~500 us for 45 degreesconst int   SERVO_TRIM_US     = 0;      // workshop trim: centre rudderconst bool  SERVO_REVERSED    = false;  // flip if rudder moves wrong wayconst bool  ESC_REVERSED      = false;  // flip if boat goes backwards // Battery: 6-cell NiMH. Roughly 8.0 V full, 6.4 V empty.const float ADC_REF_VOLTS     = 5.0;    // Nano runs on 5 V from ESC BECconst float DIVIDER_RATIO     = 2.0;    // 10k / 10k dividerconst float BATT_FULL_V       = 8.0;const float BATT_EMPTY_V      = 6.4;const float BATT_LOW_PERCENT  = 20.0;   // below this = low batteryconst unsigned long LOWBATT_CONFIRM_MS = 3000; // must stay low 3 s const unsigned long CONTROL_PERIOD_MS = 20;  // 50 updates per secondconst unsigned long BATTERY_PERIOD_MS = 100;const unsigned long REPORT_PERIOD_MS  = 500; // ------------------------- Radio pulse capture ---------------------// The receiver sends a 1000-2000 microsecond pulse ~50 times a second// on each channel. Interrupts time each pulse in the background so the// main loop never has to wait.enum { CH_STEER = 0, CH_THROTTLE = 1, CH_MODE = 2, CH_COUNT = 3 }; volatile unsigned long riseTime[CH_COUNT]  = {0, 0, 0};volatile uint16_t      pulseWidth[CH_COUNT] = {1500, 1500, 1000};volatile unsigned long lastGood[CH_COUNT]  = {0, 0, 0};  // millis()volatile bool          everSeen[CH_COUNT]  = {false, false, false};volatile uint8_t       lastPortB = 0; // Store one finished pulse if it looks like a real stick signalstatic inline void storePulse(uint8_t ch, unsigned long now) {  unsigned long w = now - riseTime[ch];  if (w >= (unsigned long)PULSE_MIN_VALID && w <= (unsigned long)PULSE_MAX_VALID) {    pulseWidth[ch] = (uint16_t)w;    lastGood[ch]   = millis();    everSeen[ch]   = true;  }} // Throttle on D3 (external interrupt)void throttleISR() {  unsigned long now = micros();  if (PIND & _BV(PD3)) riseTime[CH_THROTTLE] = now;  else                 storePulse(CH_THROTTLE, now);} // Steering on D9 (PB1) and mode switch on D10 (PB2): pin-change interruptISR(PCINT0_vect) {  unsigned long now = micros();  uint8_t pins    = PINB;  uint8_t changed = pins ^ lastPortB;  lastPortB = pins;   if (changed & _BV(PB1)) {    if (pins & _BV(PB1)) riseTime[CH_STEER] = now;    else                 storePulse(CH_STEER, now);  }  if (changed & _BV(PB2)) {    if (pins & _BV(PB2)) riseTime[CH_MODE] = now;    else                 storePulse(CH_MODE, now);  }} // Safely copy one channel's latest values out of the interrupt areavoid readChannel(uint8_t ch, uint16_t &width, unsigned long &lastMs, bool &seen) {  noInterrupts();  width  = pulseWidth[ch];  lastMs = lastGood[ch];  seen   = everSeen[ch];  interrupts();} // ------------------------- Outputs ---------------------------------Servo esc;Servo rudder; // ------------------------- Program state ---------------------------bool  armed        = false;  // safety lock released?float motorCmd     = 0.0;    // current motor power, -100..+100 %bool  signalOk     = false;bool  kidMode      = true;bool  lowBattery   = false;  // stays on once set, until power-offfloat batteryVolts = 0.0;float batteryPct   = 100.0;float steerPct     = 0.0;float throttlePct  = 0.0;bool  batteryFilterStarted = false;unsigned long lowSinceMs = 0; unsigned long lastControlMs = 0;unsigned long lastBatteryMs = 0;unsigned long lastReportMs  = 0; // ------------------------- Helpers ---------------------------------// Turn a pulse width into a stick position from -100 to +100 %float pulseToPercent(uint16_t us) {  float p = ((float)us - PULSE_CENTRE) * 100.0 / PULSE_SPAN;  if (p > 100.0)  p = 100.0;  if (p < -100.0) p = -100.0;  if (fabs(p) < STICK_DEADBAND) p = 0.0;  // ignore tiny stick wobble  return p;} float clampf(float v, float lo, float hi) {  if (v < lo) return lo;  if (v > hi) return hi;  return v;} // Send power (-100..+100 %) to the ESC as a servo-style pulsevoid writeMotor(float pct) {  if (ESC_REVERSED) pct = -pct;  int us = PULSE_CENTRE + (int)(pct * PULSE_SPAN / 100.0);  esc.writeMicroseconds(constrain(us, 1000, 2000));} // Point the rudder (degrees, + = right)void writeRudder(float deg) {  deg = clampf(deg, -RUDDER_MAX_DEG, RUDDER_MAX_DEG);  if (SERVO_REVERSED) deg = -deg;  int us = PULSE_CENTRE + SERVO_TRIM_US + (int)(deg * SERVO_US_PER_DEG);  rudder.writeMicroseconds(constrain(us, 1000, 2000));} // ------------------------- Battery check ---------------------------void updateBattery(unsigned long now) {  int raw = analogRead(PIN_BATTERY);  float v = raw * ADC_REF_VOLTS / 1023.0 * DIVIDER_RATIO;   // Smooth the reading, because the motor makes the voltage jump about  if (!batteryFilterStarted) { batteryVolts = v; batteryFilterStarted = true; }  else batteryVolts += (v - batteryVolts) * 0.05;   batteryPct = clampf((batteryVolts - BATT_EMPTY_V) * 100.0 /                      (BATT_FULL_V - BATT_EMPTY_V), 0.0, 100.0);   // Only call it "low" if it stays low for a few seconds, then keep it  // low until the boat is switched off (no confusing on/off flicker).  if (batteryPct < BATT_LOW_PERCENT) {    if (lowSinceMs == 0) lowSinceMs = now;    if (now - lowSinceMs >= LOWBATT_CONFIRM_MS) lowBattery = true;  } else {    lowSinceMs = 0;  }} // ------------------------- Main control step -----------------------void controlStep(unsigned long now, float dt) {  uint16_t wSteer, wThr, wMode;  unsigned long tSteer, tThr, tMode;  bool sSteer, sThr, sMode;  readChannel(CH_STEER,    wSteer, tSteer, sSteer);  readChannel(CH_THROTTLE, wThr,   tThr,   sThr);  readChannel(CH_MODE,     wMode,  tMode,  sMode);   // 1) Is the radio still talking to us? (both main sticks fresh)  signalOk = sSteer && sThr &&             (now - tSteer <= SIGNAL_TIMEOUT_MS) &&             (now - tThr   <= SIGNAL_TIMEOUT_MS);   // 2) Kid or Full mode. No CH5 signal = stay in Kid mode (safe).  bool modeFresh = sMode && (now - tMode <= SIGNAL_TIMEOUT_MS);  kidMode = !modeFresh || (wMode < PULSE_CENTRE);   steerPct    = signalOk ? pulseToPercent(wSteer) : 0.0;  throttlePct = signalOk ? pulseToPercent(wThr)   : 0.0;   // 3) Safety lock: unlock only once the throttle stick is at zero  if (!armed && signalOk && fabs(throttlePct) < STICK_DEADBAND) {    armed = true;  }   // 4) Motor power  if (!armed || !signalOk) {    motorCmd = 0.0;                         // stop straight away  } else {    // Wanted power: reverse is weaker than forward    float target = (throttlePct >= 0) ? throttlePct : throttlePct * REVERSE_FACTOR;     // Speed limit: low battery beats everything, then Kid mode    float limit = lowBattery ? LIMIT_LOWBATT : (kidMode ? LIMIT_KID : LIMIT_FULL);    target = clampf(target, -limit, limit);     // Gentle change: only move a little toward the target each step    float rate = kidMode ? RAMP_KID : RAMP_FULL;    float maxStep = rate * dt;    motorCmd += clampf(target - motorCmd, -maxStep, maxStep);  }  writeMotor(motorCmd);   // 5) Rudder: up to 35 degrees each way, centred if signal is lost  float rudderDeg = signalOk ? steerPct * (RUDDER_MAX_DEG / 100.0) : 0.0;  writeRudder(rudderDeg);} // ------------------------- Status light ----------------------------void updateLed(unsigned long now) {  bool on;  if (!signalOk)       on = (now % 2000) < 1000;  // slow blink: no signal  else if (!armed)     on = (now % 250)  < 125;   // fast blink: zero throttle  else if (lowBattery) on = (now % 500)  < 250;   // medium blink: low battery  else                 on = true;                 // solid: all good  digitalWrite(PIN_LED, on ? HIGH : LOW);} // ------------------------- Serial report (workshop testing) --------void report() {  if (!signalOk)       Serial.print(F("NO SIGNAL: motor stopped, rudder centred"));  else if (!armed)     Serial.print(F("Waiting: put throttle to zero to start"));  else if (lowBattery) Serial.print(F("LOW BATTERY: 30% power, head to shore"));  else if (kidMode)    Serial.print(F("Kid mode: max 50%, gentle start"));  else                 Serial.print(F("Full speed mode"));  Serial.print(F(" | Power: "));   Serial.print((int)round(motorCmd));  Serial.print(F("%  Battery: ")); Serial.print((int)round(batteryPct));  Serial.print(F("% ("));          Serial.print(batteryVolts, 2);  Serial.print(F(" V)  Steer: ")); Serial.print((int)steerPct);  Serial.print(F("%  Throttle: "));Serial.print((int)throttlePct);  Serial.println(F("%"));} // ------------------------- Setup -----------------------------------void setup() {  // Outputs first: tell the ESC "neutral" right away so it arms safely  esc.attach(PIN_ESC_OUT, 1000, 2000);  writeMotor(0);  rudder.attach(PIN_SERVO_OUT, 1000, 2000);  writeRudder(0);   pinMode(PIN_LED, OUTPUT);  digitalWrite(PIN_LED, LOW);   // Radio inputs  pinMode(PIN_THROTTLE_IN, INPUT);  pinMode(PIN_STEER_IN, INPUT);  pinMode(PIN_MODE_IN, INPUT);   attachInterrupt(digitalPinToInterrupt(PIN_THROTTLE_IN), throttleISR, CHANGE);   lastPortB = PINB;  PCMSK0 |= _BV(PCINT1) | _BV(PCINT2);  // watch D9 and D10  PCICR  |= _BV(PCIE0);                 // enable port-B pin-change interrupt   analogReference(DEFAULT);  Serial.begin(115200);  Serial.println(F("Tinkerly RC boat controller starting"));   lastControlMs = lastBatteryMs = lastReportMs = millis();} // ------------------------- Main loop (never waits) -----------------void loop() {  unsigned long now = millis();   if (now - lastBatteryMs >= BATTERY_PERIOD_MS) {    lastBatteryMs = now;    updateBattery(now);  }   if (now - lastControlMs >= CONTROL_PERIOD_MS) {    float dt = (now - lastControlMs) / 1000.0;    if (dt > 0.1) dt = 0.1;  // never jump more than a small step    lastControlMs = now;    controlStep(now, dt);  }   updateLed(now);   if (now - lastReportMs >= REPORT_PERIOD_MS) {    lastReportMs = now;    report();  }} 

Comments

No comments yet

Ask the maker a question, or say what you would change. Comments are public.

Sign in to comment. It is free.

More in outdoors & water

See all in Outdoors & water