Micro Lab Act 2
Micro Lab Act 2
Micro Lab Act 2
1. Objective:
This activity aims to demonstrate the different digital I/O operations in a microcontroller based
system. The activity will cover assembly of a switch-driven circuit, programming digital input functions,
using conditional statements, and outputting digital results.
-Write a code for a microprocessor based system that implements digital input devices.
-Design a circuit that accepts digital transducer data, process and then display digital output.
3. Discussion:
The digital inputs and outputs (digital I/O) on the Arduino are what allow you to connect the Arduino
sensors, actuators, and other ICs. Learning how to use them will allow you to use the Arduino to do some
really useful things, such as reading switch inputs, lighting indicators, and controlling relay outputs.
As for today’s activity, we used 4-input dip switch to control the output or LED. This will be done
through programming functions such as: pinMode(), digitalRead() and digitalWrite(). These functions
determine the pin and mode (input or output), reads a value from the digital I/O pin you want to read and
writes the digital value of a pin (I\O or High\Low).
4. Resources Needed:
1 Arduino
Arduino (Software)
1 USB cable
2 LED
2 100 ohm resistor
2 1000 ohm resistor
1 Set wires
1 Breadboard
1 4-input Dip Switch
5. Procedures:
Steps in running the experiment:
1. Connect the arduino to a computer through USB cable.
2. Make a connection as shown in Figure 1.
Figure 1
3. Make a command through Arduino Software to control the LED using 4-input dip switch.
4. Run the Program.
Code:
int x = 0;
int y = 0;
void setup()
{
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop()
{
x = digitalRead(3);
y = digitalRead(4);
Serial.println(x);
Serial.println(y);
delay(100);
if( x == 0 and y == 0)
{
digitalWrite(13, LOW);
digitalWrite(12, LOW);
}
else if ( x== 0 and y == 1)
{
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
}
else if (x == 1 and y == 0)
{
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
}
else
{
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
}
}
6. Results
7. Observations:
8. Conclusions:
9. References: