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

Cse 630 A1

The document contains code for 6 Arduino programs that use UART serial communication and servo motors. The programs control LEDs, read input from the serial monitor, and manipulate servo positions using potentiometers. Functions are defined to setup and loop through the different programs.

Uploaded by

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

Cse 630 A1

The document contains code for 6 Arduino programs that use UART serial communication and servo motors. The programs control LEDs, read input from the serial monitor, and manipulate servo positions using potentiometers. Functions are defined to setup and loop through the different programs.

Uploaded by

Lg G
Copyright
© © All Rights Reserved
Available Formats
Download as 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");

}
2
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{

digitalWrite(12, LOW);

5
Serial.println("led2 off");

6
7
8
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 !");

void loop()

if (Serial.available()){

11
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);

digitalWrite(12,LOW);

12
delay(500);

digitalWrite(13,HIGH);

digitalWrite(12,HIGH);

delay(1500);

digitalWrite(13,LOW);

digitalWrite(12,LOW);

13
14
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);

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

myservo.write(val);

delay(15);

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