Upload
jonadri-bundo
View
53
Download
0
Tags:
Embed Size (px)
Citation preview
What is Arduino
• A microcontroller board, contains on-board power supply, usb port to communicate with pc and an Atmel microcontroller chip.
• It simplify the proces of creating any control system by providing the standard board that can be programmed and connected to the system without the need to any sophisticated PCB design.
• An OPEN-SOURCE hardware.
Ultrasonic sensor
It is a sensor that work on a principle similar to radar, which evaulate attributes of a target by interpreting the echoes from radio or sound waves respectively.
Using the code below we can read from Arduino the distance of different objects
• int echo=9;
• int trig= 10;
• int distance;
void loop ()
• { • digitalWrite (trig, LOW); • delay (2); • digitalWrite (trig, HIGH); • delay (2); • digitalWrite (trig, LOW); • distance=pulseIn (echo,HIGH); • distance=distance/58; • • Serial.println(distance); • }
void setup ()
• {
• Serial.begin (9600);
• pinMode (echo,INPUT);
• pinMode (trig, OUTPUT);
• pinMode ( buzz, OUTPUT);
• }
Void loop ()
• void loop () • { • digitalWrite (trig, LOW); • delay (2); • digitalWrite (trig, HIGH); • delay (2); • digitalWrite (trig, LOW); • distance=pulseIn (echo,HIGH); • distance=distance/58; • if (distance < 7) •
You know what comes next:
The Code… • #include <CapacitiveSensor.h> • CapacitiveSensor capSensor =
CapacitiveSensor(4,2); • boolean ledstate=LOW; • int sensorValue; • int sensor;
• const int ledPin = 8;
• void setup() { • Serial.begin(9600); • pinMode(ledPin, OUTPUT); • } • void loop() { • sensorValue = capSensor.capacitiveSensor(30); • if(sensorValue > 0) { • ledstate =!ledstate; • }
• Serial.println(sensorValue); • • digitalWrite(ledPin,ledstate);
• delay(500); • }
And for desert…
Let’s transform all this to an alarm system using: Arduino, an ultrasonic sensor, a buzzer and a rgb led.
void setup ()
• { • Serial.begin(9600); • pinMode(ECHOPIN,INPUT); • pinMode(TRIGPIN,OUTPUT); • pinMode (buzz,OUTPUT); • pinMode (red,OUTPUT); • pinMode (green,OUTPUT); • pinMode (blue, OUTPUT); • }
void loop ()
• { • digitalWrite (buzz,LOW); • digitalWrite (red,LOW); • digitalWrite (green,LOW); • digitalWrite (blue,LOW); • digitalWrite(TRIGPIN,LOW); • delayMicroseconds(2); • digitalWrite(TRIGPIN,HIGH); • delayMicroseconds(2); • digitalWrite(TRIGPIN,LOW);
• int distance=pulseIn(ECHOPIN,HIGH); • distance=distance/58; • if (distance>20) • { digitalWrite (green,HIGH); • digitalWrite (buzz,LOW); • } • else if (distance>10 && distance<20) • { • digitalWrite (green, LOW); • digitalWrite ( blue,HIGH); • digitalWrite (buzz,LOW); • }