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

Handout-Control Using a Microcontroller

The document outlines an experiment for a control theory course using an ARDUINO microcontroller, focusing on various control tasks such as blinking LEDs, controlling brightness with a potentiometer, and rotating a servo motor. It provides detailed instructions for each task, including circuit diagrams, code listings, and the expected outcomes. Students are required to prepare a report documenting their setup and the logic behind their code implementations.

Uploaded by

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

Handout-Control Using a Microcontroller

The document outlines an experiment for a control theory course using an ARDUINO microcontroller, focusing on various control tasks such as blinking LEDs, controlling brightness with a potentiometer, and rotating a servo motor. It provides detailed instructions for each task, including circuit diagrams, code listings, and the expected outcomes. Students are required to prepare a report documenting their setup and the logic behind their code implementations.

Uploaded by

SS
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Control theory and applications (MCL212): Prof. S. V.

Modak, IIT Delhi

Experiment: Control using a Microcontroller

Objective: Study control using a Microcontroller

Tasks: Perform the following control tasks using an ARDUINO microcontroller. Make the
circuit for each task, write an Arduino sketch, compile it, upload it to the microcontroller,
and verify and demonstrate the desired control action.

1. Blinking two LEDs in sequence


2. Blink two LEDs with potentiometer input and PWM signal
3. Rotate a servo motor through desired angles
4. Blink two LEDs in breathing mode using the PWM signal

The ARDUINO codes:

• The ARDUINO codes for the first three tasks are given below so that you can learn
ARDUINO programming quickly and successfully implement these tasks.
• Watch my video on “Control using a Microcontroller”, which explains how to make
Arduino circuits for the first three tasks, the logic behind the codes below, and how
to implement these tasks.
• Learn the logic used, make files (i.e., Arduino sketches using these codes) on your
Laptop in IDE, upload them to the board, and demonstrate and verify the desired
control actions.

Report: Prepare a report with the a) circuit diagram, b) code listing, c) photo of the setup
you made and of the setup in action, and d) a brief description of the logic used to make
the code for each task

****
Control theory and applications (MCL212): Prof. S. V. Modak, IIT Delhi

ARDUINO codes

a) Blinking two LEDs in sequence

Control blinking of two LEDs in sequence. ON time = 2000 ms and OFF time = 500 ms.
The LEDs should continue to blink in sequence once started.

Further tasks: Change the ON/OFF times; change the delay. How will you modify the
program to blink the LEDs only a certain number of times?

//*************************************************
// THIS PROGRAM BLINKS TWO LEDs IN SEQUENCE
//*************************************************
//Define global constants here
int out_pin_1=12;
int out_pin_2=10;
int OFF_time=500;
int ON_time=2000;
//*************************************************
void setup() {
// put your setup code here, to run once:
pinMode(out_pin_1,OUTPUT);
pinMode(out_pin_2,OUTPUT);
}
//*************************************************
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(out_pin_1,HIGH);
delay(ON_time);
digitalWrite(out_pin_1,LOW);
delay(OFF_time);

digitalWrite(out_pin_2,HIGH);
delay(ON_time);
digitalWrite(out_pin_2,LOW);
delay(OFF_time);
}
//*************************************************
Control theory and applications (MCL212): Prof. S. V. Modak, IIT Delhi

b) Blink two LEDs together with brightness proportional to the potentiometer


input and PWM signal

Here, the brightness of the LEDs is controlled by a potentiometer and PWM signal.

//*************************************************
// THIS PROGRAM BLINKS TWO LEDs TOGETHER PROPORTIONAL TO THE
// POTENTIOMETER INPUT AND A PWM SIGNAL.
//*************************************************

//Define global constants here

int out_pin_1 = 11;


int out_pin_2 = 10;

//*************************************************
void setup() {
// put your setup code here, to run once:
pinMode(out_pin_1, OUTPUT);
pinMode(out_pin_2, OUTPUT);

Serial.begin(9600);
}

//*************************************************
void loop() {
// put your main code here, to run repeatedly:

int int_val_voltage_1024 = analogRead(A0); //THIS IS IN DIGIT FROM 0 TO 1023


Serial.println(int_val_voltage_1024);

int int_val_voltage_255 = int_val_voltage_1024 / 4; //THIS IS IN DIGIT FROM 0 TO 255

analogWrite(out_pin_1, int_val_voltage_255);
analogWrite(out_pin_2, int_val_voltage_255);
}
//*************************************************

c) Rotate a servo motor through desired angles

Command the servo motor to go from position 0 to 20 degrees in step of 5. This


should be followed by servo directly going to position 100 and then to 140 in
steps of 10.
Control theory and applications (MCL212): Prof. S. V. Modak, IIT Delhi

//********************************************************
// THIS PROGRAM ROTATES A SERVO MOTOR THROUGH DESIRED
ANGLES
//********************************************************
// INCLUDE INBUILT SERVO LIBRARY
#include <Servo.h>

//Define global constants here

int out_pin_1=9;
Servo servo1;//DECLARE A SERVO OBJECT WITH A CHOSEN NAME
//*************************************************
void setup() {
// put your setup code here, to run once:
servo1.attach(out_pin_1);

// COMMAND THE SERVO TO GO FROM POSITION 0 TO 20 DEGREE IN


STEPS OF 5
for(int desired_theta=0; desired_theta<=20; desired_theta+=5){
servo1.write(desired_theta);
delay(1000);
}

// COMMAND THE SERVO TO GO TO POSITION 100 AND TO 140 IN


STEPS OF 10
for(int desired_theta=100; desired_theta<=140; desired_theta+=10){
servo1.write(desired_theta);
delay(1000);
}

}
//*************************************************
void loop() {
}
//*************************************************

d) Blink the two LEDs in breathing mode using the PWM signal

Here, the LEDs should again blink in sequence, but the intensity of brightness of the two
LEDs should be increased from 0 to maximum and back to 0. Flash the inputs delivered
to the LEDs on the serial monitor.

Write your own sketch and perform the control task.

****

You might also like