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 8945217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:11:52+00:00 2026-06-15T12:11:52+00:00

I am trying to make a Arduino program where it receives signals from the

  • 0

I am trying to make a Arduino program where it receives signals from the Serial monitor and then lights LED’s accordingly, i have it set up with RGB. But I have a problem where all three LED’s light like the blue one only should. here is my code:

#define SENSOR 0   
#define R_LED 11
#define G_LED 10
#define B_LED 9
#define BUTTON 12
int val = 0;
int times = 0;
int btn = LOW;
int old_btn = LOW;
int state = 0;
int r = 0;
int g = 0;
int b = 0;
byte inByte = 0;
char buffer[5];
void setup() {
  Serial.begin(9600);
  pinMode(BUTTON, INPUT);
}
void loop() {
  val = analogRead(SENSOR);
  Serial.println(val);
  if (Serial.available() > 0) {
    inByte = Serial.read();
    if (inByte == '#') {
      r = Serial.read() + 1;
      r = r * 25;
      g = Serial.read() + 1;
      g = g * 25;
      b = Serial.read() + 1;
      b = b * 25;
    }
  }   
  btn = digitalRead(BUTTON);
  if ((btn == HIGH) && (old_btn == LOW)){
    state = 1 - state;
  }
  old_btn = btn;
  if (state == 1){
    analogWrite(R_LED, r);
    analogWrite(G_LED, g);
    analogWrite(B_LED, b);
  }else{
    analogWrite(R_LED, 0);
    analogWrite(G_LED, 0);
    analogWrite(B_LED, 0);
  }
  delay(100);
}

Note: I am sure it is a coding issue, not a mechanical one,for your information.

  • 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-15T12:11:53+00:00Added an answer on June 15, 2026 at 12:11 pm

    If I understand what you’re doing correctly, some code such as #987 will be sent on the serial monitor every time you want the color to change, correct? In that case, the issue is that when you do r = Serial.read() + 1; (and the same goes for b and g), Serial.read() is returning the ASCII code for a character from '0' through '9' (48 – 57). Try this:

      r = Serial.read() - '0' + 1;
      r = r * 25;
      g = Serial.read() - '0' + 1;
      g = g * 25;
      b = Serial.read() - '0' + 1;
      b = b * 25;
    

    This will subtract the ASCII code for '0' first, so the numbers will be in the proper 0-9 range.

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

Sidebar

Related Questions

I'm trying to make a app that read the outgoing signals from Arduino, but
In my Arduino IDE I have set up a program that runs eight LEDs
I have just bought an Arduino Uno and I am currently trying to make
Trying to make the infamous checkall checkbox for dynamically created rows from a MySQL
Trying to make a cross protocol, same domain request from https to http. I
im trying make one replace in string from a array but this dont work
I am trying make a request and get response from server. Here is my
in my application I am trying make a requst but i have received an
I'm trying to interact with my Arduino Uno from my Android tablet running 4.0.3
I'm trying make this code which is from a Dictionary of Arrays (CODE) from

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.