Uploaded by Gilbert Chimboza

MM3

advertisement
NNAME:
PARTNER:
GILBERT C CHIMBOZA R195293X
HETTW
ARMSTRONG MWANYINYA R196677S
MICROCONTROLLERS M3 PRACTICAL
LECTURER: MR P DANGARE
DUE DATE: 09 JULY 2021
AIM:
Microcontroller interfacing using real examples (LEDs and sensors)
To learn microOperating systems. 3. To learn to build interfaces between real world data and the
computer.
Introduction
With technology and information developing rapidly, particularly the information and
many other fields related to technology, ne of the areas is the Internet of Things (IoT).
IoT refers to the things around us that are connected by the internet and are able to
communicate with each other. Most sensors are mounted on objects directly such as
ovens, refrigerators, and others. IoT can be implemented in several domains such as
industry, medical services,home and others. The data generated by the IoT application
is the Big Data which can be further analyzed to optimize the resources used.
AIMS AND OBJECTIVES
1. To teach microcontroller interfacing using real examples (LEDs and sensors)
2. To learn micro-controller usage:




3. To learn to build interfaces between real world data and the computer
EQUIPMENT AND MATERIALS
1. Temperature controller




cting wires




2. Washing machine controller



Part 1 a)
Fig 1:Temperature controller block diagram
Part 1b)
Fig 2:Temperature controller Flowchart diagram
Part 1c)
Fig 3:Temperature controller circuit with IR option
Operation:
The cicuit is connected as in figure 1 above. The first four lines of the code are
variables and show which pin a wire will connect to, be it for an LED or relay.
Power to the LM35 is provided via the arduino board. The signal generated by the
LM35 is then connected to the analog A1 port of the arduino.
After the computation is done to present a degree celcius reading, pin 10 for the red
LED will have a high output whenever the arduino computed temperature reads less
than 20 degrees celcius.
Pin 7 of the relay will also turn HIGH during this instant meaning the air-conditioning
unit power circuit will be completed, turning on the unit.
When the temperature reading is above 22 degrees, the Cooling function will be
activated as indicated by the yellow LED switching on.
If the temperature reading falls between the 20 to 22 degrees celcius, after a delay of
ten seconds, the controller will deliver a LOW that will switch off the relay and mains
to the unit and switch on the green LED.
When the server temperature falls below 15 degrees celcius above 28 degrees celcius,
a buzzer will sound to alert the server room staff of the temperature abnormality.
The bulb in the circuit was used to demonstrate the relay functionality.
The code:
#include <IRremote.h>
int val;
//parameter declaration
int tempPin = 1; //assign analog pin1 as sensor input
int unitOff = 3;
int relay = 7;
//assignment digital pin 7 name to Relay
int heater = 10;
//Heater ON red LED set to pin9
int cooling = 9; //Cooling ON green LED set to pin10
int buzzer = 12; //buzzer assigning
const int infrared = 6;
IRsend irsend;
void setup()
{
Serial.begin(9600);
//serial monitor initialisation
pinMode(relay,OUTPUT);
//Relay set as an output pin to turn unit on or off
pinMode(heater,OUTPUT); //signal output send to red led
pinMode(cooling,OUTPUT);
pinMode(buzzer,OUTPUT); //signal output send to green led
pinMode(infrared,OUTPUT);
pinMode(unitOff,OUTPUT);
}
void loop()
{
val = analogRead(tempPin);
float mv = ( val/1024.0)*5000;
float cel = mv/10;
Serial.print("TEMPRATURE = ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(10000);
for (cel>=20;cel<=22,cel++){digitalWrite(relay,LOW); //Switches off the unit at the mains
digitalWrite(unitOff,HIGH);
delay(10000);}
if(cel<20){digitalWrite(relay,HIGH);
digitalWrite(heater,HIGH)
Delay(10000);
}
else if(cel>22){digitalWrite(relay,HIGH);
digitalWrite(cooling,HIGH);
digitalWrite(heater,LOW);
Delay(10000); }
//unit turns on
//red led switched on indicating heater is on
//Switch on unit.
delay(10000);
if (cel<15) { digitalWrite(buzzer,HIGH);}
else if (cel>28) {digitalWrite(buzzer,HIGH);
Delay(30000);
}
//Buzzer alarm if too cold
//Buzzer alarm if too hot
Part 2: INTRODUCTION
The use of embedded systems and microcontrollers has become common in our day
today living making work easier and somehow. For example we can make use of the
temperature sensor to maintain room temperature. Other works can be achieved again
for example a washing machine programmed on Arduino.
In the experiment, in our first task we will use a temperature sensor to measure the
room temperature and an Arduino. The temperature is maintained in the desired range
raising an alarm when a desired range is exceeded. The temperature is measured using
the temperature and the Arduino will help in maintaining the room temperature,
triggering the heater and the cooler where necessary.
In the second task we will design the controller for a washing machine. A push button
is to be used as the input to start the whole experiment, once the button is pushed a
heater is turned on followed by the opening of a water valve thereafter depending on
the colour of clothes being washed, a DC motor is rotated clockwise and
anticlockwise alternatively thus washing the clothes. Rotating is then repeated for 3060 minutes again depending on the colour of
clothes being washed.
2. Washing machine controller
i) Data flow diagram
Figure 4: Data flow diagram
ii) Flow chart
Figure 5: Washing machine flow diagram
iii) The push button and the switch are the 2 inputs of the microcontroller
The heater, DC motor and the valve are the outputs
iv)The code:
int heater = 3;
int valve = 4;
int motorClockwise = 5;
int motorAnticlockwise = 6;
int button = 7;
int Switch = 8;
int i;
int x;
void setup() {
pinMode(heater, OUTPUT);
pinMode(valve, OUTPUT);
pinMode(motorClockwise, OUTPUT);
pinMode(motorAnticlockwise, OUTPUT);
pinMode(Switch, OUTPUT);
}
void loop() {
if(digitalRead(button)==HIGH, digitalRead(Switch)==HIGH){
int colored=i;
int white=x;
//turning the heater on for 30seconds for colored clothes
for (i=0; i<1; i++){
digitalWrite(heater,HIGH);
delay(30000); }
//turning on the heater for 60 seconds for white clothes
for (i=0; i<1; i++){
digitalWrite(heater,HIGH);
delay(60000);
}
//opening the valve for 60 seconds
digitalWrite(valve,HIGH);
delay(60000);
//washing the clothes
for (i=0; i<1; i++){
digitalWrite(motorClockwise,HIGH);//turns on the clockwise motor
delay(10000);
digitalWrite(motorAnticlockwise,HIGH);//turns on the counter clockwise motor
delay(10000);
}
delay (1000);
}
}
v)Setup
DISCUSSION
In the first part when controlling the room temperature, the Red LED turned on when
the heater was triggered and a yellow LED is turned on when the cooler was switched
on. A green LED was turned on when both are switched off. A buzzer should sounded
when the temperature dropped below 15°C or exceeded 25°C. All the condition were
maintained hence the room temperature was controlled successfully. However we had
to take note of the polarity of the temperature sensor (LM35) otherwise wrong
temperature would have been recorded. Special attention was to be paid again on
conversion of units to degrees Celsius. In the second task, the heater (which was
represented by the red LED) turned on for 30 seconds for white clothes then 60
seconds for colored clothes after the push button was
pressed. The DC motor was then turned on clockwise and anticlockwise thus the
clothes were washed.
CONCLUSION:
The tasks carried out in the experiments apply in our everyday lives and always make
peoples work easier. One can use microcontrollers to maintain the temperature of a
blast furnace other than continuously record the temperature. They can also be used to
monitor some conditions where it is risky for a human being to do for example
measuring the temperature of magma. The washing machine is now becoming
common in our day to day living. Microcontrollers can be used to enhance the
functionalities of these washing machines to make work easier.
REFERENCES:

Controlled Clothes Washing Machine.

Washing Machine

Download