0% found this document useful (0 votes)
69 views

ArduinoWeek2 Merged Merged

The document discusses experiment 5 which involves interfacing different sensors with an Arduino board, including a gas sensor, temperature sensor, and flex sensor. It provides the code, circuit diagrams, and results for interfacing each sensor. It also discusses introducing Arduino boards and describing their features.

Uploaded by

lakhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

ArduinoWeek2 Merged Merged

The document discusses experiment 5 which involves interfacing different sensors with an Arduino board, including a gas sensor, temperature sensor, and flex sensor. It provides the code, circuit diagrams, and results for interfacing each sensor. It also discusses introducing Arduino boards and describing their features.

Uploaded by

lakhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Week 5:

Experiment 5 (A)
Problem Statement: Write a program for Interfacing Gas sensor with arduino
Aim: To write a program for interfacing gas sensor with arduino.
Components Required: Arduino UNO, Breadboard, LED’s, Resistors, Jumper wires, MQ-2 ,gas
sensor, Buzzer
Program:
Source code:
int LED1 = 12;
int LED2 = 11;
int buzzer = 10;
int smokeA0 = A5;
int sensorThreshold = 400;
void setup() {
pinMode(LED1, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.print("Pin A0: ");
Serial.println(analogSensor);
if (analogSensor > sensorThreshold)
{
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
noTone(buzzer);
}
delay(100);
}
Output:

Circuit Diagram
Result:
The above program and circuit executed Successfully.
Week 5:
Experiment 5 (B)
Problem Statement: Write a program for Interfacing Temperature sensor with Arduino.
Aim: To write a program for interfacing temperature sensor with arduino
Components Required: 1 Arduino (the Keyestudio Uno is used in this example) ,1 LM35
Temperature Sensor, 3 Jumper Wires (Male to Male), 1 USB Data Cable (depends on the
Arduino), 1 breadboard
Program:
Source code:
void setup()
{
Serial.begin(9600);
}
void loop()
{
val = analogRead(tempPin);
float mv = ( val/1024.0)*5000;
float cel = mv/10;
float farh = (cel*9)/5 + 32;
Serial.print("TEMPRATURE = ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(1000);
Serial.print("TEMPRATURE = ");
Serial.print(farh);
Serial.print("*F");
Serial.println();
}
Output:
Circuit Diagram:
Result: The above program and circuit executed Successfully.
Week 5:
Experiment 5 (C)
Problem Statement: Write a program for Interfacing Flex Sensor
Aim: To write a program for interfacing flex sensor
Components Required:
Arduino UNO
Flex Sensor
TowerPro SG90 Servo Motor
10KΩ Resistor
LED
1KΩ Resistor
Mini Breadboard
Connecting wires
Program:
Source code:
int val;
int tempPin = 1;
const int flexPin = A0;
const int ledPin = 7;
void setup()
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}
void loop()
{
int flexValue;
flexValue = analogRead(flexPin);
Serial.print("sensor: ");
Serial.println(flexValue);
if(flexValue>890)
digitalWrite(ledPin,HIGH);
else
digitalWrite(ledPin,LOW);
delay(20);
}
Output:
Circuit Diagram:

Result: The above program and circuit executed Successfully.


WEEK – 1
Exp – b: Knowing more about Arduino board description.

 Arduino UNO Features and Techniques


WEEK - 1

Exp – c: Installation of Arduino UNO Software.

o Get the latest version from the Arduino UNO download page. You can choose
between the Installer (.exe) and the Zip packages. We suggest you use the first one
that installs directly everything you need to use the Arduino Software (IDE),
including the drivers. With the Zip package you need to install the drivers manually.
The Zip file is also useful if you want to create a portable installation.

o When the download finishes, proceed with the installation and please allow the
driver installation process when you get a warning from the operating system.

o Choose the components to install.

o Choose the installation directory.

o Installation in progress.

o The process will extract and install all the required files to execute properly the
Arduino Software (IDE)

o The text of the Arduino getting started guide is licensed under a Creative Commons
Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the
public domain
WEEK – 4
Exp – a: Introduction to Sensors.
Sensors are the backbone of any IoT deployment. They gather information and provide
software with sensory information it needs to achieve its full potential.
In addition, this post will go over considerations and decision-making for selecting sensors in
an IoT deployment. Often times, a single sensor is not the best implementation, a suite of
sensors can gather more data and even affect behaviour for other sensors. In many cases,
more than one sensor is necessary to perform the IoT deployment’s function.
Sensor Overview
Sensors are just as critical to every IoT application as the internet. Imagine Alexa or Google
Home without a microphone: it wouldn’t work. People wouldn’t be able to interact with the
device, or it would need some other kind of sensor such as a keyboard to obtain input from
a user. At the same time, the application dictates what kind of sensor is needed. A smart
home device without a microphone wouldn’t be useful. Interacting with the device through
voice allows for the user to be in many different places or partaking in another activity, like
cooking, while still using the device. The sensors in an IoT application are the eyes, ears, and
nose of software. Just like the organs that allow humans to interact with the world, sensors
are the way software detects the physical world and interacts with it.

As alluded to in the introduction, the Applications determines what kind of sensor should be
used. Trying to make a smart device to control the temperature? Use a thermometer. Trying
to detect people approaching your house? A motion sensor could be used, but then what if
a neighbourhood cat constantly trips it, or a porch bandit nabs a package? The motion
sensor wouldn’t give very actionable information. Whereas with a camera, the porch bandit
would be recorded and the algorithm behind the camera could exclude cats. On the flip
side, a camera controlling an automatic door would be overkill, and a motion sensor would
suffice.
The sensor is an important choice because it determines other important decisions in the
IoT stack. Cameras and microphones require lots of power and bandwidth to operate
effectively, should use Wi-Fi, and have large batteries or an outlet. As opposed to this,
motion sensors require little bandwidth and just standby power. GPS modules almost
always have to be battery-powered or have their functionality be severely limited.

Sensors are critical to IoT deployments, they are software’s equivalent to our eyes and ears.
In some cases, an IoT deployment is entirely limited by the sensors that are employed. The
IoT deployment dictates which sensor is the best to choose and then the sensor dictates
other hardware and software choices.
WEEK – 4
Exp – e: Implementing real time applications using sensors.
Introduction to Applications of Sensors
The sensor is an electronic device that measures physical attributes such as temperature, pressure,
distance, speed, torque, acceleration, etc., from equipment, appliances, machines and any other
systems. The sensor produces an electrical signal/optical signal using multiple technologies
proportional to the inputs. These Signals are either interpreted into a readable format or passed on
to the next stage for further processing. Sensors are broadly grouped into analog and digital sensors.
Analog sensors measure the exact value of physical variables, whereas digital sensors measure the
status. Applications classify sensors, Property sensed, Technology used and Systems where they are
deployed. Let’s analyse the applications of sensors in detail.

The ability of Sensors is to measure multi various data on the activities taking place within a system
that throws open plenty of use cases.

 The data measured by sensors can be used in:


 Operating the system efficiently.
 Monitoring the operations for any abnormalities.
 Controlling the operations.
 Utilizing the resources effectively.
 Making design changes to improve performance further.
 Enhancing Future product portfolio.

For example, the temperature sensor installed in a furnace measures the temperature data on a
periodic interval and sends it to the controlling unit. Intelligence built into the controlling unit can
switch off the furnace’s power supply if the temperature reaches above an upper limit.

Types of Sensors

1. Temperature Sensor

2. Proximity Sensor

3. Infrared Sensor

4. Light Sensor

5. Accelerometer sensor

6. Pressure Sensor

7. Ultrasonic Sensor

8. Touch Sensor

9. Smoke, Gas, Alcohol

10. Humidity Sensor

11. Flow and level sensor

12. Tilt Sensor

Sensors Measure the Following Properties

1. Distance
2. Temperature

3. Sound Intensity

4. Pressure

5. Proximity

6. Speed

7. Velocity

8. Torque

9. Tilt

10.Oxygen

11. Acceleration

12. RF Radiation

13.Altitude

14. Motion

15. Crushing

16. Conductivity

17. Flow

18. Level

19. Force

20. Hydro Carbon

21. Microwave Radiation and many more

Technologies Used by Sensors

1. Acoustic

2. Capacitive

3. Doppler

4. Electro Magnetic

5. Electro-Mechanical

6. Thermistor

7. Hall effect

8. Inductance

9. Infrared

10. Laser

11. Microwave
12. Optic

13. Radiofrequency

14. Ultrasonic

15. Giant Magento resistance (GMR)


WEEK – 1
Exp – a: Introduction to Internet of Things and Arduino UNO
Internet of Things (IoT) is the networking of physical objects that contain electronics
embedded within their architecture in order to communicate and sense interactions
amongst each other or with respect to the external environment. In the upcoming years,
IoT-based technology will offer advanced levels of services and practically change the way
people lead their daily lives. Advancements in medicine, power, gene therapies, agriculture,
smart cities, and smart homes are just a very few of the categorical examples where IoT is
strongly established.
Over 9 billion ‘Things’ (physical objects) are currently connected to the Internet, as of now.
In the near future, this number is expected to rise to a whopping 20 billion.
There are four main components used in IoT:
1. Low-power embedded systems: Less battery consumption, high performance are
the inverse factors that play a significant role during the design of electronic
systems.
2. Cloud computing: Data collected through IoT devices is massive and this data has to
be stored on a reliable storage server. This is where cloud computing comes into
play. The data is processed and learned, giving more room for us to discover where
things like electrical faults/errors are within the system.
3. Availability of big data: We know that IoT relies heavily on sensors, especially in
real-time. As these electronic devices spread throughout every field, their usage is
going to trigger a massive flux of big data.
4. Networking connection: In order to communicate, internet connectivity is a must
where each physical object is represented by an IP address. However, there are only
a limited number of addresses available according to the IP naming. Due to the
growing number of devices, this naming system will not be feasible anymore.
Therefore, researchers are looking for another alternative naming system to
represent each physical object.

Introduction to Arduino Uno


 Arduino Uno is a microcontroller board, developed by Arduino.cc, based on
the Atmega328 microcontroller and is marked as the first Arduino board
developed(UNO means “one” in Italian).
 The software used for writing, compiling & uploading code to Arduino boards
is called Arduino IDE (Integrated Development Environment), which is free
to download from Arduino Official Site.
 It has an operating voltage of 5V while the input voltage may vary from 7V to
12V.
 Arduino UNO has a maximum current rating of 40mA, so the load shouldn’t
exceed this current rating or you may harm the board.
 It comes with a crystal oscillator of 16MHz, which is its operating frequency.
 Arduino Uno Pinout consists of 14 digital pins starting from D0 to D13.
 It also has 6 analog pins starting from A0 to A5.
 It also has 1 Reset Pin, which is used to reset the board programmatically. In
order to reset the board, we need to make this pin LOW.
 It also has 6 Power Pins, which provide different voltage levels.
 Out of 14 digital pins, 6 pins are used for generating PWM pulses of 8-Bit
resolution. PWM pins in Arduino UNO are D3, D5, D6, D9, D10 and D11.
 Arduino UNO comes with 3 types of memories associated with it, named:
o Flash Memory: 32KB
o SRAM: 2KB
o EEPROM: 1KB
 Arduino UNO supports 3 types of communication protocols, used for
interfacing with third-party peripherals, named:
o Serial Protocol
o I2C Protocol
o SPI Protocol
Week 2:
Experiment 2 (A)
Problem Statement: Write an Arduino program to blink LED.
Aim: To blink the LED by using Arduino program.
Components Required: Arduino UNO, Breadboard (generic), LED (Generic), Jumper wires (Generic),
Resistor 220 ohm, Plier, Needle nose , Arduino IDE.
Program:
Source code:
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
Output:

Circuit Diagram:

Result:
the above program and circuit executed successfully.
Week 2:
Experiment 2 (B)
Problem Statement: write an arduino program to controlled by integer ,character and string.
Aim: To write an arduino program to controlled by integer ,character and string.
Components Required: Arduino UNO, Breadboard (generic), LED (Generic), Jumper wires (Generic),
Resistor 220 ohm, Arduino IDE.
Program:
Source code:
String inputString = "";
boolean stringComplete = false;
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
analogWrite(ledPin, 0);
Serial.begin(9600);
inputString.reserve(200);
}
void loop() {
if (stringComplete) {
Serial.println(inputString);
stringComplete = false;
inputString = "";
}
if(inputString == "led on") analogWrite(ledPin, 255);
if(inputString == "led off") analogWrite(ledPin, 0);
}
void serialEvent() {
while (Serial.available())
{
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n') {
stringComplete = true;
}
}
}
Output:

