0% found this document useful (0 votes)
48 views8 pages

Lab 6

The document describes the lab assignment completed by student Ayush Yadav of TY-ME-D division with roll number 55. The assignment involved 6 tasks - blinking an LED, building a binary counter, interfacing a temperature sensor, fading an LED, using a serial monitor, and implementing a servo motor. Code snippets are provided for each task.

Uploaded by

Ayush yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views8 pages

Lab 6

The document describes the lab assignment completed by student Ayush Yadav of TY-ME-D division with roll number 55. The assignment involved 6 tasks - blinking an LED, building a binary counter, interfacing a temperature sensor, fading an LED, using a serial monitor, and implementing a servo motor. Code snippets are provided for each task.

Uploaded by

Ayush yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Name: Ayush Yadav ; Div.

: TY-ME-D ; Roll no: 55

Mechatronics -Lab Assignment 6

Experiment - Simulation of microcontroller action and building basic control system


(using Arduino simulator)

Task 1 : Blinking of LEDs

Code

void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);

digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}

Task 2 : Binary Counter

Code :

int pin1=11; int


pin2=10;
int pin3=9;

int timr=1000;
int i=0; void
setup() {

pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);pinMode(pin3,OUTPUT);

void loop() {
digitalWrite(pin3,LOW); digitalWrite(pin2,LOW);
digitalWrite(pin1,LOW);
delay(timr);

i++;

if((i % 2) > 0) { digitalWrite(pin1, HIGH); } else { digitalWrite(pin1, LOW); }

if((i % 4) > 1) { digitalWrite(pin2, HIGH); } else { digitalWrite(pin2, LOW); }

if((i % 8) > 3) { digitalWrite(pin3, HIGH); } else { digitalWrite(pin3, LOW); }

delay(timr);

}
Task 3 : Interfacing of Temperature sensor

Code :

int pinTemp = A1;

void setup() {
Serial.begin(9600);
} void loop() { int temp =
analogRead(pinTemp); temp =
temp * 0.48828125;
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println("C"); delay(1000);
}
Task 4 : Fading of LED

Code -

int led = 13; int


brightness = 0;
int fadeAmount = 5;

void setup() {

pinMode(led, OUTPUT);
}

void loop() {

analogWrite(led, brightness);

brightness = brightness + fadeAmount;

if (brightness <= 0 || brightness >= 255) {


fadeAmount = -fadeAmount;
}
delay(30);
}
Task 5 : Application of serial monitor

Code :

const int trigPin = 9;


const int echoPin = 10;

long duration; int


distance;
void setup() { pinMode(trigPin,
OUTPUT); pinMode(echoPin,
INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance); delay
(1000);
}

Task 6 : Implementation of servo motor

Code
#include<Servo.h>
Servo Myservo;
int pos; void
setup()
{
Myservo.attach(3);
}

void loop()
{

for(pos=0;pos<=180;pos++){
Myservo.write(pos);
delay(15); } delay(1000);
for(pos=180;pos>=0;pos--){
Myservo.write(pos);
delay(15); } delay(1000);

You might also like