Computation Structures-
Arduino LAB
Dr Shola Usharani
Associate Professor, SCOPE
List of Components available in 207 & 506
1. Arduino UNO with Cable
2. Resistors
3. LED's
4. IR Sensor
5. Ultrasonic Sensor
6. Soil Moisture Sensor
7. DHT 11
8. LDR
9. Jumper wires (M-M, M-F, F-F)
10. Breadboard
11. Servo Motor
12. Bluetooth module
About Arduino
• It is Atmel 8-bit AVR
microcontroller
• Open-source and
extensible hardware
computing platform
• Low cost
• Cross-platform
• Simple and has clear
programming
environment
Arduino IDE
• To install the Arduino software, download this page:
[Link] and proceed with the
installation by allowing the driver installation process.
A Verify
B Upload
C New
D Open
E Save
F Serial Motor
Arduino IDE
Arduino Setup
Important functions
• analogRead(sensorPin); // Read
the analog value from sensor
• Void setup() • analogWrite(ledPin, outputValue);
• { ……} // generate PWM signal
• Void loop() • delay(NUMms);
• {…..} • delayMicroseconds(2) //pause the
• pinMode(Pin,Mode)//setting mode program execution for 2
to PIN microseconds (µs)
• digitalWrite(PIN_Number,HIGH/LO • pulseIn(echoPin, HIGH); //It
W) measures the time for which the
echoPin stays HIGH, in
• digitalRead(PIN_Number) microseconds
• [Link](BaudRate) • map(sensorValue, 0, 1023, 255, 0)
• [Link](“Text”+Data) or //mapping Decimal value to 8-bit
[Link](“Text”+Data) value
LED Interfacing
• Blink Built-in LED
• LED Interfacing
• Traffic Light simulation
Built In LED (Examples
from Arduino)
• void setup() {
• // put your setup code here, to run once:
• pinMode(LED_BUILTIN,OUTPUT);
• }
• void loop() {
• // put your main code here, to run repeatedly:
• digitalWrite(LED_BUILTIN,HIGH);
• delay(2000);
• digitalWrite(LED_BUILTIN,LOW);
• delay(2000);
• }
LED Interfacing
Code
• void setup() {
• // put your setup code here, to run once:
• pinMode(11,OUTPUT);
• }
• void loop() {
• // put your main code here, to run repeatedly:
• digitalWrite(11,HIGH);
• delay(6000);
• digitalWrite(11,LOW);
• delay(4000);
Traffic Light Simulation
• void loop() {
• // put your main code here, to run
Code repeatedly:
• digitalWrite(11,HIGH);
• void setup() { • delay(6000);
• // put your setup code here, to run • digitalWrite(11,LOW);
once: • delay(2000);
• pinMode(11,OUTPUT); • digitalWrite(10,HIGH);
• pinMode(10,OUTPUT); • delay(4000);
• pinMode(9,OUTPUT); • digitalWrite(10,LOW);
• } • delay(2000);
• digitalWrite(9,HIGH);
• delay(2000);
• digitalWrite(9,LOW);
• delay(2000);
IR Sensor
Circuit Diagram
• void loop(){
Circuit Diagram & Code • int sensorStatus = digitalRead(IRSensor); //
Set the GPIO as Input
• if (sensorStatus == 1) // Check if the pin high
• int IRSensor = 9; // connect IR sensor module or not
to Arduino pin D9
• { // if the pin is high turn off the onboard
• int LED = 13; // connect LED to Arduino pin 13 Led
• void setup(){ • digitalWrite(LED, LOW); // LED LOW
• [Link](115200); // Init Serial at 115200 • [Link]("Motion Ended!"); // print
Baud Rate. Motion Detected! on the serial monitor
• [Link]("Serial Working"); // Test to window
check if serial is working or not • delay(2000);
• pinMode(IRSensor, INPUT); // IR Sensor pin • }
INPUT
• else { //else turn on the onboard LED
• pinMode(LED, OUTPUT); // LED Pin Output
• digitalWrite(LED, HIGH); // LED High
• }
• [Link]("Motion Detected!"); // print
Motion Ended! on the serial monitor window
• delay(2000); } }
Ultrasonic Sensor
Circuit Diagram
Code • void loop() {
• // put your main code here, to run
repeatedly:
• const int trigPin = 4;
• delayMicroseconds(2);
• const int echoPin = 5; • digitalWrite(trigPin, HIGH);
• float duration; • delayMicroseconds(10);
• float distance; • digitalWrite(trigPin, LOW);
• duration = pulseIn(echoPin,
• void setup() { HIGH);
• // put your setup code here, to • distance = duration * 0.034 / 2;
run once: • [Link]("Distance: ");
• pinMode(trigPin, OUTPUT); • [Link](distance);
• [Link](" cm");
• pinMode(echoPin, INPUT);
• delay(1000); }
• [Link](9600);
•}
Soil Moisture
Circuit Diagram
Circuit Diagram & Code
#define ledPin 6 int readSensor() {
#define sensorPin A0 int sensorValue =
void setup() { analogRead(sensorPin); // Read the
analog value from sensor
[Link](9600);
int outputValue = map(sensorValue,
pinMode(ledPin, OUTPUT); 0, 1023, 255, 0); // map the 10-bit
digitalWrite(ledPin, LOW); data to 8-bit data
analogWrite(ledPin, outputValue);
} // generate PWM signal
void loop() { return outputValue; //
[Link]("Analog output: "); Return analog moisture value
[Link](readSensor()); }
delay(500);
Temperature Sensor Interfacing
Circuit Diagram
Installing DHT11 library by
Adafruit
• void loop()
• {
Code • sensors_event_t event; //creating an
• #include <Adafruit_Sensor.h> event to read data for temp &
• #include <DHT.h> Humidity
• #include <DHT_U.h> • [Link]().getEvent(&event);
• #define DHTTYPE DHT11 // DHT 11
• [Link](F("Temperature: "));
• #define DHTPIN 2
• DHT_Unified dht(DHTPIN, DHTTYPE); • [Link]([Link]);
• uint32_t delayMS; • [Link](F("°C"));
• void setup() {
• [Link]().getEvent(&event);
• [Link](9600);
• [Link](); //creating instance of DHT • [Link](F("Humidity: "));
library
• sensor_t sensor;
• [Link](event.relative_humidity);
• //delayMS = sensor.min_delay / 1000; • [Link](F("%"));
• } • delay(1000);
• }
References
• LED Blinking:
• [Link]
hr2fp4giZ1Y6MJ25_tmWITc7uy4KIeiAkWG4OlBE2zyCTMjPbGmMU8EWskMk2JSE__efdUJ3xRFvZ0
M2vJLB0hUMk5HOE2LIh0lYoQhkqi8VHGoz9929jVmtFQ7ktivkBytrPl89EzjvEpTWsDR0N162q3FY5r
MfOGvP-
aQ8xa_WGLQJn96vUiPujpyZ5FJfr_klrcrVALaCG8A&q=led+interfacing+with+arduino+circuit+diagra
m&sa=X&ved=2ahUKEwi1y_6ZhpyRAxUqV3ADHVxtMQkQtKgLegQIEBAB&biw=1272&bih=594&dp
r=1.5#fpstate=ive&vld=cid:08667c3e,vid:I0ZIrzoI61g,st:0
• UR Sensor :
• [Link]
• IR Sensor:
• [Link]
• Soil_moisture Sensor:
• [Link]
uno
• Temperature Sensor:
• [Link]
• LDR Interfacing
• [Link]
• Bluetooth module Interfacing with Arduino
• [Link]
b7f411
List of Experiments
1. Introduction to Arduino,
1. Built-in LED Blinking, LED Interfacing with Traffic light simulation
2. Home Automation using IR Sensor & LEDs
2. Sensor Interfacing
1. Soil Moisture Sensor Interfacing
2. Temperature Sensor Interfacing
3. Smart water planting
3. Actuator Interfacing
1. UR Sensor Interfacing
2. Servo motor Interfacing
3. Automatic Toll gate simulation
4. Others
1. Bluetooth Module interfacing with Arduino
LAB (After CAT-I)
• 8 labs
• Digital Logic (Pending)
• RegistersStudy of SR using basic gates , Study of D Flip-Flop, Des
• ing of Registers using D Flip FLop,
• Counters Study of JK Flip Flop and Design of Asynchronous /Synchronous counter using JK Flip Flop
• Arduino:
• LAB-I introduction o Arduino with LED & IR Interfacing
• LAB-II : Temperature & Soil Moisture sensor Interfacing
• LAB-III : UR & Servo Motor Interfacing
• LAB-IV(Bluetooth module )
• Open MP
• LAB-V (Open MP)
• Assignment
• Midterm
• FAT LAB