Circuit Diagram:

Result:
the above program and circuit executed successfully.
Week 2:
Experiment 2(c)
Problem Statement: Write an Arduino program to control the brightness of an led using
potentiometer
Aim: To write a program to control the brightness of an led using potentiometer.
Components Required: Arduino board ,Breadboard, LED – any colour , 220 Ohm resistor,
Potentiometer, A bunch of wires.
Program:
Source code:
#define LED_PIN 11
#define POTENTIOMETER_PIN A1
void setup()
{
pinMode(LED_PIN, OUTPUT);
}
void loop()
{
int potentiometerValue = analogRead(POTENTIOMETER_PIN);
int brightness = potentiometerValue / 4;
analogWrite(LED_PIN, brightness);
}

Output:
Circuit Diagram:

Result:
The above program and circuit executed Successfully.
Week 2:
Experiment 2 (D)
Problem Statement: Write an Arduino program to fast and slow blinking of an led.
Components Required Arduino Board, bunch of wires, led bulb, bread board.
Program:
Source code:
void setup()
{
pinMode(8, OUTPUT);
}
void loop()
{
int n=1;
while (n<=5)
{
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(500);
}
while (n<=10)
{
digitalWrite (8, HIGH);
delay (2000) ;
digitalWrite(8, LOW) ;
delay(2000) ;
}
}
Output:
Circuit diagram:

