0% found this document useful (0 votes)
49 views

Cse 630 A1303

The document contains 6 sections that describe Arduino programs using UART communication and servo motors. Section 1 turns an LED on or off based on character input over UART. Section 2 controls two LEDs based on vowel/consonant input. Section 3 blinks LEDs differently for alphanumeric vs non-alphanumeric input. Section 4 displays digits on a 7-segment display. Section 5 controls a servo motor position using one potentiometer. Section 6 controls a servo using two potentiometers by alternating between their values.

Uploaded by

Lg G
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Cse 630 A1303

The document contains 6 sections that describe Arduino programs using UART communication and servo motors. Section 1 turns an LED on or off based on character input over UART. Section 2 controls two LEDs based on vowel/consonant input. Section 3 blinks LEDs differently for alphanumeric vs non-alphanumeric input. Section 4 displays digits on a 7-segment display. Section 5 controls a servo motor position using one potentiometer. Section 6 controls a servo using two potentiometers by alternating between their values.

Uploaded by

Lg G
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

ASSIGNMENT1

Leepaakshi g 03/08/2021 CB.EN.U4CSE19630

1) UART-1(A/a)

void setup()

Serial.begin(9600);

pinMode(13, OUTPUT);

Serial.println("Welcome to Tutorial -Serial !");

void loop()

if (Serial.available()){

char c=Serial.read();

if(c=='A'){

digitalWrite(13, HIGH);

Serial.println("led on");

else if(c=='a'){

digitalWrite(13, LOW);

Serial.println("led off");

} }
Entering'A’

2
Entering’a’

3
4
2)UART-2(vowels/consonants)

void setup()

Serial.begin(9600);

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

Serial.println("Welcome to Tutorial -Serial !");

void loop()

if (Serial.available()){

char c=Serial.read();

if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U'){

digitalWrite(13, HIGH);

Serial.println("led1 on");

else if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){

digitalWrite(13, LOW);

Serial.println("led1 off");

else if(isUpperCase(c)){

digitalWrite(12,HIGH);

Serial.println("led2 on");

else{

5
digitalWrite(12, LOW);

Serial.println("led2 off");}}}

Enterin’A’

6
Entering ‘a’

7
Entering ‘C’

8
Entering'c’

9
10
3)UART-3(blink twice alphanumeric)

void setup()

Serial.begin(9600);

pinMode(13,OUTPUT);

pinMode(12,OUTPUT);

Serial.println("Welcome to Tutorial -Serial !");

11
void loop()

if (Serial.available()){

char c=Serial.read();

if(isAlphaNumeric(c)){

if(isAlpha(c)){

digitalWrite(13,HIGH);

delay(1500);

digitalWrite(13,LOW);

delay(500);

digitalWrite(13,HIGH);

delay(1500);

digitalWrite(13,LOW);

else{

digitalWrite(12,HIGH);

delay(1500);

digitalWrite(12,LOW);

delay(500);

digitalWrite(12,HIGH);

delay(1500);

digitalWrite(12,LOW);

else{

digitalWrite(13,HIGH);

digitalWrite(12,HIGH);

delay(1500);

digitalWrite(13,LOW);

12
digitalWrite(12,LOW);

delay(500);

digitalWrite(13,HIGH);

digitalWrite(12,HIGH);

delay(1500);

digitalWrite(13,LOW);

digitalWrite(12,LOW);

Entering'a’

13
Entering'7’

14
Entering'%’

15
16
4)7-segment(0-F)

void setup()

int i=2;

pinMode(i, OUTPUT);

void loop()

// display a new digit every second

17
for (int digit = 0; digit <= 15; digit++)

for (int pin = 4; pin <= 7; pin++)

digitalWrite(pin, (bool)(digit & (1 << pin - 4)));

delay(1000);

18
19
5)servo(one potentiometer)

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer

int val; // variable to read the value from the analog pin

void setup() {

myservo.attach(9); }

void loop() {

val = analogRead(potpin);

val = map(val, 0, 1023, 0, 180);

myservo.write(val);

delay(15);}

20
21
22
6)servo(two potentiometer)

#include <Servo.h>

Servo myservo;

#include <Servo.h>

int potpin1 = 0;

int potpin2=1;

int val1,val2 ;

boolean flag=true;

void setup() {

myservo.attach(9);

23
}

void loop() {

val2 = analogRead(potpin1);

val2 = analogRead(potpin2);

val1 = map(val1, 0, 1023, 90, 180);

val2 = map(val2, 0, 1023, 90, 0);

if(flag)

{ myservo.write(val1);}

else

{ myservo.write(valr2);}

if(val2==90)

{ myservo.write(valr1);flag=true;}

if(val1==90 )

{ myservo.write(val2); flag=false;}

delay(15);

24
25
26
27

You might also like