0% found this document useful (0 votes)
47 views42 pages

Do It Yourself IoT

Uploaded by

pratapveer579
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views42 pages

Do It Yourself IoT

Uploaded by

pratapveer579
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Internet of Things

Dr. Sajal Saha


Adamas University
Internet of Things
Raspberry Pi Internet

Tag(ip address)
IOT Architecture
IoT Devices
Raspberry Pi, Arduino and Intel Galileo
Arduino Mega
Arduino Uno

Arduino Nano
Arduino Lilypad
Software environment
• Cross Compiler
• Debugger
• Simulator
• Programmer
Arduino consists of two microcontroller
Firmware
Two types of code executing on a simple
microcontroller:
1. Application code:
Executes the system's main functionality
We write this code
2. Firmware
Low-level code: supports the main
function
USB interface, power modes, reset. etc.
The distinction is a matter of perspective
Arduino IDE
Arduino shield
Color LCD shield:
Interface to display
• Add-on boards that interface with another I/O Device

device/IC
• Can be stacked directly on top of the
Synthesizer shield:
Arduino Generate music
Connect to speaker

• Libraries exist to make interfacing simple


• Open source hardware, but most can be
Ethernet shield:
purchased Interface to internet controller
Built web server and client

• Large variety of shields available


• Big advantage of the Arduino platform
Design Validation tool

Tincarcad
Ethernet Shield Library Example

connect(ipaddress, port number)


• Used by a client to establish a connection with a
int Ethernetclient::connect(IPAddress ip, uintl6 t port) {
if (_sock != MAX_SOCK_NUM)
return 0;
for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = socketstatus (1);
if (s == SNSR: :CLOSED || S == SnSR: :FIN WAIT || S == SnSR::CLOSE WAIT) {
_sock = i;
break;
}
}
Pins
• Pins are wires connected to the microcontroller
• Pins are the interface of the microcontroller
• Pin voltages are controlled by a sketch
• Pin voltages can be read by a sketch
Output Pins
• Output pins are controlled by the Arduino
• Voltage is determined by your sketch
• Other components can be controlled through outputs
Input Pins
• Input pins are controlled by other components
• Arduino reads the voltage on the pins Allows it to respond to events and data
Digital vs. Analog
Some pins are digital-only .
• Read digital input, write digital output .
• 0 volts or 5 volts
Some pins can be analog inputs
• Can read analog voltage on the pin
• Useful for analog sensors
• Analog-only pins are clearly labeled
• No pins can generate an analog output
Input/Output(I/O)
• These functions allow access to the pins void pinMode(pin, mode)
• Set a pin to act as either an input or an output
pin is the number of the pin
• 0- 13 for the digital pins
• AO - AS for the analog pins
• mode is the I/O mode the pin is set to
o INPUT, OUTPUT, or INPUT_PULLUP
o INPUT_PULLUP acts as input with reversed polarity
Digital Input/Output
Digital Input
int digitalRead(pin)
• Returns the state of an input pin
• Returns either LOW (0 volts) or HIGH (5 volts)
Example:
int pinval:
pinval = digitalRead(3)
• pinval is set to the state of digital pin 3
Digital Output
void digitalWrite(pin, value)
• Assigns the state of an output pin
• Assigns either LOW (0 volts) or HIGH (5 volts) Example:
digitalWrite(3. HIGH):
Digital pin 3 is set HIGH (5 volts)
Analog Input
int analogRead(pin) Returns the state of an analog input pin
• Returns an integer from 0 to 1023
• O for 0 volts, 1023 for 5 volts
Example:
int pinval;
pinval = analogRead(43):

Pin must be an analog pin


Example
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the
voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the
voltage LOW
delay(1000); // wait for a second
}
Arduino Serial Communication
• UART protocol used over the USB cable
• Initialize by using Serial.begin ()
• Serial.begin (speed) or Serial.begin (speed, config)
• speed is the baud rate
• config sets the data bits, parity, and stop bits
• Serial.begin (9600) Serial.begin (9600, SERIAL_8N1)
o 8 data, no parity, 1 stop
• Usually call Serial.begin () in the setup function

Strings are converted to ASCII and sent using UART Serial monitor interpret bytes
as ASCII
Arduino Mega example:
// Arduino Mega using all four of its
Serial ports
// (Serial, Serial1, Serial2, Serial3),
// with different baud rates:

void setup() {
Serial.begin(9600);
Serial1.begin(38400);
Serial2.begin(19200);
Serial3.begin(4800);

Serial.println("Hello Computer");
Serial1.println("Hello Serial 1");
Serial2.println("Hello Serial 2");
Serial3.println("Hello Serial 3");
}
void loop() {}
Fritzing
• It is free to use (although a donation is
appreciated).
• It is simple and intuitive.
• Fritzing includes many libraries of
components from popular suppliers
such as Adafruit, Sparkfun, and
Snootlabs.
• It is suitable for Arduino, Raspberry Pi,
Beaglebone, and Spark Core projects.
• Fritzing is an integrated printed circuit
board (PCB) production service. Or
export the files and use another service.
Breadboard view
Schematic view
PCB view
Idea

Breadboard Prototype

Simulation

PCB prototype

Product design

Manufacture
Resistor colour code

Black 0

Brown 1

Red 2

Orange 3

Yellow 4

Green 5 Multiplier
Digit 1 Tolerance
Digit 2
Blue 6

Violet 7

Gray 8

White 9

Gold 0.1
Silver 0.01
Assignment1
Your job is to install the Arduino IDE on your computer, compile the "Blink" example, upload the example to
the board, and ensure that the LED blinks. Turn in 2 screen shots of the Arduino IDE. The first screen shot
should show the "Done compiling" message & the byte number information in the message area. The second
screen shot should show the message area after successfully uploading the sketch.

void setup()
{
pinMode(13, OUTPUT);
}

void loop()
{
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(13, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
void setup()

Assignment 2 { pinMode(13, OUTPUT);


}
Write a program that causes the built-in LED void loop()
connected to pin 13 on the Arduino to blink,
alternating between fast blinks and slow blinks. The {
LED should blink 5 times quickly and then it should
blink 5 more times slowly. When blinking quickly, the for(int i=0;i<6;i++)
LED should have a 1 second period, so it should be
high for 0.5 seconds and low for 0.5 seconds. When {
blinking slowly, the LED should have a 4 second
period, so it should be high for 2 seconds and low for digitalWrite(13, HIGH);
2 seconds. The LED should continue to blink in this
alternating fashion for as long as the Arduino
delay(500);
receives power. If you do not have an Arduino, you digitalWrite(13, LOW);
can use the web-based Arduino simulator at
www.tinkercad.com. You will need to create an delay(500); }
account for free. There are instructional videos on
that website that will teach you how to use the for( int i=0;i<6;i++)
simulator.
{
digitalWrite(13,HIGH);
delay(2000);
digitalWrite(13,LOW);
delay(2000); } }
void setup()
{
Assignment3 pinMode(13, OUTPUT);
Serial.begin(9600);
while (!Serial);
Serial.println("Input 1 to Turn LED on and 0 to off");
Write a program that allows the }
user to control the LED void loop()
connected to pin 13 of the {
Arduino. When the program is if (Serial.available())
started, the LED should be off. {
The user should open the serial int state = Serial.parseInt();
monitor to communicate with if (state == 1)
the Arduino. If the user sends {
the character '1' through the digitalWrite(13, HIGH);
serial monitor then the LED Serial.println("Command completed LED turned ON");
should turn on. If the user sends }
the character '0' through the if (state == 0)
serial monitor then the LED {
should turn off. digitalWrite(13, LOW);
Serial.println("Command completed LED turned OFF");
}
}
}
Assignment 4
Pushbutton Digital input to blink LED
int buttonState=0;
void setup()
{
pinMode(2,INPUT);
pinMode(13, OUTPUT);
}

void loop()
{
//read the state of the pushbutton
buttonState=digitalRead(2);
if(buttonState==HIGH)
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
delay(10);
}
Assignment 5:Design a security Alarm using PIR sensor
Assignment 6:Alternate blink circuit
Assignment7: LED Chaser
Assignment 8: Visualizing Random number
generation
Assignment 9: Traffic Light
Design the schematic diagram of a traffic light system in
Tincarcad. Whare red, yellow and green light will blink
respectively after every 5 seconds. Write the code for the
same and show the output.
Assignment 10:Turn On LED via Web through ESP8266 with Arduino
ESP8266 HTML WEB SERVER.
Assignment 11: Design a PIR sensor based counter system
Assignment 12: Design an ultrasonic sensor based radar
Thank You
For any query
9477240461
[email protected]
Compile and Link
• avr-gcc is invoked to cross-compile the code
o Resulting code executes on AVR, not Intel
• Generates an object file (.o)
• avr-objcopy is invoked to change the format of the executable file
• A.hex file is generated from the .elf file

You might also like