Result:The above program and code executed sucessfully.


Week 2:
Experiment 2 (E)
Problem Statement: Write an Arduino program for fading.
Components Required Arduino Board, bunch of wires, led bulb, bread board.
Program:
Source code:
int led = 9;
int brightness = 0;
int fadeAmount = 5;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
delay(30);
}
Output:
Circuit Diagram:

Result:
The above program and circuit executed successfully.
Week 2:
Experiment 2 (F)
Problem Statement: Write an Arduino program for fading.
Components Required Arduino Board, bunch of wires, led bulb, bread board.
Program:
Source code: int GREEN = 12;
int YELLOW =11 ;
int RED = 10;
int DELAY_GREEN = 5000;
int DELAY_YELLOW = 2000;
int DELAY_RED = 5000;
void setup()
{
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
}
void loop()
{
green_light();
delay(DELAY_GREEN);
yellow_light();
delay(DELAY_YELLOW);
red_light();
delay(DELAY_RED);
}
void green_light()
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
}
void yellow_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
}

void red_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
}
Output:
Circuit diagram:

Result:
The above program and circuit executed successfully.
Week 3:
Experiment b:
Problem Statement: Write an arduino program to control RGB by the user input.
Aim: To control RGB by using arduino program
Components Required: arduinouno, resistor, RGB, breadboard, wires
Source Code:
int red_light_pin= 11;
int green_light_pin = 10;
int blue_light_pin = 9;
void setup() {
pinMode(red_light_pin, OUTPUT);
pinMode(green_light_pin, OUTPUT);
pinMode(blue_light_pin, OUTPUT);
}
void loop() {
RGB_color(255, 0, 0); // Red
delay(1000);
RGB_color(0, 255, 0); // Green
delay(1000);
RGB_color(0, 0, 255); // Blue
delay(1000);
RGB_color(255, 255, 125); // Raspberry
delay(1000);
RGB_color(0, 255, 255); // Cyan
delay(1000);
RGB_color(255, 0, 255); // Magenta
delay(1000);
RGB_color(255, 255, 0); // Yellow
delay(1000);
RGB_color(255, 255, 255); // White
delay(1000);
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(red_light_pin, red_light_value);
analogWrite(green_light_pin, green_light_value);
analogWrite(blue_light_pin, blue_light_value);
}
CIRCUIT DIAGRAM:

