Question

In: Computer Science

arduino programing Question 1: write an APL program that will print the following output on the...

arduino programing

Question 1: write an APL program that will print the following output on the serial monitor 10 times only.  


Output:  1


2


3


4


5

Question 2: write an APL program that will turn the traffic lights on and off by taking input from the Serial port working at 11500 bits processing rate. Use r or R for RED LIGHTS, y or Y for YELLOW LIGHTS and g or G for GREEN LIGHTS.   

Question 3: write an APL program that will control two DC motors at 75 % PWM using ADA FRUIT STEPPER MOTOR SHIELD. Your program must let user to send the direction in which the motor rotates. F or F for FORWARD, b or B for BACKWARDS, r or R for RIGHT, l or L for LEFT, and s or S for STOP.

Solutions

Expert Solution

here i am writing in arduino code after // this i will explain about that line

Question no.1:

void setup() {
Serial.begin(9600);      //for this line arduino will start communication with serail monitor at 9600 processing rate
}

void loop() {                            // it is also known as main function
for(int i=0; i<10; i++)                // this for loop will run 10 times means it will print content 10 times on the serial monitor
{
    for(int j=1; j<=5; j++)             // this loop will run 5 times and will start with 1 and print 1 and each and every loop it will increment by 1
    {
      Serial.println(j);                // it will print value of j with new line
    }
}
}

Question no.2

#include<SoftwareSerial.h>            //need to add library file of serial port
SoftwareSerial mySerial(2, 3);    // declaring serial port under the barracket declare the rx pin and tx pin of arduino
char val;    // declaring the varibale which store the value coming from serial port
int redled = 7;     // declaring pin for lights
int yellowled = 8;
int greenled = 9;
void setup() {                      // Setup function
mySerial.begin(11500);         // setting the data rate for the serial port to communicate at this rate
pinMode(redled, OUTPUT);        //pimode for the lights
pinMode(yellowled, OUTPUT);
pinMode(greenled, OUTPUT);
void off();                       // calling off function for initially all lights will off when program will start
}
void off()
{
digitalWrite(redled,LOW);              // creating off function
digitalWrite(yellowled,LOW);
digitalWrite(greenled,LOW);
}
void loop() {             // main function
if(mySerial.available())               //it will checks for communication means data is coming or not
{
    val=mySerial.read();              // if coming then store the data in val variable
}
switch(val)                        // switch case is the best control structure to control component according to serail port data
{
    case 'r':                          // if val == r
        void off();                     // then calling off function if any light is on then it will off then
        digitalWrite(redled,HIGH);      // only red light will on
        break;
    case 'R':                         // if data will come in capital letter
     void off();
     digitalWrite(redled,HIGH);
     break;
     case 'y':                           // similarly it is for all the lights
      void off();
      digitalWrite(yellowled,HIGH);
      break;
      case 'Y':
       void off();
      digitalWrite(yellowled,HIGH);
      break;
      case 'g':
       void off();
      digitalWrite(greenled,HIGH);
      break;
      case 'G':
       void off();
      digitalWrite(greenled,HIGH);
      break;
      default:                      // if nothing data are come or another else data will come then it call off function
      void off();
      break;
}

}

Question no.3:

