R195328R Practical Report M2
R195328R Practical Report M2
Introduction
Arduino comprises of both a physical programmable circuit board (commonly known as a
microcontroller) and a programming software, or IDE (Integrated Development
Environment) that can be run on a PC, used to compose and transfer PC code to the circuit
board. It can be done by using the Arduino programming language (based on Wiring), and
the Arduino Software (IDE), based on Processing. Unlike other programmable circuit boards,
the Arduino does not require a different equipment (called a software engineer) to upload
code to the circuit board, one can essentially utilize a USB link. Also, the Arduino IDE
utilizes a rearranged rendition of C++, making it simpler to figure out how to program. In a
word, Arduino make the functions of the micro-controller into a more accessible
package. The Uno is one of the more prevalent boards in the Arduino family and an
extraordinary. The use of sensors helps us get analog output from the environment and create
variables that will help us control devices in our circuits, an example can be a temperature
sensor in this instance measures the instantaneous temperature of the air around the sensor
and we can make regulations based on its readings and so on. These sensors var widely each
with its specific task such that they can be applied in different situations requiring different
attentions to certain states of environment e.g., humidity, proximity etc.
3. To learn to build interfaces between real world data and the computer getting analog input from
different sensors.
Task #1: Arduino Based Temperature Controller.
Task#2: Arduino Based distance sensor.
i) Distance measurement.
ii) Water level Controller.
• Arduino Uno
• Connecting Wires
• LEDs
• Push Switch
• Breadboard
• Computer (Arduino C IDE installed)
• Temperature sensor (LM35)
• Ultrasonic range detector (HC SR-04)
(a)
The air conditioner is to be triggered automatically by a relay
if the air temperature is below 30°C and switched off when it is at least 40C. A red
led is turned on when the heater is triggered and a green led is turned on when it is
switched off. Write an Arduino C programme which solves the above problem and
implement the temperature controller to monitor and control the air temperature.
void setup()
{
Serial.begin(9600) ; //Starting serial Communication at baud rate of
9600
pinMode(high,OUTPUT); //declaring LED pins as OUTPUT
pinMode(low,OUTPUT);
}
void loop()
{
int temp_reading = analogRead(1) ; //reading analog voltage and
storing it in an integer
temp_reading = temp_reading * 0.48828125; //converting reading into
Celsius
Serial.print("TEMPRATURE = "); //to Display on serial monitor
Serial.print(temp_reading); //Temperature reading
Serial.print("*C"); //TEMPRATURE = 27*C ETC
Serial.println(); //To end the line
delay(5000); //1 Sec delay
/*
LOGIC:
if (temperature (temp_reading) > 30 ° C )
turn on Yellow Leds
turn off Green Leds
else
turn off Yellow Leds
turn on Green Led
*/
if(temp_reading > 40) // This is the control statement
{
digitalWrite(high,HIGH) ;
digitalWrite(low,LOW) ;
}
else
{
digitalWrite(high,LOW) ;
digitalWrite(low,HIGH) ;
}
}
A red LED turned on when the temperature reading from the sensor was 40 degrees Celsius and the
Green LED turned on when the temperature fell below 30 degrees Celsius.
b.
Arduino based distance sensor uses 2 sensors along with Arduino. The two
sensors are infrared proximity sensor and ultrasonic range finding sensor. The IR
sensor has a light source, which bounces the infrared light from the objects to the
sensor. The ultrasonic range finder sensor produces the high frequency sound
waves and calculates the echo time, to determine the distance.
(i) Design a distance measuring sensor using the Ultrasonic Sensor HC - SR04
and the Arduino Uno board. Design an experiment to calibrate the sensor for
measurements from 0 to 1 m. Present the results of the calibration.
Design an Arduino Based Water Level Controller that will control the water
(ii) level of a tank automatically by detecting the water level by using sensors (e.g.,
the Ultrasonic Sensor HC - SR04). As the water level drops below a preset
value, the circuit alerts the user by sounding an alarm and it automatically.
int duration;
float distance;
int enchopin = 13;
int trigpin = 9;
void setup()
{
Serial.begin(9600);
pinMode(enchopin,INPUT);
pinMode(trigpin,OUTPUT);
digitalWrite(trigpin,LOW);
delay(200);
}
void loop()
{
digitalWrite(trigpin,HIGH);
delay(500);
digitalWrite(trigpin,LOW);
duration = pulseIn(enchopin,HIGH);
Serial.println("the distance is ");
distance = duration*0.034/2;
Serial.print(distance);
Serial.print("cm");
Serial.println();
delay(1000);
There’s a continuous reading on the serial of the Arduino IDE interface when there are changes done
in proximity between the Utrasonic sensor and the object and there’s a 2 second delay put in place
to make sure the object whose proximity is in question can settle well before a reading is taken.
int duration;
float distance;
int enchopin = 13;
int trigpin = 9;
int buzzer = 7;
int Red = 6;
int Green = 5;
int preset_value1 = 40;
int preset_value2 = 10;
void setup()
{
Serial.begin(9600);
pinMode(enchopin,INPUT);
pinMode(trigpin,OUTPUT);
pinMode(buzzer,OUTPUT);
pinMode(Red,OUTPUT);
pinMode(Green,OUTPUT);
digitalWrite(trigpin,LOW);
digitalWrite(Red,LOW);
digitalWrite(Green,LOW);
digitalWrite(buzzer,LOW);
delay(200);
}
void loop()
{
digitalWrite(trigpin,HIGH);
delay(500);
digitalWrite(trigpin,LOW);
duration = pulseIn(enchopin,HIGH);
Serial.println("the distance is ");
distance = duration*0.034/2;
Serial.print(distance);
Serial.print("cm");
Serial.println();
delay(1000);
if( distance > preset_value1)
{
digitalWrite(buzzer,HIGH);
digitalWrite(Green,HIGH);
digitalWrite(Red,LOW);
}
else if( distance < preset_value2)
{
digitalWrite(buzzer,HIGH);
digitalWrite(Red,HIGH);
digitalWrite(Green,LOW);
}
else
{
digitalWrite(buzzer,LOW);
digitalWrite(Red,LOW);
digitalWrite(Green,LOW);
}
}
There’s a continuous reading on the serial of the Arduino IDE interface when there are changes done
in proximity between the Utrasonic sensor and the object and there’s a 2 second delay put in place
to make sure the object whose proximity is in question can settle well before a reading is taken and
a buzzer sounds to signify either very low water levels and very high water levels, the red LED turns
on in Synchrony with the buzzer when the distance becomes very small resembling very high water
levels and the Green LED turns on together with the sound of a buzzer when the distance is greater
signifying very low water level.
All the systems in question were, connected, programmed and launched thus the whole
practical’s scope was illuminated on the actual interface.
All the circuits and projects worked out so well, according to the script they were supposed
to follow; the challenges were on the amount of space on the breadboard which was almost
elapsed and it was too difficult to debug errors on the hardware once the whole circuit was
connected. However, the practical was a success, being well familiarized with the
equipment and managing the new interface of Arduino C to program the Arduino UNO and
the components on the board; thus, the whole of the practical’s aim was achieved.