Result:
The above program executed successfully.
Week 3:
Experiment c:
Problem Statement: Write an arduino program for servo motor interfacing with arduino.
Aim: To interface servo motor with arduino uno
Components Required: arduinouno, resistor, servo motor , breadboard, wires
Source Code:
#include<Servo.h>
Servo Myservo;
int pos;
void setup()
{
Myservo.attach(3);
}
void loop()
{
for(pos=0;pos<=180;pos++)
{
Myservo.write(pos);
delay(15);
}
delay(1000);
for(pos=180;pos>=0;pos--)
{
Myservo.write(pos);
delay(15);
}
delay(1000);

}
Curcuit Diagram:

Result:
The above program executed successfully.
Week 3:
Experiment d:
Problem Statement: Write an arduino program to control motor using npn transistor
Aim: To control motor with npn transistor
Components Required: arduinouno , potentiometer, breadboard, wires ,npn transistor ,9v
Battery.
Source Code:
#define pwm 3
#define pot A0
void setup()
{
pinMode(pwm,OUTPUT);
pinMode(pot,INPUT);
Serial.begin(9600);
//safety speed reset of the motor
analogWrite(pwm,0);

}
void loop()
{
float val = analogRead(pot);
float duty = map(val,0,1023,0,255);
analogWrite(pwm, duty); //here's how to generate PWM signal from Digital arduino pin
Serial.println(duty);
}

