Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8356101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:04:50+00:00 2026-06-09T10:04:50+00:00

I am doing a project with an arduino to make a bell ring, and

  • 0

I am doing a project with an arduino to make a bell ring, and when I first tried, it worked how I wanted it to (wait(Serial.read())), but now I need to send over 100 0‘s over the serial port just to make it show for 4 seconds. Here is my Java code:
prepare for longness

Main.ringBell("100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");

public static void ringBell(String length) throws Exception {
     output.write(length.getBytes());
     output.flush();
}

Here is the Arduino sketch:

int ledPin = 13;

void setup() {
    pinMode(ledPin, OUTPUT);
    Serial.begin(9600);
}

void loop() {
    if(Serial.available() > 0) {
        digitalWrite(ledPin, HIGH);
        delay(Serial.read());
        digitalWrite(ledPin, LOW);
    }
}

Does anyone see a error in my code? If so, please just let me know what’s wrong and I’ll fix it.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:04:52+00:00Added an answer on June 9, 2026 at 10:04 am

    You are not sending one big number to the arduino but several ASCII bytes. The Arduino will see this sequence:

    49, 48, 48, 48, 48, 48, ...
    

    In each loop it will read one byte and wait for that number of milliseconds. 49 or 48 milliseconds are not a long time. So what you have is a constant flicker of the LED which is to fast to see with the eye.

    The next thing is: You are sending the bytes in one flush. But the Arduino has only a small internal buffer of 64 byte (see available docu). The rest is simply forgotten.

    Lets calculate roughly: 64 bytes * (48 ms delay per byte ) is 3072ms. Yes, this sounds plausible.

    Next thing would be: delay only can handle arguments of type unsigned long which is 32 bit which translates to ~4,000,000,000 milliseconds you can wait. Your argument in Main is way beyond this limit.

    So: The easiest thing is to use parseInt instead of read. And in Main supply only numbers in the range of a positive int (0.. 32767). And also do some delays in your Main before sending the next ringBell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing project based on epub reader. here to read a page I
I'm doing a project that involves speech recognition. But here i don't just need
I am planning on doing a small arduino project and would like to know
I've been doing project Euler for a few days, and I have to admit
I'm doing project on object detection using javacv in that I went through couple
I am doing project euler question 33 and have divised a refactor to solve
I am doing project in cakephp . I want to write below query in
im doing research project for a the game Text twist,the text will automatically search
After doing a project with WPF and getting very much attached to it's excellent
Im doing a project with C# winforms. This project is composed by: alt text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.