Download Hardware Required

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Oscilloscope history wikipedia , lookup

Multimeter wikipedia , lookup

Phase-locked loop wikipedia , lookup

Integrating ADC wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Power electronics wikipedia , lookup

Wien bridge oscillator wikipedia , lookup

CMOS wikipedia , lookup

LCD television wikipedia , lookup

Operational amplifier wikipedia , lookup

Transistor–transistor logic wikipedia , lookup

Lego Mindstorms wikipedia , lookup

Valve RF amplifier wikipedia , lookup

Current mirror wikipedia , lookup

Resistive opto-isolator wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Schmitt trigger wikipedia , lookup

Trionic T5.5 wikipedia , lookup

Rectiverter wikipedia , lookup

Charlieplexing wikipedia , lookup

Opto-isolator wikipedia , lookup

Transcript
TWO DAY HANDS ON ARDUINO WORKSHOP
BMS COLLEGE OF ENGINEERING
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Workshop Content
Sl.No
1
Content
IoT Overview
1. a. Definition of IoT and WSN background
b. Applications and industry verticals
c. Architecture overview
d. Prototyping platforms and which one to choose
2
3
4
Getting Started with Arduino
Introduction to Arduino Platform &Software
GPIO Interfacing
a. LED Blinking
b. Traffic Controller
5
ADC
Understand digital input and output
a. Activate LEDs using pushbuttons
b. Control brightness of led using potentiometer
LCD
6
7
8
9
Sensor Interfacing
a.Temperature
Creating temperature-Logging device
b. Moisture
c. Photo
Interface an LDR to sense ambient light intensity
d. Proximity
e. Motion
Relay interfacing
Ethernet
a. Creating Arduino Tweeter
10
11
12
13
14
15
Build your own Arduino Project
Pg.No
Aim
Turns on an LED on for one second, then off for one second, repeatedly
Hardware Required


Arduino Board
LEDs
Circuit Diagram
Code
// Pin 13 has an LED connected on most Arduino boards
int led = 13;
// the setup routine runs once when you press reset:
void setup()
{
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH);
// turn the LED on (HIGH is the voltage
level)
delay(1000);
// wait for a second
digitalWrite(led, LOW);
// turn the LED off by making the
voltage LOW
delay(1000);
}
// wait for a second
Aim
Traffic Signal Simulation
Hardware Required




Arduino Board
LEDs
Resistors – 10 K
Bread board
Circuit Diagram
Code
// defining variables so that we can address the lights by name rather than a number
int red = 13;
int yellow = 12;
int green = 11;
// add the setup function, where’ll we define the red, yellow and green LEDs to be output
mode
void setup()
{
pinMode(red,OUTPUT);
pinMode(yellow,OUTPUT);
pinMode(green,OUTPUT);
}
void loop()
{
changeLights();
delay(15000);
}
void changeLights(){
// green off, yellow for 3 seconds
digitalWrite(green,HIGH);
digitalWrite(yellow,LOW);
delay(3000);
// turn off yellow, then turn red on for 5 seconds
digitalWrite(yellow,LOW);
digitalWrite(red,HIGH);
delay(5000);
// red and yellow on for 2 seconds (red is already on though)
digitalWrite(yellow,HIGH);
delay(2000);
// turn off red and yellow, then turn on green
digitalWrite(yellow,LOW);
digitalWrite(red,LOW);
digitalWrite(green,HIGH);
}
Aim
Push button to control LED (Digital Communication)
Hardware Required




Arduino Board
momentary button or switch
10K ohm resistor
Breadboard
Circuit Diagram
Code
const int buttonPin = 2;
const int ledPin = 13;
// the number of the pushbutton pin
// the number of the LED pin
// variables will change:
int buttonState = 0;
status
// variable for reading the pushbutton
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Aim
Control brightness of led using potentiometer (Analog Communication)
Hardware Required


Arduino Board
Potentiometer
By turning the shaft of the potentiometer, you change the amount of resistance on either side
of the wiper which is connected to the center pin of the potentiometer. This changes the
voltage at the center pin. When the resistance between the center and the side connected to 5
volts is close to zero (and the resistance on the other side is close to 10 kilohms), the voltage
at the center pin nears 5 volts. When the resistances are reversed, the voltage at the center pin
nears 0 volts, or ground. This voltage is the analog voltage that you're reading as an input.
The Arduino has a circuit inside called an analog-to-digital converter that reads this changing
voltage and converts it to a number between 0 and 1023. When the shaft is turned all the way
in one direction, there are 0 volts going to the pin, and the input value is 0. When the shaft is
turned all the way in the opposite direction, there are 5 volts going to the pin and the input
value is 1023. In between,analogRead() returns a number between 0 and 1023 that is
proportional to the amount of voltage being applied to the pin.
Circuit Diagram
Code
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a
voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}
Aim
Handling LCD
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("Dr. Kayarvizhy");
lcd.setCursor(0,1);
lcd.print("Press Key:");
}
void loop() {
int x;
x = analogRead (0);
lcd.setCursor(10,1);
if (x < 60) {
lcd.print ("Right ");
}
else if (x < 200) {
lcd.print ("Up ");
}
else if (x < 400){
lcd.print ("Down ");
}
else if (x < 600){
lcd.print ("Left ");
}
else if (x < 800){
lcd.print ("Select");
}
}
Aim
Read the temperature and print it in serial port
Hardware Required


