element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Help a noob
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 6 replies
  • Answers 2 answers
  • Subscribers 389 subscribers
  • Views 1069 views
  • Users 0 members are here
Related

Help a noob

wazi
wazi over 4 years ago

Hi Guys

Please could you perhaps assist with a piece of code.

The basic idea is to have a countdown timer for my sons model rocket. He sets the time by mapping a pot and then "Arms: the system. After doing the checks he then presses a "Launch" button to initiate the countdown timer.

Once the timer reaches "0" it activates a relay and in turn fires the rocket.

 

I found the below code on the net and modified it with the help of a friend to use a i2c 16x2 LCD display.

I am in no way an expert but having fun learning.

 

I have 2 x minor issues now.

 

1st I need to add a decimal point to the countdown seconds (Currently displaying 000 seconds, I would like 00.0)

2nd, the LCD display is flickering. Even more so when the countdown initiates. ( I think this is due to bad coding)

 

Is anyone able to point me in the right direction and possibly recommend some improvements?

 

Code below -

 

 

 

 

 

#define FuseTIME      1500  //Fuse current duration in milliseconds.

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);//change address according to your LCD

#define Fuss     7          //Pin connected to the Fuse relay.

int GoButt = 6;             //Pin Connected to the GO button.

int ArmButt = 5;            //Pin connected to the ARM button.

#define BuzzPin  4          //Connected to the Speaker.

#define SetPot   0          //Analog Pin connected to the Pot.

 

void setup(){

 

lcd.begin();

 

  pinMode(Fuss,OUTPUT);

  pinMode(ArmButt, INPUT);        // set "ARM" button pin to input

  pinMode(GoButt, INPUT);         // set "GO" button pin to input

  digitalWrite(Fuss,LOW);         //OPEN the fuse circuit.

  digitalWrite(ArmButt, HIGH);    // turn on pullup resistor

  digitalWrite(GoButt, HIGH);     // turn on pullup resistor

 

lcd.clear();

lcd.setCursor(4,0);

lcd.print("Rocket");

lcd.setCursor(3,1);

lcd.print("Launcher"); 

delay(2000);

 

}

 

int  DownCntr;                    // down counter (1/10 Secs.)

int  Go=0;                        // Stopped

 

 

//================================================================

 

void loop(){

 

  if(!digitalRead(GoButt)||!digitalRead(ArmButt)){

 

    Go=0;                         //ABORT!!!

    tone(BuzzPin, 440, 1500);

    delay(1500);

  }

  if(Go==0){

    WaitARM();

    WaitGO();

  }  

  ShowTimer();

  if (DownCntr > 50){

      if (DownCntr % 10 ==0)tone(BuzzPin, 1000, 50);  //Tone every second.

     }

  else if (DownCntr % 2 ==0)tone(BuzzPin, 1000, 50);  //Tone every 1/5 second.

  if (DownCntr ==0){

 

 

    //------------------ ROCKET LAUNCH! --------------------

 

    tone(BuzzPin, 440, FuseTIME);  //Launch audible signal

    digitalWrite(Fuss,HIGH);       //CLOSE the fuse circuit

    delay(FuseTIME);

    digitalWrite(Fuss,LOW);        //OPEN the fuse circuit.

 

    //------------------------------------------------------

     Go=0;

    }

  while (millis()% 100);        //Wait until the next 1/10 of second.

  delay(50);

  DownCntr--;

}

 

//----------------------------------------

void WaitGO(){

  ShowTimer();

  while(digitalRead(GoButt));

  Go=1;

  delay(20);

  while(!digitalRead(GoButt));  //Debounce GO button.

}

 

//------------------------------------------------------

 

void ReadTimer(){

  DownCntr = map(analogRead(SetPot), 0, 1023, 10, 60);     // DownCntr = map(analogRead(SetPot), 0, 1023, 5, 60);

  DownCntr*=10;

}

 

//------------------------------------------------------

 

 

void ShowTimer(){

  String seconds = String (DownCntr, DEC);

  while(seconds.length()<3)seconds= "0" + seconds;     //format to 3 numbers.

  

lcd.clear();

lcd.setCursor(1,0);

lcd.print("Launching In");                                        

lcd.setCursor(1,1);

lcd.print(seconds);

lcd.setCursor(5,1);

lcd.print("Seconds");

 

}

 

//------------------------------------------------------

 

void WaitARM(){

  while(digitalRead(ArmButt)==1){

     ReadTimer();

     delay(50);

     ReadTimer();

     ShowTimer();                   //Show Digits.

     delay(150);

  }

 

  Go=0;

  ShowTimer();

  tone(BuzzPin, 2000, 150);

  delay(200);

  tone(BuzzPin, 2000, 150);

  delay(200);

  tone(BuzzPin, 2000, 150);

  delay(20);

  while(!digitalRead(ArmButt));  //Debounce ARM button.

 

}

  • Sign in to reply
  • Cancel

Top Replies

  • BigG
    BigG over 4 years ago +4 suggested
    LCD flickering is due to using this "lcd.clear();" repeatedly. Don't use after the first clear. For your first line on LCD. Just write once and that's it. Then all you need to do is update second line…
  • wazi
    wazi over 4 years ago in reply to Andrew J +4
    Hi Andrew Thanks so much for that, I really appreciate your assistance with this project. You are going to have a very happy 7 year old when he presses the buttons to launch his rocket. I changed this…
  • Andrew J
    Andrew J over 4 years ago in reply to wazi +3 verified
    No probs, we all start somewhere and you've clearly had a good go and got it pretty much working. I'm not too clear on what you are trying to achieve with the display of digits: does your value have an…
Parents
  • Andrew J
    0 Andrew J over 4 years ago

    Excellent, well done.  I see I got my comment wrong - it should of course read “...will treat the answer as a float...” and not “...as an integer...”

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Andrew J
    0 Andrew J over 4 years ago

    Excellent, well done.  I see I got my comment wrong - it should of course read “...will treat the answer as a float...” and not “...as an integer...”

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube