Arduino Beginner Series: Project 8: LED choice from Serial monitor

Hello everyone!! Welcome to this post on Arduino LED Projects!!
Need a short introduction to what the Arduino is then click on LINK
Check out the breadboard intro right HERE

In this project we’ll tell the Arduino if we want green, red, yellow or blue LED on.

Demo:

So this is what my project looks like:

Things Required:

  1. Arduino UNO
  2. LEDs (1 of green, red, yellow and blue each)
  3. Breadboard
  4. 220 ohm resistor (x4)
  5. Jumper Wires
  6. Arduino IDE on computer

Functions used:

  1. digitalWrite()
  2. Serial.println()
  3. Serial.available()
  4. Serial.readString()

Reference Material:

I referred to this (LINK) video for this project.

Code:

View/ Download from Github : (LINK)

int greenled= 11;
int redled=10;
int yellowled=9;
int blueled=8;
String msg1= "Do you want green, red, yellow or blue led on?";
String choice;
String msg2=" led is on";

void setup() {
  // put your setup code here, to run once:
  pinMode(greenled, OUTPUT);
  pinMode(redled, OUTPUT);
  pinMode(yellowled, OUTPUT);
  pinMode(blueled, OUTPUT);
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(msg1);
  while(Serial.available()==0){
    
  }

  choice = Serial.readString();

  if(choice=="green"){
    digitalWrite(greenled, HIGH);
    digitalWrite(redled, LOW);
    digitalWrite(yellowled, LOW);
    digitalWrite(blueled, LOW);
  }

  if(choice=="red"){
    digitalWrite(greenled, LOW);
    digitalWrite(redled, HIGH);
    digitalWrite(yellowled, LOW);
    digitalWrite(blueled, LOW);
  }

  if(choice=="yellow"){
    digitalWrite(greenled, LOW);
    digitalWrite(redled, LOW);
    digitalWrite(yellowled, HIGH);
    digitalWrite(blueled, LOW);
  }

  if(choice=="blue"){
    digitalWrite(greenled, LOW);
    digitalWrite(redled, LOW);
    digitalWrite(yellowled, LOW);
    digitalWrite(blueled, HIGH);
  }

}

Stay Tuned for upcoming posts on Arduino Projects! We’re on the basic newbie projects right now and slowly, gradually move on to those cool, ultra techy projects!! Want to be the first to know when a new and amazing post comes up?? Then feel free to subscribe!

Happy Learning!!

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: