ATL Arduino Homework Activity Workbook - Prof. Dattaraj Vidyasagar Vidyasagar Academy
ATL Arduino Homework Activity Workbook - Prof. Dattaraj Vidyasagar Vidyasagar Academy
ATL Arduino Homework Activity Workbook - Prof. Dattaraj Vidyasagar Vidyasagar Academy
32
ATL Arduino Homework Activity Workbook – Prof. Dattaraj Vidyasagar; Vidyasagar Academy, www.vsa.edu.in
ATL Arduino Activity Workbook
ATL Arduino Homework Activity Workbook – Prof. Dattaraj Vidyasagar; Vidyasagar Academy, www.vsa.edu.in
ATL Arduino Activity Workbook
Introduction to Arduino
1. Arduino is an open source platform for robotics
2. Uses ATMega328p microcontroller
3. Arduino UNO R3 is the clone of original Arduino UNO
4. Special Arduino programming language
5. Simplified form of C/C++ language
6. Simple programming language
7. Easy connections to make any circuit
8. Easy interface of sensors with Arduino
9. Compatible with AVR Programming…!
Connection Details
Features of Arduino
ATL Arduino Homework Activity Workbook – Prof. Dattaraj Vidyasagar; Vidyasagar Academy, www.vsa.edu.in
Vidyasagar Academy’s STEM Education Worksheet
These details are universally applicable to any type of Arduino like UNO, nano, Mega, etc. We can write
Arduino code in AVR style also.
Human Comments
/*
* Project of Servo Motor Control
* Date: 27 August, 2019;
* Vidyasagar Academy, Akola
*/
#include <Servo.h> // library file linked
All header files must be linked at the beginning of program, below the top comment. Examples are given below:
#include <LiquidCrystal.h>
#include <Servo.h>
Definition Section
Define all the connections and other details below Link Section, as given in following examples:
#define LED 13
#define PotPin A0
#define SS 1
Global Declaration
Keywords
Just remember these keyboards given below. They are required in different Arduino programming:
void, int, float, if, else, while, for, Servo, continue, long, short,
signed, unsigned, return, break, register, case, switch, double, char,
static, default, volatile, const,
Useful Functions
Functions in Arduino execute a particular action. There are lot of functions used in Arduino programming.
Some regularly required functions are given below.
void setup()
{
Write all commands here which you want to initialize at the beginning
of program. This function runs “once” only.
}
void setup()
{
pinMode(LED,OUTPUT);
pinMode(SS,INPUT);
pinMode(variable,MODE);
}
You can use “for” loop in void setup() function to rotate the assignments of pins, as follows:
int LEDPins[]={0,1,2,3,4,5,6,7};
void setup() {
for(int i=0;i<8;i++)
{
pinMode(LEDPins[i],OUTPUT);
}
}
This function is also known as infinite loop. Whatever actions you write in this loop, will be executed again and
again.
Void loop(){
Write all commands here to perform repeatedly
}
There are capital alphabets (A to Z) and small alphabets (a to z), 0 to 9 – in all ten digits and some special
characters. The list of special characters are given below –
A variable in ‘C’ is an identifier, whose value may change during program execution is called as memory
variable. There are rules about variable names, as follows:
Note: All the variables must be declared in the definition section of every program.
What is DataType?
Data type: The type of value stored in a variable is called as data type. In ‘C’, there are different types of
datatypes, as given below. In any program, the datatype declares the type of data that the variable can hold.
In this way, there are number of datatypes with different memory allocation.
Arduino UNO Dev. Board contains one built-in LED. It is connected to pin-13 internally. We shall write a
simple program to blink this LED. We shall also adjust the value in delay() function to blink this LED with
different time periods. Get ready with paper and pencil or your PC.
In-built LED
connected at pin-13
To write program for blinking 8 LEDs for above given circuit, you have to define 8 variables first.
Then you have to write 8 pinMode statements.
Then you have to write 8+8=16 digitalWrite commands to make the LEDs on/off.
This is sooooooo boring…!
int LED0=0;
int LED1=1;
int LED2=2;
int LED3=3;
int LED4=4;
int LED5=5;
int LED6=6;
int LED7=7;
void setup() {
pinMode(LED0, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
}
void loop() {
digitalWrite(LED0, HIGH);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, HIGH);
delay(1000);
digitalWrite(LED0, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
delay(1000);
}
Such types of functions are called as User Defined Functions (UDFs). They are NOT the default functions of
Arduino. The userDefined_Function() function can be used in the program as follows:
int LED0=0;
int LED1=1;
int LED2=2;
int LED3=3;
int LED4=4;
int LED5=5;
int LED6=6;
int LED7=7;
void allLEDs_ON()
{
digitalWrite(LED0, HIGH);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(LED6, HIGH);
digitalWrite(LED7, HIGH);
}
void allLEDs_OFF()
{
digitalWrite(LED0, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(LED6, LOW);
digitalWrite(LED7, LOW);
}
void setup()
{
pinMode(LED0, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
}
allLEDs_OFF()
delay(1000);
}
Note: Though the use of user defined functions is good, but still its boring. If we have to use the UDF many
times in a program, then UDFs are recommended. But if you want to use the UDF only once, in the program,
then this trick is still boring…!
This method is also called as Direct Port Register Addressing Technique. In this technique we use the
programming methodology of AVR microcontroller programming. So to understand this method, we shall see
the basics of AVR programming first. Remember that C & C++ commands are used in AVR.
PC4
PC3
PC2
PC1
PC0
Vcc
PB5
PB4
PB3
PB2
PB1
28
27
26
25
24
23
22
21
20
19
18
17
16
15
A T M e g a 3 2 8 p
10
12
13
14
11
1
9
Gnd
PD0
PD2
PB7
PD7
PB0
RST
PD1
PD3
PD4
Vcc
PB6
PD5
PD6
Unlike Arduino, in AVR programming technique, there are I/O PORTs instead of pins. The Arduino UNO uses
ATMega328p microcontroller. It has 3 I/O PORTs i.e. INPUT-OUTPUT Ports: PORTB, PORTC & PORTD
1. PORTB (8-pins): PB7 to PB0. First pin is PB7 and last pin is PB0 i.e. PB7 is at MSB and PB0 at LSB.
2. PORTC (6-pins): PC5 to PC0. First pin is PC5 and last pin is PC0 i.e. PC5 is at MSB and PC0 at LSB.
3. PORTD (8-pins): PD7 to PD0. First pin is PD7 and last pin is PD0 i.e. PD7 is at MSB and PD0 at LSB.
The Arduino can be coded using Direct PORT Register Addressing. For that we have to understand the
architecture of Arduino in terms of PORTs, as shown below:
void setup() {
DDRD=0b11111111; // all pins of PORTD defined as output pins
}
void loop() {
PORTD=0b00000000; // LOW signal is sent on all pins of PORTD
delay(1000);
PORTD=0b11111111; // HIGH signal is sent on all pins of PORTD
delay(1000);
}
Exercise
1. Write different codes to produce decorative effects in 8 LEDs array using DPRA.
2. At least 5 different codes must be written by the student.
A servo motor is a device that contains an encoder which converts the mechanical motion into digital pulses.
Servo motor works on the PWM (Pulse Width Modulation) principle, which means its angle of rotation, is
controlled by the duration of pulse applied to its control PIN. Basically servo motor is made up of
DC motor which is controlled by a variable resistor (potentiometer) and some gears.
It is recommended to connect servo motor to PWM pin of Arduino. But it is not mandatory. You can connect it
to other digital pins also.
Following circuit shows a simple connection of servo motor to pin-0 of Arduino and its positive (+) negative (-)
terminals are connected to 5V and Gnd terminals of Arduino. Use the give code to control the servo motor.
The Code
#include <Servo.h>
Servo motor1,motor2,motor3; // creating servo objects
void setup(){
motor1.attach(3);
motor2.attach(5);
motor3.attach(6);}
void loop(){
motor1.write(0);
delay(1000);
motor2.write(90);
delay(1000);
motor3.write(180);}
Mapping in Arduino converts one range into another (ADC). It uses following syntax for the same.
We can control the servo motor using simple potentiometer. When we rotate the pot the servo motor rotates
proportionally. Such type of arrangement is typically used in manual robotic arm controlling systems like in
surgical robots, industrial robots.
The Code
#include <Servo.h>
Servo i; // create servo object
int potpin=0;
int pot_voltage;
void setup() {
i.attach(9);
}
void loop() {
pot_voltage=analogRead(potpin);
pot_voltage=map(pot_voltage,0,1023,0,255); // i.e. 210 = 1024 28 = 256
i.write(pot_voltage);
delay(15);
}
int position=0;
void loop()
{
for(position=0; position<=180; position++) {
i.write(position);
delay(50);
}
delay(1000);
Note: with this code, CCTV camera will rotate from 0 – 180 and then 180 – 0 to watch entire area.
Many students find it difficult to use LCD display with Arduino due to large number of wire connections. We
shall see simple & effective method of using LCD display with Arduino.
void loop() {
lcd.clear(); // clears previous message on the display
lcd.setCursor(0,0); // first row selected
lcd.print(“*VSAGAR ACADEMY*”);
delay(3000);
lcd.setCursor(0,1); // second row
lcd.print(“ www.vsagar.org “);
delay(3000);
void loop() {
for (int positionCounter = 0; positionCounter < 13; positionCounter++)
{
lcd.scrollDisplayLeft(); // or use lcd.scrollDisplayRight();
delay(400);
}
When we control servo motor through a pot, it is necessary to know the position of the servo for accurate
control. To obtain the correct position, we can use this code. To read the correct position of servo, we use the
default function: servo.read(); as given below.
#include <Servo.h>
#include <LiquidCrystal.h>
const int rs=2, en=3, d4=4, d5=5, d6=6, d7=7;
void setup() {
i.attach(9); // servo motor attached to pin-9
lcd.begin(16,2);
}
void loop() {
value=analogRead(potpin); // read pot voltage
// and store in “value” variable
value=map(value, 0, 1023, 0, 255); // ADC process
i.write(value); // controlling servo as per the value of potpin
i.read();
lcd.clear();
lcd.print(i.read());
delay(15); // perceptible pause
}
Note: this function is useful in CCTV cameras to read the correct positioning or direction of camera.
____________________________________
Problem Statement
Write an embedded C Program to measure the real time temperature using NTC Thermister.
Objectives
Description
In this project, the thermister of 10kΩ/25C and a resistor of 10kΩ form a potential divider. The centre point of
this circuit connected to analog input pin A0, as shown below.
10kΩ
The voltage across 10kΩ resistor, which is connected to pin A0 is given by:
10𝑘Ω 10𝑘Ω×5V
𝑉=( ) × 5V ∴ 10𝑘Ω + 𝑅𝑇ℎ =
10𝑘Ω+𝑅𝑇ℎ V
10𝑘Ω × 5V
∴ 𝑅𝑇ℎ = − 10𝑘Ω
V
This voltage is analog voltage. It is converted into digital by using the ADC process. Its formula is given by:
𝐴𝐷𝐶 = 𝑎𝑛𝑎𝑙𝑜𝑔𝑅𝑒𝑎𝑑(𝑉)
The analogRead() function reads the value from A0. It’s a 10-bit analog to digital converter in Arduino
UNO. This means that it will map input voltages between 0 and the operating voltage of 5V into integer values
between 0 and 1023. For example, 5V/ 1024 units = 4.9 mV per unit.
5V × ADC
Vo =
1023
1
𝑇𝑒𝑚𝑝𝑒𝑟𝑎𝑡𝑢𝑟𝑒 𝑖𝑛 𝐾𝑒𝑙𝑣𝑖𝑛 =
(𝐴 + (𝐵. log 𝑅𝑇ℎ ) + (𝐶. (log 𝑅𝑇ℎ )3))
Arduino UNO Dev. Board – 1, Breadboard – 1, Jumper wires, 10kΩ/25C thermister, 10kΩ resistor, LCD
display, data cable, PC/Laptop, etc.
The Code
#include <math.h>
#include <LiquidCrystal.h>
const int rs=2, en=3, d4=4, d5=5, d6=6, d7=7;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
}
void loop() {
int ADCvalue;
double Vo, RTh, Log_RTh, Temp;
Temp=(1/(0.001129148+(0.000234125*Log_RTh)+(0.0000000876741*Log_RTh*Log_RTh
*Log_RTh)));
delay(2000);
}
Problem Statement
Write an embedded C Program to measure the accurate distance between ultrasonic sensor and the object.
Objectives
Description
In this project we shall learn how to trigger and receive the echo signal of Ultrasonic sensor.
Required Material
Arduino UNO Dev. Board – 1, Breadboard – 1, LCD Display, Ultrasonic sensor, Jumper wires, servo motors,
data cable, PC/Laptop, measuring scale, etc.
Connection Diagram
#include <LiquidCrystal.h>
#define trigger 9 // trigger pin connected to pin-9
#define echo 10 // echo pin connected to pin-10
void setup() {
lcd.begin(16,2);
pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
}
void loop() {
lcd.clear(); // clear the LCD display first
// echo received
time=pulseIn(echo,HIGH);
lcd.setCursor(0,1);
lcd.print("Distance:");
lcd.print(distance/100); // distance in meter
lcd.print("m");
delay(1000);
}
Problem Statement
Write an embedded C Program to control relay switch and a high power bulb as per the DTMF signal received
in Arudino UNO dev. board. When a ‘1’ is pressed on mobile, the relay must be on and when ‘0’ or any other
switch is pressed, the relay must be off.
Objectives
Description
Here we use the DTMF sensor which has 4 outputs D3, D2, D1 and D0. These outputs are connected to Arduino
pins 8,9,10,11 respectively. The DTMF signal input is applied to this sensor through a good quality mobile
phone through its earphone socket. The relay controlling switch is connected to pin-0. The complete connection
diagram is given below.
Required Material
Arduino UNO Dev. Board – 1, Breadboard – 1, Jumper wires, Relay switch – 1, 60W/100W 230V bulb, data
cable, PC/Laptop, connecting wires for bulb, etc.
Connection Diagram
Make the necessary connections and with the respective pins of Arduino UNO Dev. Board as shown below:
The Code
Button D3 D2 D1 D0 Decimal
#define Relay_Sw 0
#define D3 8 0 1 0 1 0 10
#define D2 9 1 0 0 0 1 1
#define D1 10 2 0 0 1 0 2
#define D0 11
3 0 0 1 1 3
void setup() 4 0 1 0 0 4
{ 5 0 1 0 1 5
pinMode(D3,INPUT); 6 0 1 1 0 6
pinMode(D2,INPUT);
pinMode(D1,INPUT); 7 0 1 1 1 7
pinMode(D0,INPUT); 8 1 0 0 0 8
pinMode(Relay_Sw,OUTPUT); 9 1 0 0 1 9
}
* 1 0 1 1 11
void loop() # 1 1 0 0 12
{
// when '1' is pressed on mobile
if(!(digitalRead(D3)) && !(digitalRead(D2)) && !(digitalRead(D1)) &&
(digitalRead(D0)))
{
digitalWrite(Relay_Sw,HIGH); // relay switch is ON
}
1) Write an embedded C Program to control 4 different electrical appliances using Arduino UNO with
individual on/off system with the help of DTMF signals.
2) Write an embedded C Program to control 4 different electrical appliances using Arduino UNO with
simultaneous on/off system, with the help of DTMF signals.
Problem Statement
Write an embedded C Program to control an LED by the signal of sound sensor. The sound sensor receives
sharp sound. When it receives sharp sound, its output either becomes 1/0 and then within a short time 0/1.
Objectives
Description
In this project, the output of sound sensor is connected to pin-0 of Arduino. When the sensor receives sharp
sound its output becomes 0 (in some type of sound sensors its output becomes 1). This output remains for a very
short time. When the sound stops, the output of the sensor becomes 1. Now we have to use this property of the
sound sensor to control the in-built LED at pin-13 of the Arduino Dev. Board.
Required Material
Arduino UNO Dev. Board – 1, Breadboard – 1, Jumper wires, Sound Sensor – 1, LED – 1, resistor 330Ω – 1,
data cable, PC/Laptop, connecting wires, etc.
Connection Diagram
Make the necessary connections and with the respective pins of Arduino UNO Dev. Board as shown below:
void setup()
{
pinMode(SS,INPUT);
pinMode(LED,OUTPUT);
}
void loop()
{
if(digitalRead(SS)) // if sensor output becomes ‘0’ with sharp sound
{
digitalWrite(LED,HIGH); // LED becomes ON
delay(5000);
}
else
digitalWrite(LED,LOW); // otherwise the LED is OFF
}
1) Write an embedded C Program to control two LEDs such that when one clap is produced, the first LED
glows. When two claps are produced one after another quickly, the second LED glows. When three
claps are produced one after another quickly, both LEDs become OFF.
2) Connect LCD display in this project count the number claps produced during a time of say 1 minute.
Display the count on the LCD display.
Problem Statement
With the help of serial monitor and plotter in Arduino Software, we can actually visualise the real time changes
in our program. Write a program to study the serial monitor and plotter given in Arduino Software.
Objectives
Description
In this project, we shall connect a pot to analog pin-0 of Arduino UNO. When we shall rotate this pot, its
voltage will change proportionally. With the help of mapping (in the form of a formula:
writeValue=(255.0/1023.0)*readValue;) we shall convert this analog value into proportional
digital signal. Then we shall write this calculated value on the LED to control its brightness and also observe
this activity on Serial Monitor/Plotter.
Required Material
Arduino UNO Dev. Board – 1, Breadboard – 1, Jumper wires, Sound Sensor – 1, LED – 1, Pot 10kΩ – 1, data
cable, PC/Laptop, connecting wires, etc. (any value of pot from 1kΩ to 1MΩ can be used).
Connection Diagram
Make the necessary connections and with the respective pins of Arduino UNO Dev. Board as shown below:
www.vsagar.org
www.vsagar.org
void setup()
{
pinMode(potPin,INPUT);
pinMode(LED,OUTPUT);
Serial.begin(9600); // turn on Serial Port
}
void loop()
{
readValue=analogRead(potPin); // read pot voltage
writeValue=(255.0/1023.0)*readValue; // calculate write value for LED
analogWrite(LED,writeValue); // write to the LED
Serial.print("Writing value: "); // print values on serial monitor
Serial.println(writeValue);
}
In this code, simple linear relationship is used and it allows us to use the skills we have learned in math class.
The following graph explains the relationship:
𝑦2 − 𝑦1 = 𝑚. (𝑥2 − 𝑥1 )
255
∴ 𝑦2 − 0 = . (𝑥2 − 0)
1023
(0,0)
255 1023
i.e. 𝑦2 = ( ). 𝑥2 analogRead values
1023
255
𝑤𝑟𝑖𝑡𝑒𝑣𝑎𝑙𝑢𝑒 = ( ) . 𝑅𝑒𝑎𝑑𝑉𝑎𝑙𝑢𝑒
1023
1) Can you control the rotational angle of servo using this code? Why?
2) Write a program to control the brightness of two LEDs such that when brightness of one LED increases
the brightness of the other will decrease proportionately.
Problem Statement
Write an embedded C Program to control single LED with the help of a switch. The LED must remain ON when
the switch is pressed once & released. When the switch is pressed again the LED must be OFF and remain OFF
till again the switch is pressed.
Objectives
Description
We connect one RED LED to the Arduino Dev. Board with a simple push-to-on type switch. The switch is
connected to a pull-up resistor of 2.2kΩ to avoid accidental triggering of the LED. The other resistor of 330Ω is
used to limit the current flowing through the LED.
Required Material
Arduino UNO Dev. Board – 1, Breadboard – 1, Jumper wires – 6, LEDs – 1, Push-to-on Switch – 1, Resistors
330Ω – 1, 2.2kΩ – 1, data cable, PC/Laptop
Connection Diagram
Make the necessary connections on breadboard and with the respective pins of Arduino UNO Dev. Board as
shown below:
/*
* Program of Toggle Switch with LED
*/
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase this if LED flickers
void setup()
{
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
}
void loop()
{
reading = digitalRead(inPin);
if (reading == HIGH && previous == LOW && millis() - time > debounce)
{
if (state == HIGH)
{
state = LOW;
}
else
state = HIGH;
time = millis();
}
digitalWrite(outPin, state);
previous = reading;
}
1) Write an embedded C Program to control single LED such that when the switch is pressed & released
once, the LED should be ON and start blinking at 1 sec rate for 5 times. Then the LED should remain
ON until the switch is pressed again. Now the LED should be OFF and remain OFF until the switch is
pressed again to repeat the action.
2) Write an embedded C Program to control two LEDs with two different switches. The action for each
switch should be toggling action.
Problem Statement
Write the program of Bluetooth controlled DC motor and study the working of Bluetooth sensor.
Objectives
Precautions
1) You need to remove the RX and TX cables when you’re uploading the sketch to your Arduino.
2) Sometimes people connect the TX from the Bluetooth module to the TX of the Arduino – that is wrong
and it won’t work.
3) Make sure you connect it properly, the TX into RX and the RX into the TX.
Note: If the HC-05 Bluetooth Module asks for a password, enter the password as: 1234
Required Material
Arduino UNO Dev. Board – 1, Breadboard – 1, Jumper wires, DC Motor – 1, Bluetooth Module (HC-05),
Smartphone (any Android phone), data cable, PC/Laptop, connecting wires, etc.
Connection Diagram
Make the necessary connections and with the respective pins of Arduino UNO Dev. Board as shown below:
www.vsagar.org
www.vsagar.org
void setup() {
// sets the pins as outputs:
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
// sets enablePin high so that motor can turn on:
digitalWrite(enablePin, HIGH);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
//if some date is sent, reads it and saves in state
if(Serial.available() > 0){
state = Serial.read();
flag=0;
}
// if the state is '0' the DC motor will turn off
if (state == '0') {
digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
if(flag == 0){
Serial.println("Motor: off");
flag=1;
}
}
// if the state is '1' the motor will turn right
else if (state == '1') {
digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
digitalWrite(motorPin2, HIGH); // set pin 7 on L293D high
if(flag == 0){
Serial.println("Motor: right");
flag=1;
}
}
// if the state is '2' the motor will turn left
else if (state == '2') {
digitalWrite(motorPin1, HIGH); // set pin 2 on L293D high
digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
if(flag == 0){
Serial.println("Motor: left");
flag=1;
}
}
}
For the android communication with our Bluetooth module we have to use the BlueTerm app, It’s completely
free, so you just need to go to “Play store” and download it. Then you just need to connect your smarthphone
with the Bluetooth module. Remember to remove the TX and RX cables.
The 3 Commands
Following diagram is given to control 2 DC motors simultaneously. LM means left motor, RM means right
motor. You can connect 2 motors to control a 2-wheeled robot using Bluetooth sensor.
1) Learn the pinout of L293D motor driver IC and try to control 2 motors by doing modifications in the
code. Connect 2 motors to the IC after understanding its pinout.
2) Can we control a Servo motor using Bluetooth? Search for the solution.
Problem Statement
Write the program to display decimal digits from 0 – 9 on common cathode LED display.
Objectives
Required Material
Arduino UNO Dev. Board – 1, Breadboard – 1, Jumper wires, Resistor 100Ω – 1, Common cathode LED
display – 1, data cable, PC/Laptop, connecting wires, etc.
Connection Diagram
Make the necessary connections and with the respective pins of Arduino UNO Dev. Board as shown below:
void setup() {
DDRD=0b01111111; // PD6-PD0 output pins, PD7 not used
}
switch(i)
{
case 0:
PORTD=0b00111111; // '0' is displayed
break;
case 1:
PORTD=0b00000110; // '1' is displayed
break;
case 2:
PORTD=0b01011011; // '2' is displayed
break;
case 3:
PORTD=0b01001111; // '3' is displayed
break;
case 4:
PORTD=0b01100110; // '4' is displayed
break;
case 5:
PORTD=0b01101101; // '5' is displayed
break;
case 6:
PORTD=0b01111101; // '6' is displayed
break;
case 7:
PORTD=0b00100111; // '7' is displayed
break;
case 8:
PORTD=0b01111111; // '8' is displayed
break;
case 9:
PORTD=0b01101111; // '9' is displayed
break;
} // switch closed
} // “for” loop closed
} // void loop closed
Problem Statement
Write the program to control the speed of DC motor using PWM technique of servo motor.
Objectives
Required Material
Arduino UNO Dev. Board – 1, Breadboard – 1, Jumper wires, Resistor 100Ω – 1, Common cathode LED
display – 1, data cable, PC/Laptop, connecting wires, etc.
Connection Diagram
Make the necessary connections and with the respective pins of Arduino UNO Dev. Board as shown below:
void setup() {
DDRD=0b01111111; // PD6-PD0 output pins, PD7 not used
}
switch(i)
{
case 0:
PORTD=0b00111111; // '0' is displayed
break;
case 1:
PORTD=0b00000110; // '1' is displayed
break;
case 2:
PORTD=0b01011011; // '2' is displayed
break;
case 3:
PORTD=0b01001111; // '3' is displayed
break;
case 4:
PORTD=0b01100110; // '4' is displayed
break;
case 5:
PORTD=0b01101101; // '5' is displayed
break;
case 6:
PORTD=0b01111101; // '6' is displayed
break;
case 7:
PORTD=0b00100111; // '7' is displayed
break;
case 8:
PORTD=0b01111111; // '8' is displayed
break;
case 9:
PORTD=0b01101111; // '9' is displayed
break;
} // switch closed
} // “for” loop closed
} // void loop closed