Arduino LED Strip + Ultrasonic Sensor

[circuito]

[obstacle course]

// Include Libraries
#include "Arduino.h"
#include "NewPing.h"
#include "RGBLed.h"


// Pin Definitions - RGB Strip
#define LEDSTRIPRGB_PIN_SIGR  9
#define LEDSTRIPRGB_PIN_SIGG  6
#define LEDSTRIPRGB_PIN_SIGB  5


// Pin Definitions - Ultrasonic Sensor
#define HCSR04_PIN_TRIG  3
#define HCSR04_PIN_ECHO 2



// Global variables and defines - RGB Strip
#define LedStripRGB_TYPE COMMON_CATHODE
// object initialization
RGBLed LedStripRGB(LEDSTRIPRGB_PIN_SIGR,LEDSTRIPRGB_PIN_SIGG,LEDSTRIPRGB_PIN_SIGB,LedStripRGB_TYPE);


// Global variables and defines - Ultrasonic sensor
NewPing hcsr04(HCSR04_PIN_TRIG,HCSR04_PIN_ECHO);


long timeout = 0;       //define timeout used to switch RGB strip ON and OFF
int colors = -1; // cycle colors


// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup() 
{
    // Setup Serial which is useful for debugging
    // Use the Serial Monitor to view printed messages
    Serial.begin(9600);
    Serial.println("start");
}

// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop() 
{
    int hcsr04Dist = hcsr04.ping_cm();
    //delay(10);

    if (hcsr04Dist == 0)
    {
      //ignore
    }
    else if (hcsr04Dist < 40)
    {
      //Serial.print(F("Distance: ")); Serial.print(hcsr04Dist); Serial.println(F("[cm]"));
      if (timeout == 0)
      {
        //Serial.println("ON:");
        // 1. sets LED Strip RGB color to purple. Change the values in the brackets to (255,0,0) for pure RED, (0,255,0) for pure GREEN and (0,0,255) for pure BLUE.
        colors = (colors + 1) % 3;
        switch (colors)
        {
          case 0:
            LedStripRGB.setRGB(255, 0, 0);
            //Serial.println("RED");
            break;
          case 1:
            LedStripRGB.setRGB(0, 255, 0);
            //Serial.println("GREEN");
            break;
          case 2:
            LedStripRGB.setRGB(0, 0, 255);
            //Serial.println("BLUE");
            break;
        }
      }
      timeout = millis() + 750;
    }
    
    if (timeout > 0 &&
      millis() > timeout)
    {
      //Serial.println("OFF:");
      timeout = 0;
      LedStripRGB.turnOff();        // 3. turns LED Strip RGB off (showing no color). Change the values in the brackets to alter the color.
    }
}

/*******************************************************

*    Circuito.io is an automatic generator of schematics and code for off
*    the shelf hardware combinations.

*    Copyright (C) 2016 Roboplan Technologies Ltd.

*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.

*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.

*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see .

*    In addition, and without limitation, to the disclaimers of warranties 
*    stated above and in the GNU General Public License version 3 (or any 
*    later version), Roboplan Technologies Ltd. ("Roboplan") offers this 
*    program subject to the following warranty disclaimers and by using 
*    this program you acknowledge and agree to the following:
*    THIS PROGRAM IS PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS, AND 
*    WITHOUT WARRANTIES OF ANY KIND EITHER EXPRESS OR IMPLIED.  ROBOPLAN 
*    HEREBY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT 
*    NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY, TITLE, FITNESS 
*    FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND THOSE ARISING BY 
*    STATUTE OR FROM A COURSE OF DEALING OR USAGE OF TRADE. 
*    YOUR RELIANCE ON, OR USE OF THIS PROGRAM IS AT YOUR SOLE RISK.
*    ROBOPLAN DOES NOT GUARANTEE THAT THE PROGRAM WILL BE FREE OF, OR NOT 
*    SUSCEPTIBLE TO, BUGS, SECURITY BREACHES, OR VIRUSES. ROBOPLAN DOES 
*    NOT WARRANT THAT YOUR USE OF THE PROGRAM, INCLUDING PURSUANT TO 
*    SCHEMATICS, INSTRUCTIONS OR RECOMMENDATIONS OF ROBOPLAN, WILL BE SAFE 
*    FOR PERSONAL USE OR FOR PRODUCTION OR COMMERCIAL USE, WILL NOT 
*    VIOLATE ANY THIRD PARTY RIGHTS, WILL PROVIDE THE INTENDED OR DESIRED
*    RESULTS, OR OPERATE AS YOU INTENDED OR AS MAY BE INDICATED BY ROBOPLAN. 
*    YOU HEREBY WAIVE, AGREE NOT TO ASSERT AGAINST, AND RELEASE ROBOPLAN, 
*    ITS LICENSORS AND AFFILIATES FROM, ANY CLAIMS IN CONNECTION WITH ANY OF 
*    THE ABOVE. 
********************************************************/

