Logo
Builders' Plan Gallery  |  Hip Pocket Web Site  |  Contact Forum Admin (Account/Technical Issues)  |  Contact Global Moderator
December 07, 2021, 01:24:53 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with email, password and session length
 
Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: DIY Arduino Beetle DT/ESC timer  (Read 505 times)
0 Members and 1 Guest are viewing this topic.
DougFunny
Bronze Member
***

Kudos: 1
Offline Offline

United States United States

Posts: 41

Topic starter


Ignore
« on: August 21, 2021, 04:51:37 PM »

Here is a project I have been messing around with- the arduino Beetle is a ATMega32 microprocessor on a tiny (a little larger than a quarter) platform. It is very inexpensive (about $7).
I have implemented this as a simple flight controller. The concept uses two trim-pots, one for motor run and the other for DT servo. A pushbutton is pressed to arm the ESC, then pressed again to start flight. If the flight needs to be cancelled, the button can be pressed again, the motor stops, and all timers reset. At the end of a flight, the button is pressed, which rotates the DT servo back into flight position and resets the timers.

I am an industrial controls engineer, but have very little experience with arduino/C programming languages, so my code may not be the most elegant, but all is working well thus far!

The parts I used:
DFRobot Arduino Beetle ($7)
3A DC voltage step down ($1 ebay)
10k linear trim pot ($5/50 pcs ebay)
micro tactile thru-hole momentary pushbutton ($3/20 pcs ebay)
prototype board ($2.99 ebay)
1.7g digital servo ($4 hobbyking)
6a turnigy esc ($10 hobbyking)
misc. wire and JST connectors

The code:

#include <Servo.h>
Servo dtservo;
Servo escservo;
const int ledPin =  13;      // the number of the LED pin
const int potPin = A2;// select the input pin for the potentiometer     // variable to store the value coming from the sensor
const int spdPin = A1;
unsigned long DELAY_TIME = 0;
unsigned long delayStart = 0;
unsigned long DELAY_TIME2 = 0;
unsigned long delayStart2 = 0;
unsigned long value = 0;
unsigned long value2 = 0;
int buttonState = 0;         // variable for reading the pushbutton status
bool delayRunning = false;
bool delayRunning2 = false;
bool resetLatch = false;
int pos = 0;
int pos2 = 0;



void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(2, INPUT_PULLUP);
  escservo.attach(9,1000,2000);
  escservo.write(0);
  escservo.write(180);
  dtservo.attach(11);
  dtservo.write(90);
}

void timer() {
  if (delayRunning && ((millis() - delayStart) >= DELAY_TIME)) {
    resetLatch = true;
    delayRunning = false; // finished delay -- single shot, once only
    digitalWrite(ledPin, LOW); // turn led off
    dtservo.write(150);
  }
}

void timer2 () {
  if (delayRunning2 && ((millis() - delayStart) >= DELAY_TIME2)) {
    delayRunning2 = false;
    escservo.write(0);
  }
}


void loop() {

  int pbVal = digitalRead(2);  //button status check - convert pullup input to correct h/l orientation
  if (pbVal == HIGH) {
    buttonState = LOW;

  } else {
    buttonState = HIGH;
  }
 
  value = analogRead(potPin); // scale potentiometer value to timer range in millisec
  value = map(value, 0, 1023, 0, 120000);
  DELAY_TIME = value;
  delay(100);                          //Small delay


  value2 = analogRead(spdPin); // scale potentiometer value to motor run range in millisec
  value2 = map(value2, 0, 1023, 0, 30000);
  DELAY_TIME2 = value2;
  delay(100);                          //Small delay

  timer();
  timer2();

  if ((buttonState == HIGH) && (resetLatch == false) && (delayRunning == false)) { //run timer routine
    digitalWrite(ledPin, HIGH);
    dtservo.write(90);
    escservo.write(180);
    delayStart = millis();
    delayRunning2 = true;
    delayRunning = true;
  }
  else if ((buttonState == HIGH) && (resetLatch == true) && (dtservo.read() != 90)) { //timer routine already done, reset servo to 0
    dtservo.write(90);
    escservo.write(0);
    digitalWrite(ledPin, LOW);
  }
  else if ((buttonState == LOW) && (resetLatch == true) && (dtservo.read() == 90)) { //reset timer done
    resetLatch = false;
    escservo.write(0);
  }
  else if ((delayRunning == true) && (resetLatch == false) && (buttonState == HIGH)) {
    digitalWrite(ledPin, LOW);
    escservo.write(0);
    delayRunning = false;
    delayRunning2 = false;
    resetLatch = false;
  }
}


I've attached a layout picture of using TinkerCad, it's doesn't use the exact same arduino control board, but all the wires connect to the same places on the Beetle. Also not shown is the DC stepdown that is necessary to avoid frying the Beetle and servo when using a battery greater than 5volts. I will try to draw a better representation of the actual schematic when I get a chance.
Attached files Thumbnail(s):
DIY Arduino Beetle DT/ESC timer
Logged
Pat D
Silver Member
****

Kudos: 5
Offline Offline

Ireland, Republic of Ireland, Republic of

Posts: 223




Ignore
« Reply #1 on: September 02, 2021, 06:22:54 AM »

Hi, this is really interesting and I have thought about doing something similar also using the Arduino platform, I think I will source the parts you have outlined and give it a go myself.

Thanks for sharing

Pat
Logged
DougFunny
Bronze Member
***

Kudos: 1
Offline Offline

United States United States

Posts: 41

Topic starter


Ignore
« Reply #2 on: September 03, 2021, 08:46:31 PM »

Thanks Pat. I suppose I should have taken pics of my wiring/soldering, but A) it was really quite messy, and B) I wrapped the boards in electrical tape to prevent shorts and then screwed to the inside of the model. For testing your code and wiring design, I can’t recommend TinkerCad enough. They currently only have emulation for the full sized Arduino board, but it’s still a great way to work out bugs entirely on the computer.
Logged
wcstoddart
Bronze Member
***

Kudos: 1
Offline Offline

United States United States

Posts: 14



Ignore
« Reply #3 on: October 27, 2021, 12:31:45 PM »

Thanks for sharing this interesting timer implementation. 
Have you considered using one of the remaining analog or digital pins to read an RDT signal while inside the Loop (without the use of an Interrupt)?

best wishes,
Chris
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!