GIRIJANANDA CHOWDHURY
INSTITUTE OF MANAGEMENT AND
TECHNOLOGY
4- Day online Workshop on
“Doing Projects Using Arduino”
Organised by
Department of Electrical Engineering, GIMT, Guwahati, Assam
DAY 01
Introduction and simple programming using LED
Introduction
Arduino was created for hobbyist and designers who wanted to create exciting projects
With microcontroller becoming cheaper, one requires minimum time to learn
microcontroller programming,
Students at different level can learn and create projects according to their levels using
microcontroller coding.
Before the advent of Arduino
After Arduino
What is Arduino?
Open-source electronic prototyping platform enabling users
to create interactive electronic objects.
Arduino designs, manufactures, and supports electronic
devices and software, allowing people around the world to
easily access advanced technologies that interact with the
physical world. Our products are straightforward, simple,
and powerful, ready to satisfy users’ needs from students to
makers and all the way to professional developers.
Why Arduino
If you are a hobbyist or some one with a passion to create new things, innovate and do
real time projects, this is the right tool for you.
Know mode on projects using Arduino:
https://blog.arduino.cc/?_gl=1*8nclus*_ga*MjI0ODE0MzA5LjE2MDA0NTQ4MTk.*_ga_NEXN8
H46L5*MTY1ODEyOTc3OC4zLjEuMTY1ODEyOTkxNS42MA..
Arduino creators
Know more..
Arduino boards
Brief description
Arduino is a single board microcontroller which consists of Atmega328 microcontroller, I/O
circuits and a RAM.
The microcontroller on the Arduino board needs to be programmed via a USB cable.
The board can be powered through a USB connection with the computer or from a 7-12 V
battery or Adapter.
Once the program is uploaded, the board can be disconnected from the computer to
make the board work independently.
The Arduino basically consists of two components- hardware (blue or green coloured
board) and software (Where codes are written)
Hardware description
Hardware description
Installation process
Go to https://www.arduino.cc/
Go to software -→ Downloads →
A sneak-peek into Arduino Website
Go to https://www.arduino.cc/
The Arduino software
The Arduino software development environment is free to download from
www.Arduino.cc and requires no lengthy registration process.
It is a multi-platform environment i.e. it can run on windows, Macintosh and Linux
The core language used in Arduino development environment is the C computer
programming language.
C uses a procedural language syntax and that needs to be processed by a compiler to
convert high level code to machine level instructions.
To make the programming easy for the beginners, the Arduino team has developed many
standard Arduino libraries that provide simple set of functions to be used.
The Arduino software
The Arduino software development environment basically used to write, edit, compile and
upload your Arduino source code to your interface board.
The Arduino software, also called as the Integrated Development Environment (IDE) allow
us to write and easily upload the programs to our Arduino board.
In case of windows OS, after downloading the Arduino IDE from the website, you need
to decompress the downloaded folder to your computer desktop. Open the
decompressed folder and launch the exe file.
Writing codes in
IDE
The Arduino IDE
Exploring the Arduino IDE
Basic Programming with LED
Blinking LED
The code int
int
led_red=13; // Red LED is connected to pin no 13
led_blue=12; // blue led is connected to pin no 12
int led_yellow=8; //yellow led is connected to pin no 8
int i; // a variable
void setup() {
// put your setup code here, to run once:
pinMode(led_red, OUTPUT);
pinMode(led_blue, OUTPUT);
pinMode(led_yellow, OUTPUT);
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(led_red, HIGH);
delay(100);
digitalWrite(led_blue, HIGH);
delay(100);
digitalWrite(led_yellow, HIGH);
delay(100);
digitalWrite(led_red, LOW);
digitalWrite(led_blue, LOW);
digitalWrite(led_yellow, LOW);
delay(100);
}
Controlling LED using push button
int led_red=13; // Red LED is connected to pin no 13
int led_blue=12; // blue led is connected to pin no 12
The code int
int
int
led_yellow=8; //yellow led is connected to pin no 8
switch_pin=3; // switch is connected to pin no 3
start=0; // variable used to read the state of switch
void setup() {
// put your setup code here, to run once:
pinMode(led_red, OUTPUT);
pinMode(led_blue, OUTPUT);
pinMode(led_yellow, OUTPUT);
pinMode(start,INPUT);
void loop() {
// put your main code here, to run repeatedly:
start=digitalRead(switch_pin);
if (start==HIGH)
{
digitalWrite(led_red, HIGH);
delay(100);
digitalWrite(led_blue, HIGH);
delay(100);
digitalWrite(led_yellow, HIGH);
delay(100);
digitalWrite(led_red, LOW);
digitalWrite(led_blue, LOW);
digitalWrite(led_yellow, LOW);
delay(100);
}
else
{
digitalWrite(led_red, LOW);
digitalWrite(led_blue, LOW);
digitalWrite(led_yellow, LOW);
}
}
Simple traffic light (one side only)
int led_red=13; // Red LED is connected to pin no 13
int led_blue=12; // blue led is connected to pin no 12
The code
int led_yellow=8; //yellow led is connected to pin no 8
int switch_pin1=3; // switch is connected to pin no 3
int start1=0; // variable used to read the state of switch 1
void setup() {
// put your setup code here, to run once:
pinMode(led_red, OUTPUT);
pinMode(led_blue, OUTPUT);
pinMode(led_yellow, OUTPUT);
pinMode(start1,INPUT);
void loop() {
// put your main code here, to run repeatedly:
start1=digitalRead(switch_pin1);
if (start1==HIGH)
{
digitalWrite(led_red, HIGH);
digitalWrite(led_blue, LOW);
digitalWrite(led_yellow, LOW);
delay(2000);
digitalWrite(led_blue, HIGH);
digitalWrite(led_red, LOW);
digitalWrite(led_yellow, LOW);
delay(1000);
digitalWrite(led_blue, LOW);
digitalWrite(led_red, LOW);
digitalWrite(led_yellow, HIGH);
delay(3000);
else
{
digitalWrite(led_red, LOW);
digitalWrite(led_blue, LOW);
digitalWrite(led_yellow, LOW);
}
}
Day 2
Programming with POT, 7 segment display and LCD
LDR digital pin program
Liquid Crystal display (LCD)
LCD text scrolling left and right
// LCD PRINT IN 16 X 2 LCD
The code //scroll left and right
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD
interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 =
2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
lcd.print("This is a 4 day workshop on Doing Projects
using Arduino");
}
void loop() {
// put your main code here, to run repeatedly:
//lcd.setCursor(0,0);
//lcd.print("This is a 4 day workshop on");
//lcd.scrollDisplayLeft();
delay(1000);
//lcd.setCursor(0,1);
//lcd.print("Doing Projects using Arduino");
lcd.scrollDisplayRight();
delay(1000);
}
Program to read the position of a
potentiometer
𝑅2
𝑂𝑢𝑡𝑝𝑢𝑡 = × 𝑉𝑐𝑐
𝑅1 + 𝑅2
Since the resolution of Arduino is 10bit
Therefore, digital value is 210 = 1024
Therefore, 5 V = 1024
Or 1024 = 5V
Day 3
Programming LED Dot Matrix, Keypad and LCD with Keypad
The code
#include <Keypad.h> // include keypad libraries
String input; //variable to store the keypad characters
String password="10*C"; // set the password
const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {13,12,11,10};// Connect keypad ROW0, ROW1, ROW2
and ROW3 to these Arduino pins.
byte colPins[COLS] = {9,8,7,6};// Connect keypad COL0, COL1 and COL2
to these Arduino pins.
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS
);
int led1=5; // LED 1 will glow when pressed
int led2=4; //LED 2 will glow when pressed
int led3=3; //LED 2 will glow when pressed
int led4=2; //LED 2 will glow when pressed
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop() {
The code
char key=keypad.getKey();
if (key != NO_KEY)
{
input=input+key; // store the keypad character
}
if (input==password)
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
}
if (key =='1') // if any key is pressed
{
digitalWrite(led1, HIGH);
}
else if (key == '0') // if any key is pressed
{
digitalWrite(led2, HIGH);
}
else if (key == '*') // if any key is pressed
{
digitalWrite(led3, HIGH);
}
else if (key == 'C') // if any key is pressed
{
digitalWrite(led4, HIGH);
}
else
{
}
Password based Authentication
The code // Program to show application of keypad with LCD
// the 3rd row and 3rd column has been removed
#include <Keypad.h> // include keypad libraries
#include <LiquidCrystal.h>
String input; //variable to store the keypad characters
String password="12B0D4*"; // set the password
const byte ROWS = 3; // Four rows
const byte COLS = 3; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','A'},
{'4','5','B'},
{'*','0','D'}
};
byte rowPins[ROWS] = {12,10,9};// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = {8,7,6};// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const int rs = 13, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Doing Projects");
lcd.setCursor(0,1);
lcd.print("using Arduino");
delay(1000);
reset();
}
void loop() {
The code char key=keypad.getKey();
if (key != NO_KEY) // if any key is pressed
{
lcd.clear();
input=input+key; // store the keypad character
lcd.print("#######");
{
if(key=='*')
{
if (input==password) // if password is correct
{
lcd.setCursor(0,0);
lcd.print("CORRECT PASSWORD");
delay(1000);
lcd.setCursor(0,1);
lcd.print("PROCEED");
}
else // if password is not correct
{
lcd.setCursor(0,0);
lcd.print("WRONG PASSWORD");
delay(1000);
lcd.setCursor(0,1);
lcd.print("TRY AGAIN");
delay(1000);
input="";
reset();
}
}
}
}
}
void reset()
{
lcd.clear();
lcd.print("ENTER PASSWORD");
}
Day 4
ESP8266 Wifi Module and Mini Project (Home Automation)
ESP8266 Wi-Fi module
The code
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
void setup() {
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// Print WiFi MAC address
printMacAddress();
}
void loop()
{
// scan for existing networks
Serial.println();
Serial.println("Scanning available networks...");
listNetworks();
delay(10000);
}
void printMacAddress()
{
// get your MAC address
byte mac[6];
WiFi.macAddress(mac);
The code // print MAC address
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
Serial.print("MAC address: ");
Serial.println(buf);
}
void listNetworks()
{
// scan for nearby networks
int numSsid = WiFi.scanNetworks();
if (numSsid == -1) {
Serial.println("Couldn't get a wifi connection");
while (true);
}
// print the list of networks seen
Serial.print("Number of available networks:");
Serial.println(numSsid);
// print the network number and name for each network found
for (int thisNet = 0; thisNet < numSsid; thisNet++) {
Serial.print(thisNet);
Serial.print(") ");
Serial.print(WiFi.SSID(thisNet));
Serial.print("\tSignal: ");
Serial.print(WiFi.RSSI(thisNet));
Serial.print(" dBm");
Serial.print("\tEncryption: ");
printEncryptionType(WiFi.encryptionType(thisNet));
}
}
void printEncryptionType(int thisType) {
The code
// read the encryption type and print out the name
switch (thisType) {
case ENC_TYPE_WEP:
Serial.print("WEP");
break;
case ENC_TYPE_WPA_PSK:
Serial.print("WPA_PSK");
break;
case ENC_TYPE_WPA2_PSK:
Serial.print("WPA2_PSK");
break;
case ENC_TYPE_WPA_WPA2_PSK:
Serial.print("WPA_WPA2_PSK");
break;
case ENC_TYPE_NONE:
Serial.print("None");
break;
}
Serial.println();
}
Project Demonstration
Transformer oil Testing device using Arduino
The Device
Figure 1: Model (Top view) Figure 2: Model (Side view)
Figure 3: Pure oil sample Figure 4: Impure oil sample (Grade1) Figure 5: Impure oil sample (Grade2)
Figure 4.5: Impure oil sample Figure 4.4: Pure oil sample with Figure 4.6: Impure oil sample
(Grade1) mixed with water water (Grade2) with water
Connect with us
Click the icons to follow Dept. of EE