2024-25-Spr-MS101-EE-Lab4-Arduino
2024-25-Spr-MS101-EE-Lab4-Arduino
February 2025
This experiment has two parts: part A is for familiarization with Arduino
board, its Integrated Development Environment (IDE) and software.
Part B is for controlling motors using Arduino boards.
In part 4A, we shall carry out 5 simple experiments using Arduino.
1 LED Blink experiment for Digital output – to be done before
coming to the lab to test your board and IDE installation.
2 LED fade experiment for Pulse Width Modulated outputs.
3 Switch reading (digital input) and serial output,
4 Reading voltage output from a potentiometer as an illustration of
analog input.
For this lab, we’ll use ready made example programs available in the
Arduino IDE with minimal modifications.
Done!
(Department of Electrical Engineering, IIT Bombay)
MS101 Makerspace Expt. 4: Arduino Familiarization and Motor
February
Control
2025 11 / 40
Expt. 4A-2 – Pulse Width Modulation: Fade
This is how I wired up all parts of expt. 4 on a breadboard, using a Nano
board.
if (brightness < 0) {
brightness = fd1;
fadeAmount = fd1;
}
// wait for 50 milliseconds per brightness change
delay(50);
(Department of Electrical Engineering, IIT Bombay)
MS101 Makerspace Expt. 4: Arduino Familiarization and Motor
February
Control
2025 16 / 40
Expt. 4A-2 – Pulse Width Modulation: Fade
Press and release the push button (or touch and remove the 5V
wire from the top of the 10KΩ resistor) and check that the digital
value read on pin 2 changes from ‘0’ to ‘1’ and back.
Call your TA and claim that you have learnt:
1 how to read digital input,
2 how to send data through the serial line, and
3 how to plot incoming data from Arduino on the laptop.
(The TA may be tempted to test whether you have actually learnt it)!
11 UNO/nano
10 board group of pins on the Arduino board.
10 K
9 A0
8
7
A1
A2 The breadboard compatible potentiometer
470
6 A3
5 A4 covers the nearby pins – so make a note of
LED
4 A5
3
Tx
Gnd the label on the group of 5 pins on the
Rx
breadboard to which each of its terminals is
connected.
The LED connected to pin D9 through a (≈ 470)Ω resistor should still
be there. (If you removed these by mistake, connect these again as
shown).
Open the serial monitor. For this, click on the Tools tab and then
on the Serial Monitor choice. (You can also click on the icon at the
top right of the IDE). This will open a window below the edit
window to show serial communication between the Laptop and
Arduino.
Adjust the position of the potentiometer by rotating the slider using
a small screw driver. Watch the intensity of the LED being
controlled by the position of the potentiometer.
Also see the sensor output values (ADC outputs with a 10 bit
range and the mapped values to 8 bit ranges) being sent through
the serial port. These appear in the serial monitor. You can also
use the plotter function to see how these change when you turn
the potentiometer slider.
Show the operation to your TA and explain how it all works. Get your
notebook signed for observations of experiment 4A-4.
(Department of Electrical Engineering, IIT Bombay)
MS101 Makerspace Expt. 4: Arduino Familiarization and Motor
February
Control
2025 24 / 40
Motor Speed Control with PWM using an Arduino
Board
In this part of the experiment, we’ll learn how to control the speed of a
motor using an Arduino board.
We need a motor driver card and battery operated (BO) motors for this
part.
First, we have to assemble the set up. The various steps for this are:
Soldering a capacitor and wires to the Battery Operated (BO)
motor.
Mounting the motor on a stage and fixing an encoder disk on its
axis.
Mounting a reflective sensor with an LED and photo-diode which
gives digital outputs of ‘1’/‘0’ as the encoder disk rotates.
Connecting the motor to its driver and connecting the driver to
Arduino Nano card.
(Department of Electrical Engineering, IIT Bombay)
MS101 Makerspace Expt. 4: Arduino Familiarization and Motor
February
Control
2025 25 / 40
Soldering a Capacitor across BO Motor Terminals
After making all the connections, have these checked by your TA.
We’ll use 12 V power from the Keithley power supply (Channel 1 or 2).
Set the voltage on the selected channel to 12 V.
Program Iset to 1A on this channel and turn ON the output.
The power LED on motor driver should glow.
If it does not, turn everything off and re-check your connections.
When you have stopped jumping for joy, call the TA and show your
success to him/her. Have your lab book signed that your motor
connections are right and the motor is rotating.
Try various positive and negative values of PWM.
(Absolute value of PWM has to be ≤ 255).
For this you will have to edit the sketch, altering the value of pwmValue
near the end of the sketch every time, and re-uploading the binary to
Arduino.
After this, enter, compile and upload the second sketch given to you.
(sketch-expt4B-2.ino).
See the motor accelerate in one direction, decelerate, then accelerate
in the other direction and decelerate to idle condition.
See how this is accomplished in the code in the given sketch.