Drone ultrasonic detector

[circuito]

[Drone Obstacle Course]


// Include Libraries
#include "Arduino.h"
#include "NewPing.h"
#include "LED.h"
#include "Switchable.h"


// Pin Definitions
#define HCSR04_PIN_TRIG	3
#define HCSR04_PIN_ECHO	2
#define LEDB_PIN_VIN	4
#define LEDB_PIN_VIN2  5
#define LEDB_PIN_VIN3  16



// Global variables and defines

// object initialization
NewPing hcsr04(HCSR04_PIN_TRIG,HCSR04_PIN_ECHO);



long timeout = 0;       //define timeout of 10 sec

// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup() 
{
    // Setup Serial which is useful for debugging
    // Use the Serial Monitor to view printed messages
    Serial.begin(9600);
    while (!Serial) ; // wait for serial port to connect. Needed for native USB
    Serial.println("start");
    
    pinMode(LEDB_PIN_VIN, OUTPUT);
    pinMode(LEDB_PIN_VIN2, OUTPUT);
    pinMode(LEDB_PIN_VIN3, OUTPUT);
}

// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop() 
{
    // Ultrasonic Sensor - HC-SR04 - Test Code
    // Read distance measurment from UltraSonic sensor           
    int hcsr04Dist = hcsr04.ping_cm();
    delay(10);

    if (hcsr04Dist > 0 && hcsr04Dist < 100)
    {
      Serial.print(F("Distance: ")); Serial.print(hcsr04Dist); Serial.println(F("[cm]"));
      if (timeout == 0)
      {
        digitalWrite(LEDB_PIN_VIN, HIGH);   // turn the LED on (HIGH is the voltage level)
        digitalWrite(LEDB_PIN_VIN2, HIGH);   // turn the LED on (HIGH is the voltage level)
        digitalWrite(LEDB_PIN_VIN3, HIGH);   // turn the LED on (HIGH is the voltage level)
      }
      timeout = millis() + 750;
    }

    if (timeout > 0 &&
      millis() > timeout)
    {
        timeout = 0;
        digitalWrite(LEDB_PIN_VIN, LOW);    // turn the LED off by making the voltage LOW
        digitalWrite(LEDB_PIN_VIN2, LOW);    // turn the LED off by making the voltage LOW
        digitalWrite(LEDB_PIN_VIN3, LOW);    // turn the LED off by making the voltage LOW
    }
}



