Skip to main content

[DIY] Arduino : Serial Monitor - String Operations

Curious on how does Arduino Serial Monitor interacts and processes the string read and Output Functions.

Activity: Use Serial Port to blink Red, Green or Yellow LED one at a time.

Wiring Diagram:


Bill of Material:


Arduino IDE Code: 

int redPin = 13;
int greenPin = 11;
int yellowPin = 9;

String msg = "Hi!, which LED color would you like to glow? ";
String ledPick;
String msg2 = " blinking done!";

void setup() {
  Serial.begin(9600);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
}

void loop() {
  Serial.println(msg);

  while (Serial.available() == 0) {
    // wait for input
  }

  ledPick = Serial.readString();

  if (ledPick == "RED" || ledPick == "red" || ledPick == "Red") {
    digitalWrite(redPin, HIGH);
    digitalWrite(greenPin, LOW);
    digitalWrite(yellowPin, LOW);
  }

  if (ledPick == "GREEN" || ledPick == "green" || ledPick == "Green") {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);
    digitalWrite(yellowPin, LOW);
  }

  if (ledPick == "YELLOW" || ledPick == "yellow" || ledPick == "Yellow") {
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(yellowPin, HIGH);
  }

  Serial.print(ledPick);
  Serial.println(msg2);
}

Comments

Popular posts from this blog

Hobby Rocket Motors: Classes, Thrust and Applications

Rocket motors provide the thrust required to accelerate a hobby rocket. They are commonly classified by total impulse , while thrust describes the force produced at a particular instant during the motor's operation. For educational purposes, hobby motors can broadly be grouped as: Motor class Category Typical application A–D Low-power Beginner and STEM model rockets E–G Mid-power Larger hobby and educational rockets H–O+ High-power/amateur Advanced rocketry and specialized projects The boundaries can depend on the motor's characteristics and applicable regulations. Fig. Motor Classification Based upon Power. Fig. Small Rocket Motors Understanding Thrust and Total Impulse Thrust is the force generated by the motor and is measured in Newtons (N). Total impulse represents the overall thrust delivered during the motor's operating period and is measured in Newton-seconds (N·s). These are different parameters. A motor can have a high peak thrust but a short burn, while another ...

Navigating the Future: STEM and Autonomous Driving

  Autonomous driving, often referred to as self-driving technology, is one of the most fascinating applications of STEM (Science, Technology, Engineering, and Mathematics). It combines multiple disciplines to create vehicles that can navigate roads, avoid obstacles, and make decisions without human intervention. This blog dives into the ongoing technologies driving this innovation and highlights free resources and software to help you explore this exciting field. Ongoing Technologies in Autonomous Driving 1. Sensors and Perception Autonomous vehicles rely on sensors to perceive their environment. These include: LiDAR (Light Detection and Ranging): Creates 3D maps of surroundings. Radar : Detects objects and measures their speed. Cameras : Provide visual data for object recognition and lane detection. Ultrasonic Sensors : Aid in short-range detection for parking and obstacle avoidance. 2. Machine Learning and Artificial Intelligence (AI) AI enables vehicles to process m...

Exploring the Cosmos Starts Here: Simulate with GMAT

The ability to simulate and analyze satellite or spacecraft missions before they ever leave the ground is one of the most powerful tools in modern aerospace engineering. Among the most accessible and capable tools for this purpose is NASA’s GMAT — the General Mission Analysis Tool. Developed by NASA’s Goddard Space Flight Center, GMAT is a free and open-source platform for designing and simulating space missions. It has been used in real-world missions such as LCROSS (Lunar Crater Observation and Sensing Satellite) and the Lunar Reconnaissance Orbiter. This article offers a high-level overview of what GMAT can do, followed by a hands-on walkthrough of a simple satellite orbit simulation. The aim is to introduce the software's utility in a way that is accessible even to those without prior experience. What is GMAT? GMAT is a space mission analysis and trajectory optimization tool. It allows users to simulate spacecraft motion under a variety of physical forces including gravity...