Arduino Board
Temperature Sensor (LM35 temperature sensor)
Circuit Diagram
Code
int outputpin= 0;
//this sets the ground pin to LOW and the input voltage pin to high
void setup()
{
Serial.begin(9600);
}
//main loop
void loop()
{
int rawvoltage= analogRead(outputpin);
float millivolts= (rawvoltage/1024.0) * 5000;
float celsius= millivolts/10;
Serial.print(celsius);
Serial.print(" degrees Celsius, ");
Serial.print((celsius * 9)/5 + 32);
Serial.println(" degrees Fahrenheit");
delay(1000);
}
Aim
Reading the state of a photo resistor
Hardware Required




Arduino Board
Photocell
10K ohm resistor
Bread board
Circuit Diagram
Code
const int sensorMin = 0;
experiment
const int sensorMax = 600;
experiment
// sensor minimum, discovered through
// sensor maximum, discovered through
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// map the sensor range to a range of four options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
// do something different depending on the
// range value:
switch (range) {
case 0:
// your hand is on the sensor
Serial.println("dark");
break;
case 1:
// your hand is close to the sensor
Serial.println("dim");
break;
case 2:
// your hand is a few inches from the sensor
Serial.println("medium");
break;
case 3:
// your hand is nowhere near the sensor
Serial.println("bright");
break;
}
delay(1);
// delay in between reads for stability
}
Aim
Measuring the distance from obstacle ( Proximity sensor)
Hardware Required


HC-SR04 Ultrasonic Sensor
It is a very affordable proximity/distance sensor that has been used mainly for object
avoidance in various robotics projects
Arduino Board
Circuit Diagram
Code
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define LEDPin 13 // Onboard LED
int maximumRange = 200; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)
}
void loop() {
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
if (distance >= maximumRange || distance <= minimumRange){
/* Send a negative number to computer and Turn LED ON
to indicate "out of range" */
Serial.println("-1");
digitalWrite(LEDPin, HIGH);
}
else {
/* Send the distance to the computer using Serial protocol, and
turn LED OFF to indicate successful reading. */
Serial.println(distance);
digitalWrite(LEDPin, LOW);
}
//Delay 50ms before next reading.
delay(50);
}
Aim
Motion detection System
Hardware Requirement


Arduino Board
PIR Motion Sensor
Circuit Diagram
Code
//the time we give the sensor to calibrate (10-60 secs according to the
datasheet)
int calibrationTime = 30;
//the time when the sensor outputs a low impulse
long unsigned int lowIn;
//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int pirPin = 3;
int ledPin = 13;
//the digital pin connected to the PIR sensor's output
/////////////////////////////
//SETUP
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(pirPin, LOW);
//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}
////////////////////////////
//LOOP
void loop(){
if(digitalRead(pirPin) == HIGH){
digitalWrite(ledPin, HIGH);
if(lockLow){
//makes sure we wait for a transition to LOW before any further output is
made:
lockLow = false;
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW){
digitalWrite(ledPin, LOW); //the led visualizes the sensors output
pin state
if(takeLowTime){
lowIn = millis();
//save the time of the transition from
high to LOW
takeLowTime = false;
//make sure this is only done at the
start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
Serial.print("motion ended at ");
//output
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
}
}
}
Aim
To find the Moisture level in the sand
Hardware Requirement


Arduino Board
Moisture Sensor
Aim
Reverse Alarm System using Proximity Sensor
Hardware Requirement
 The HC-SR04 Ultrasonic Sensor
It is a very affordable proximity/distance sensor that has been used mainly for object avoidance in
various robotics projects . It essentially gives your Arduino eyes / spacial awareness and can prevent
your robot from crashing or falling off a table. It has also been used in turret applications, water level
sensing, and even as a parking sensor. This simple project will use the HC-SR04 sensor with an
Arduino and a Processing sketch to provide a neat little interactive display on your computer screen.
 Arduino Board
 Buzzer
Circuit Diagram
Code
#include <NewPing.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN
11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum
sensor distance is rated at 400-500cm.
simon::NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and
maximum distance.
int tonepin = 8;
int distance;
void setup() {
Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.
pinMode(tonepin,OUTPUT);
}
void loop() {
delay(500);
// Wait 50ms between pings (about 20 pings/sec). 29ms should be the
shortest delay between pings.
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
Serial.print("Ping: ");
distance=uS / US_ROUNDTRIP_CM;
Serial.print(distance); // Convert ping time to distance in cm and print result (0 = outside set distance
range)
Serial.println("cm");
if(distance >0 && distance <10)
{
Serial.print("Less Distance");
tone(tonepin,2000,1000);
}
if (distance > 10)
{
noTone(8);
}
}