#include<SoftwareSerial.h>       // library file for communication between ports
SoftwareSerial mySerial(2,3);   //declartion of serail port with rx and tx pin
const int IN1=7;          // motor 1 of 2 pin
const int IN2=6;         //motor 1 of 2 pin
const int IN3=5;        // motor 2 of 1 pin
const int IN4=4;       // motor 2 of 2 pin
const int EN1=8;      // sheild enable pin
const int EN2=9;     // sheild enable pin
char val;           // declaring the varibale which store the value coming from serial port
void setup() {
mySerial.begin(9600);             // start communication with serial port
pinMode(IN1,OUTPUT);             // pinmode of all motor and enable pin
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
pinMode(EN1,OUTPUT);
pinMode(EN2,OUTPUT);
void stop();

}
void loop() {
analogWrite(EN1,192);           // here we are controlling speed of motor see when we use 100 % of pwm then we have to give 255 value so here are using 75% of pwm then 255 of 75% is around 192
analogWrite(EN2,192);
if(mySerial.available())               //it will checks for communication means data is coming or not
{
    val=mySerial.read();              // if coming then store the data in val variable
}
switch(val)       // switch case is the best control structure to control component according to serail port data
{
    case 'f':            // when serial read f then it call forward function
    void forward();
    break;
    case 'F':         // also when serial read F then it call forward function
    void forward();
    break;
    case 'b':               // similarly when b or B read then it call backward function
    void backward();
    break;
    case 'B':
    void backward();
    break;
    case 'r':          // similarly when r and R read then it call right function
    void right();
    break;
    case 'R':
    void right();
    break;
    case 'l':            //similalrly when l and L read then it call left function
    void left();
    break;
    case 'L':
    void left();
    break;
    case 's':          // and when s and S read then it call stop function
    void stop();
    break;
    case 'S':
    void stop();
    break;
}

}
void forward()            //creating forward function it will run the motor in forward direction
{
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
void backward()            //creating backward function it will run the motor in backward direction
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
}
void left()                     //creating left function it will run the motor in left direction
{
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
}
void right()                    //creating right function it will run the motor in right direction
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
}
void stop()
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}


Related Solutions

Write the following in C language for Arduino: Write a program that turns on the LED...
Write the following in C language for Arduino: Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change. Remember you are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for...
Write the following in C language for Arduino: Write a program that increases the LED brightness...
Write the following in C language for Arduino: Write a program that increases the LED brightness in five steps with each press of the button. Remember you are going to using a digital input and the "digitalRead" command. You are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine...
Write Arduino program to implement wiring three momentary switches to the Arduino board
Write Arduino program to implement wiring three momentary switches to the Arduino board
Question 1: 5pts Write a program to receive two integers as user input and then print:...
Question 1: 5pts Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: 10pts An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is...
Question 1: Write a program to receive two integers as user input and then print: Sum...
Question 1: Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is compounded monthly....
Design and program an Arduino-based circuit that contains the following items - 1 Arduino Uno microcontroller....
Design and program an Arduino-based circuit that contains the following items - 1 Arduino Uno microcontroller. - 1 IR remote control, - 1 IR sensor - 1 LCD 16x2 Display - Any other components you find necessary. The circuit will do the following: - The circuit represents a 2-digit calculator. - At start of operation, the LCD display should display “0” in line 2 of the LCD display. - Pressing the On/Off button on the IR remote represents the “Clear”...
HOW CAN I WRITE A PROGRAMING CODE IN ARDUINO DIE ABOUT THE ROOT MEAN SQUARE VALUE...
HOW CAN I WRITE A PROGRAMING CODE IN ARDUINO DIE ABOUT THE ROOT MEAN SQUARE VALUE OF A SIGNAL
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
Write a C++ program for the following problem: Calculate and print the area and volume of...
Write a C++ program for the following problem: Calculate and print the area and volume of a cone inside a While  loop that goes from 1 to 20 with a step of .5. (the step is 1/2 or Point 5, so you go 10, 10.5,11, 11.5) Note: Your loop variable will need to be a double data type Use two decimal places on all numbers that are double data type. This will be a table with 3 columns. Don't worry about...
Objectives: Write a program which reads User Input using Scanner Print formatted output using printf or...
Objectives: Write a program which reads User Input using Scanner Print formatted output using printf or DecimalFormat Practice programming simple mathematical calculations Instructions: Samwise Gamgee has finally decided to submit his expense report for all of his adventures regarding his travels to Mordor. Part of those expenses are his stay at the Prancing Pony Inn located in Bree. You are to write a simple Java program which will generate an Invoice for his stay at the Inn. Your program should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT