SandroMesquitaeliezerne
Published © GPL3+

Boat with Arduino Nano 33 IoT on Arduino Cloud

Double helix boat, controlled by Arduino IoT Cloud with siren, patrol LED and laser cannon.

IntermediateFull instructions provided6,340
Boat with Arduino Nano 33 IoT on Arduino Cloud

Things used in this project

Hardware components

Arduino Nano 33 IoT
Arduino Nano 33 IoT
×1
DC Motor, Miniature
DC Motor, Miniature
×2
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×2
LED, Blue Green
LED, Blue Green
×1
5 mm LED: Red
5 mm LED: Red
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Buzzer
Buzzer
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Laser Diode, 655 nm
Laser Diode, 655 nm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Hot glue gun (generic)
Hot glue gun (generic)
Tape, Electrical
Tape, Electrical
Plier, Long Nose
Plier, Long Nose
Plier, Needle Nose
Plier, Needle Nose
Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Schematics

Circuito Boat

This is the assembly circuit, attention, you will only use the buttons if you are programming your boat for local control, by cable.

Code

Code to program your boat for offline control

Arduino
This code is the control base of the online code in the Arduino IoT cloud, however the control that this code does is by physical button the cloud receives an online instruction from the cloud dashboard.
/*
 * Design of a WiFi-controlled boat with the Arduino
 * Nano 33 IoT Board
 * Start: 23/11/2020
 * Finish: 28/11/2020
 * Release: 29/11/2020
 *    Servo Motor included
 * Developers:  Specialist Prof. Sandro Mesquita
 *              Mestre Eliezer Neto
 * Country: Brazil
 * State: Cear
 * City: Fortaleza
 */

#include <Servo.h>

Servo laser;

//Variables of pins
byte  INBRight = 2, INARight = 3 , INBLeft = 4 , INALeft = 5, 
      btFront = A1, btLeft = A0, btBack = A2, btRight = A3,
      blueLed = 6, redLed = 12;
//Button state variables
bool front, left, back, right, Status=0;
unsigned long Time;
int switchTime=0, toneVal;
float sinVal;

void setup() {
  laser.attach(9);
  
  Serial.begin(9600);
  for (byte x = 2; x < 13; x++) {
    pinMode(x, OUTPUT);           //Declares pins as output
  }

  pinMode(btFront, INPUT_PULLUP); //Declares the pin A1 as input pullup
  pinMode(btLeft, INPUT_PULLUP);  //Declares the pin A0 as input pullup
  pinMode(btBack, INPUT_PULLUP);  //Declares the pin A2 as input pullup
  pinMode(btRight, INPUT_PULLUP); //Declares the pin A3 as input pullup

  digitalWrite(redLed, Status);
  digitalWrite(blueLed, !Status);

  Time = millis();
}

void loop() {
  flashes(Status);
  siren();
  control();
  engine();
}

void control() {
  front = digitalRead(btFront);   //Read the button forwar
  left = digitalRead(btLeft);     //Read the button left
  back = digitalRead(btBack);     //Read the button back
  right = digitalRead(btRight);   //Read the button right
}

void engine() {
  if (!front) {
    //Clockwise right engine
    rotationSenseRight(0, 1);
    //Clockwise left engine
    rotationSenseLeft(0, 1);
  }

  else if (!left) {
    //Clockwise right engine
    rotationSenseRight(0, 1);
    //Counterclockwise left engine
    rotationSenseLeft(1, 0);
  }

  else if (!back) {
    //Counterclockwise left engine
    rotationSenseRight(1, 0);
    //Counterclockwise left engine
    rotationSenseLeft(1, 0);
  }

  else if (!right) {
    //Counterclockwise left engine
    rotationSenseRight(1, 0);
    //Clockwise right engine
    rotationSenseLeft(0, 1);
  }

  else {
    //Engine stopped
    rotationSenseRight(0, 0);
    //Engine stopped
    rotationSenseLeft(0, 0);
  }
}

void rotationSenseRight(bool INB, bool INA) {
  digitalWrite(INBRight, INB);
  digitalWrite(INARight, INA);
}

void rotationSenseLeft(bool INB, bool INA) {
  digitalWrite(INBLeft, INB);
  digitalWrite(INALeft, INA);
}

bool flashes(bool led) {
  switchTime = millis() - Time;
  if (switchTime > 1000) {
    led=!led;
    digitalWrite(redLed, led);
    digitalWrite(blueLed, !led);
    Time = millis();
    Status = led;
    return Status;
    if(led){
      servo.write(0);
    }
    else servo.write(180);
  } 
}

void siren(){
  for (int x=0;x<260;x++){
        //converts degrees to radians
        sinVal = (sin(x*(3.1412/180)));
        //now generates a frequency
        toneVal = 3500+(int(sinVal*200));
        //touches the value in the buzzer
        tone(11,toneVal);
        //2ms delay and generates new tone
        delay(2);
    }
}

Cloud IoT Arduino online code

This is the code to control the boat remotely by the Arduino IoT Clod

Credits

SandroMesquita

SandroMesquita

14 projects • 113 followers
Professor de robótica com Arduino e Raspberry, estudando e aplicando conhecimentos de I.A. usando a Linguagem Python como base.
eliezerne

eliezerne

0 projects • 1 follower

Comments