Circuit Diagram:

Result:
The above program executed successfully.
Week 3:
Experiment e:
Problem Statement: Write an arduino program to control servo motor with RGB
and arduino uno.
Aim: To control servo motor with RGB and arduino uno.
Components Required: arduinouno, resistor, servo motor , breadboard, wires ,RGB
Source Code:
#include <Servo.h>
Servo gol;
long distance;
int red = 11;
int green = 10;
int blue = 9;
void setup()
{
gol.attach(3);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}

void loop()
{
distance = 100;
top_open();
delay(2000);
distance = 20;
top_open();
delay(2000);
}

void top_open()
{
if(distance < 30)
{
gol.write(90);
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
else
{
gol.write(0);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
digitalWrite(blue, LOW);
}
}
Circuit Diagram:

Result:
The above code has been executed successfully.
Week 4:
Experiment b:
Problem Statement: Write an arduino program for interfacing LDR sensor with arduino
Aim: To interface LDR sensor with arduino
Components Required: arduinouno, resistor, LED, breadboard, wires, LDR sensor
Source Code:
const int ledPin = 5;
const int ldrPin = A0;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
void loop()
{
int ldrStatus = analogRead(ldrPin);
if (ldrStatus <= 200)
{
digitalWrite(ledPin, HIGH);
Serial.print("Darkness over here,turn on the LED :");
Serial.println(ldrStatus);
}
else
{
digitalWrite(ledPin, LOW);
Serial.print("There is sufficient light , turn off the LED : ");
Serial.println(ldrStatus);
}
}
Circuit Diagram:

Result:
The above code executed successfully.
Week 4:
Experiment c:
Problem Statement: Write an arduino program for interfacing PIR with arduino
Aim: To interface PIR sensor with arduino
Components Required: arduinouno, resistor, LED, breadboard, wires, PIR motion sensor
Source Code:
const int led = 9;
const int sensor = 5;
const int state = LOW;
const int val = 0;
void setup()
{
pinMode(led, OUTPUT);
pinMode(sensor, INPUT);
Serial.begin(9600);
}
void loop()
{
val = digitalRead(sensor);
if (val == HIGH)
{
digitalWrite(led, HIGH);
delay(500);

if (state == LOW)
{
Serial.println(" Motion detected ");
state = HIGH;
}
}
else
{
digitalWrite(led, LOW);
delay(500);
if (state == HIGH)
{
Serial.println("The action/ motion has stopped");
state = LOW;
}
}
}
Circuit Diagram:

Result:
The above code executed successfully.
Week 4:
Experiment d:
Problem Statement: Write an arduino program for interfacing ultrasonic HC-05 with arduino uno
Aim: To interface ultrasonic HC-05 with arduino
Components Required: arduinouno, resistor, LED, breadboard, wires, LDR sensor
Source Code:
#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUDROID 13
#define MAX_COMMAND 20
#define MIN_COMMAND 10
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2
#include <NewPing.h>
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200 .
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
#define BUZZER_PIN 9
#define red_LED 4
#define green_LED 5
#define blue_LED 6
String inText;
void setup() {
Serial.begin(9600);
Serial.println("ArduDroid 0.12 Alpha by TechBitar (2013)");
}
void loop()
{
Serial.flush();
int ard_command = 0;
int pin_num = 0;
int pin_value = 0;
char get_char = ' ';
if (Serial.available() < 1) return;
get_char = Serial.read();
if (get_char != START_CMD_CHAR) return;
ard_command = Serial.parseInt();
pin_num = Serial.parseInt();
pin_value = Serial.parseInt();
if (ard_command == CMD_TEXT)
{
inText ="";
while (Serial.available())
{
char c = Serial.read();
delay(5);
if (c == END_CMD_CHAR)
{
break;
}
else
{
if (c != DIV_CMD_CHAR)
{
inText += c;
delay(5);
}
}
}
}
if (ard_command == CMD_DIGITALWRITE)
{
if (pin_value == PIN_LOW) pin_value = LOW;
else if (pin_value == PIN_HIGH) pin_value = HIGH;
else return;
set_digitalwrite( pin_num, pin_value);
return;
}
if (ard_command == CMD_ANALOGWRITE)
{
analogWrite( pin_num, pin_value );
return;
}
if (ard_command == CMD_READ_ARDUDROID)
{
delay(500);
unsigned int uS = sonar.ping();
Serial.print("Ping:");
Serial.print(uS / US_ROUNDTRIP_CM);
Serial.println("cm");
if (uS / US_ROUNDTRIP_CM <= 10)
{
Serial.print("OBSTRUCTION");
return;
}
if (uS / US_ROUNDTRIP_CM > 10)
{
Serial.print("NO OBSTRUCTION");
return;
}
}
}
void set_digitalwrite(int pin_num, int pin_value)
{
switch (pin_num) {
/*case 13:
pinMode(13, OUTPUT);
digitalWrite(13, pin_value);
break;
case 12:
pinMode(12, OUTPUT);
digitalWrite(12, pin_value);
break;
case 11:
pinMode(11, OUTPUT);
digitalWrite(11, pin_value);
break;
case 10:
pinMode(10, OUTPUT);
digitalWrite(10, pin_value);
break;*/
case 9:
pinMode(9, OUTPUT);
digitalWrite(9, pin_value);
break;
/*case 8:
pinMode(8, OUTPUT);
digitalWrite(8, pin_value);
break;
case 7:
pinMode(7, OUTPUT);
digitalWrite(7, pin_value);
break;*/
case 6:
pinMode(6, OUTPUT);
digitalWrite(6, pin_value);
break;
case 5:
pinMode(5, OUTPUT);
digitalWrite(5, pin_value);
break;
case 4:
pinMode(4, OUTPUT);
digitalWrite(4, pin_value);
break;/*
case 3:
pinMode(3, OUTPUT);
digitalWrite(3, pin_value);
break;
case 2:
pinMode(2, OUTPUT);
digitalWrite(2, pin_value);
break;*/
}
}
Circuit Diagram:

Result:
The above code executed successfully.
Week 4:
Experiment e:
Problem Statement: Write an arduino program for implementing real time applications
Aim: To implement real time applications using sensors
Components Required: arduinouno, LED, breadboard, wires, LED , temperature sensor,
ultrasonic sensor,
Source Code:
static int trigger = 9;
static int echo = 8;
static int led_HC = 10;
static int led_pulsed = 13;
static int led_temperature = 12;
static int LM35_analogPin = 0;
long duration;
long distance;
float temp_C;
void setup()
{
Serial.begin(9600);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
pinMode(led_HC, OUTPUT);
pinMode(led_pulsed, OUTPUT);
pinMode(led_temperature, OUTPUT);
digitalWrite(echo, LOW);
digitalWrite(trigger, LOW);
digitalWrite(led_HC, LOW);
digitalWrite(led_pulsed, LOW);
digitalWrite(led_temperature, LOW);
analogReference(INTERNAL);
duration = 0;
distance = 0;
}
void loop()
{
}
void loop1(3000)
{
digitalWrite(trigger, HIGH);
delayMicroseconds(10);
digitalWrite(trigger, LOW);
duration = pulseIn(echo, HIGH);
distance = duration / 29 / 2;
if (distance < 10)
{
digitalWrite(led_HC, HIGH);
}
else
{
digitalWrite(led_HC, LOW);
}
Serial.print("duration : ");
Serial.print(duration);
Serial.print(" - distance : ");
Serial.println(distance);
}
void loop2(7000)
{
int i;
Serial.println("Pulsed LED");
for (i = 0; i < 5; i++)
{
digitalWrite(led_pulsed, HIGH);
delay(500);
digitalWrite(led_pulsed, LOW);
delay(500);
}
}
void loop3(11000)
{
float sum_temp = 0;
float average_temp = 0;
for (int i = 0; i < 3; i++)
{
delay(500);
temp_C = (1.1 * analogRead(LM35_analogPin) * 100.0) / 1024;
sum_temp += temp_C;
}
average_temp = sum_temp / 3;
if (average_temp > 23)
{
digitalWrite(led_temperature, HIGH);
}
else
{
digitalWrite(led_temperature, LOW);
}
Serial.print("Temperature : ");
Serial.println(average_temp);
}
Circuit Diagram:

Result:
The above code executed successfully.
Week 3:
Experiment a:
Problem Statement: Write an arduino program to control Led and buzzer by button
Aim: To control led and buzzer using button
Components Required: arduinouno, LED, breadboard, wires, buzzer piezo, push button
Source Code:
#include "pitches.h"
int melody[] = {
NOTE_C4, NOTE_C4, NOTE_D4, NOTE_C4, NOTE_F4, NOTE_E4, NOTE_C4, NOTE_C4, NOTE_D4,
NOTE_C4, NOTE_G4, NOTE_F4, NOTE_C4, NOTE_C4, NOTE_C5, NOTE_A4, NOTE_F4, NOTE_E4,
NOTE_D4, NOTE_AS4, NOTE_AS4, NOTE_A4, NOTE_F4, NOTE_G4, NOTE_F4
};
int buttonPin =12;
int noteDurations[] = {
8, 8, 4, 4, 4, 2, 8, 8, 4, 4, 4, 2, 8, 8, 4, 4, 4, 4, 4, 8, 8, 4, 4, 4, 2,
};
void setup()
{
pinMode (9, OUTPUT);
pinMode (10, OUTPUT);
pinMode (11, OUTPUT);
pinMode (buttonPin, INPUT);

}
void loop()
{
int buttonState = digitalRead(buttonPin);
if (buttonState == 1)
{
for (int thisNote = 0 ; thisNote < 25 ; thisNote++)
{
int randomLight1 = random(9, 12);
int randomLight2 = random(9, 12);
int randomLight3 = random(9, 12);
delay(100);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite (randomLight1, HIGH);
digitalWrite (randomLight2, HIGH);
digitalWrite (randomLight3, LOW);
int noteDuration = 1130/noteDurations[thisNote];
tone (3, melody[thisNote], noteDuration);
int pause = noteDuration * 1.275;
delay (pause);
noTone(3);
}
}
}
Circuit Diagram:

Result:

The above code executed successfully.


Week 5:
Experiment 5 (d)
Problem Statement: write a program for interfacing ambient light sensor
Aim: To write a program for interfacing Ambient light sensor
Components Required:
Arduino UNO
BH1750 Ambient Light Sensor Module
16×2 LCD Display
Mini Breadboard
10KΩ Potentiometer
330Ω Resistor
Connecting Wires
Program:
Source code:
#include <Wire.h>
#include<LiquidCrystal.h>
int BH1750address = 0x23;
byte buff[2];
LiquidCrystal lcd (7,6,5,4,3,2);
void setup()
{
Wire.begin();
lcd.begin(16,2);
lcd.print(" BH1750 Light ");
lcd.setCursor(0,1);
lcd.print("Intensity Sensor");
delay(2000);
}
void loop()
{
int i;
uint16_t value=0;
BH1750_Init(BH1750address);
delay(200);
if(2==BH1750_Read(BH1750address))
{
value=((buff[0]<<8)|buff[1])/1.2;
lcd.clear();
lcd.print("Intensity in LUX");
lcd.setCursor(6,1);
lcd.print(value);
}
delay(150);
}
int BH1750_Read(int address)
{
int i=0;
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
while(Wire.available())
{
buff[i] = Wire.read();
i++;
}
Wire.endTransmission();
return i;
}
void BH1750_Init(int address)
{
Wire.beginTransmission(address);
Wire.write(0x10);
Wire.endTransmission();
}
Output : Circuit Diagram:

Result: : The above program and circuit executed successfully

You might also like