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

Digu Mechatronics LAB 6

This document summarizes 6 tasks completed as part of a mechatronics lab. The tasks include: 1) Blinking an LED using Arduino; 2) Using 3 LEDs to count from 0 to 7; 3) Interfacing a temperature sensor to light LEDs at different temperature thresholds; 4) Fading an LED brightness using analogWrite; 5) Printing to the serial monitor; and 6) Controlling a servo motor position through 4 positions. Code and circuit diagrams are provided for each task along with screenshots of outputs.

Uploaded by

CHHATRE YADNESH
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)
8 views

Digu Mechatronics LAB 6

This document summarizes 6 tasks completed as part of a mechatronics lab. The tasks include: 1) Blinking an LED using Arduino; 2) Using 3 LEDs to count from 0 to 7; 3) Interfacing a temperature sensor to light LEDs at different temperature thresholds; 4) Fading an LED brightness using analogWrite; 5) Printing to the serial monitor; and 6) Controlling a servo motor position through 4 positions. Code and circuit diagrams are provided for each task along with screenshots of outputs.

Uploaded by

CHHATRE YADNESH
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/ 9

Mechatronics LAB-6

Name: Yadnesh Chhatre ME-A


Batch- 3 Roll no: 61
PRN- 12110342

Task 1: Blinking LED – Build a circuit using Arduino and an LED. LED
should be OFF initially. It should turn ON after 1 s. Then OFF for 1 s. Then
ON for 1 s …. and so on.
Code:
void setup()
{
pinMode(12, OUTPUT);
}
void loop()
{
digitalWrite(12, HIGH);
delay(500);
digitalWrite(12, LOW);
delay(500);
}
Snapshot: Output:
Task 2: Decimal counter using 3 LEDS, for counting nos from 0 to 7. The
ON-OFF combination of the 3 LEDs after certain no of seconds should
indicate the nos of seconds lapsed. After 7 s, all should go OFF again and
the circuit should stop.

Code:
void setup ()
{
pinMode (11, OUTPUT);
pinMode 12, OUTPUT);
pinMode (13, OUTPUT);
}
void loop()
{
digitalWrite (11, HIGH);
delay (1000);
digitalWrite (11, LOW);
digitalWrite (12, HIGH);
delay (1000);
digitalWrite (11, HIGH);
delay (1000);
digitalWrite (11, LOW);
digitalWrite (12, LOW);
digitalWrite (13, HIGH);
delay (1000);
digitalWrite (11, HIGH);
delay (1000);
digitalWrite (11, LOW);
digitalWrite (12, HIGH);
delay (1000);
digitalWrite (11, HIGH);
delay (1000);
digitalWrite (11, LOW);
digitalWrite (12, LOW);
digitalWrite (13, LOW);
delay (10000);
}

Circuit:

Figure: After 1s

Figure: After 2s Figure: After 3s

Figure: After 4s Figure: After 5s


Figure: After 6s Figure: After 7s

Task 3: Interfacing of temperature sensor

Code:
int baselineTemp = 0;
int celsius = 0;
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void loop()
{
// set threshold temperature to activate LEDs
baselineTemp = 40;
// measure temperature in Celsius
celsius = map(((analogRead(A0) - 20) * 3.04), 0, 1023, -40, 125);
if (celsius < baselineTemp) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
if (celsius >= baselineTemp && celsius < baselineTemp + 10) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
if (celsius >= baselineTemp + 10 && celsius < baselineTemp + 20) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
}
if (celsius >= baselineTemp + 20 && celsius < baselineTemp + 30) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
if (celsius >= baselineTemp + 30) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(1000); // Wait for 1000 millisecond(s)
}
Snapshot: Output:

Task 4: Fading of an LED

Code:
int brightness = 0;
void setup()
{
pinMode(9, OUTPUT);
}
void loop()
{
for (brightness = 0; brightness <= 1000; brightness += 5) {
analogWrite(9, brightness);
delay(100);
}
for (brightness = 1000; brightness >= 0; brightness -= 5) {
analogWrite(9, brightness);
delay(100);
}
}

Snapshot: Output:

Task 5: Serial monitor

Code:

void setup()

Serial.begin(9600);

void loop()

Serial.println("Hello Arduino");

delay(1000);

Circuit:
Serial Monitor Output:

Task 6: Implementation of servo / other motors

Code:
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(9);
}
void loop()
{
myservo.write(45);
delay(1000);
myservo.write(90);
delay(1000);
myservo.write(135);
delay(1000);
myservo.write(180);
delay(1000);
}
Snapshot: Output:

You might also like