/*******************************************************

*    Circuito.io is an automatic generator of schematics and code for off
*    the shelf hardware combinations.

*    Copyright (C) 2016 Roboplan Technologies Ltd.

*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.

*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.

*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see .

*    In addition, and without limitation, to the disclaimers of warranties 
*    stated above and in the GNU General Public License version 3 (or any 
*    later version), Roboplan Technologies Ltd. ("Roboplan") offers this 
*    program subject to the following warranty disclaimers and by using 
*    this program you acknowledge and agree to the following:
*    THIS PROGRAM IS PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS, AND 
*    WITHOUT WARRANTIES OF ANY KIND EITHER EXPRESS OR IMPLIED.  ROBOPLAN 
*    HEREBY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT 
*    NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY, TITLE, FITNESS 
*    FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND THOSE ARISING BY 
*    STATUTE OR FROM A COURSE OF DEALING OR USAGE OF TRADE. 
*    YOUR RELIANCE ON, OR USE OF THIS PROGRAM IS AT YOUR SOLE RISK.
*    ROBOPLAN DOES NOT GUARANTEE THAT THE PROGRAM WILL BE FREE OF, OR NOT 
*    SUSCEPTIBLE TO, BUGS, SECURITY BREACHES, OR VIRUSES. ROBOPLAN DOES 
*    NOT WARRANT THAT YOUR USE OF THE PROGRAM, INCLUDING PURSUANT TO 
*    SCHEMATICS, INSTRUCTIONS OR RECOMMENDATIONS OF ROBOPLAN, WILL BE SAFE 
*    FOR PERSONAL USE OR FOR PRODUCTION OR COMMERCIAL USE, WILL NOT 
*    VIOLATE ANY THIRD PARTY RIGHTS, WILL PROVIDE THE INTENDED OR DESIRED
*    RESULTS, OR OPERATE AS YOU INTENDED OR AS MAY BE INDICATED BY ROBOPLAN. 
*    YOU HEREBY WAIVE, AGREE NOT TO ASSERT AGAINST, AND RELEASE ROBOPLAN, 
*    ITS LICENSORS AND AFFILIATES FROM, ANY CLAIMS IN CONNECTION WITH ANY OF 
*    THE ABOVE. 
********************************************************/

Drone Flight #6

Flight #6 is been the highest flight I’ve done yet. My hands were shaking from the cold or the fear, “don’t lose this one!”. Also those LEDs turn RED as the A23 battery voltage current drops. I might go with single color LEDs (not the RGB kind) so they stay the same color.

For the next flight, I’ll want to aim towards the mountains.

Drone 2

[Full Drone Part List]

[$13.99 F450 Frame]

Landing Gear: [$7.75 black] [$6.99 white]

[$12.98 Zip Ties]

4 X Motors/ESCs: [$5.83 each] or [$9.96 each]

[$7.99 for 20 X ESC Bullet Connectors]

Flight Controller: [$127.98 Pixhawk]

[$7.95 Better GPS bracket]

Receiver: [iA6B Receiver] or [Transmitter/Receiver]

Battery: [$91.70 Venom 5000 mah]

Camera: [$70 GoPro HERO3]

LEDs: [$10.49 for 4 X RGB Leds]

LED Power: [$4.19 for 2 X 12V A23 Batteries]

Setup:

Tutorial: [Attach ESC wires]

Tutorial: [Modify ESC wires]

Tutorial: [Connect ESCs to power distribution board]

Tutorial: [Setup Battery Connection]

Tutorial: [Pixhawk Wiring]

Pixhawk Drone arming

[Hobbypower Pixhawk PX4 Flight Controller]

[HKPilot32 Flight Controller] [products]

[Logging blocking arming]

[PreArm: Logging failed]

Arming is failing and I’m down to these messages.

PreArm: Logging failed
Frame: QUAD
fmuv2 002A0037 3337510B 32343735
ChibiOS: ff603d11
ArduCopter V3.6.3 (63eb66fe)
PreArm: Logging failed
u-blox 1 HW: 00080000 SW: ROM CORE 3.01 (107888)
PreArm: Logging failed
PreArm: Hardware safety switch
EKF2 IMU1 tilt alignment complete
EKF2 IMU0 tilt alignment complete
EKF2 IMU1 initial yaw alignment complete
EKF2 IMU0 initial yaw alignment complete
GPS 1: detected as u-blox at 115200 baud
Frame: QUAD
fmuv2 002A0037 3337510B 32343735
ChibiOS: ff603d11
ArduCopter V3.6.3 (63eb66fe)
Barometer calibration complete
Initialising APM

There’s an arm check for logging that had to be disabled. Now arming works.