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

Tutorial MEK575

Uploaded by

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

Tutorial MEK575

Uploaded by

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

Tutorial MEK575 Mac-Aug 2024

1) The circuit involved connecting one wire from I/O pin 13 on the Arduino to a
resistor. The other end of the resistor is connected to the anode (long) leg of the LED.
The cathode end of the LED is connected to the Arduino ground (GND) pin. The
second LED uses essentially the same type of connections, only it is connected to
I/O pin 12. Evaluate and fill in the program codes or instructions given below:
/*
Alternate Blink
Turns on one LED on for 1 second while the other is off, then reverses
the LEDs for 1 second,
repeatedly.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
[ Code A ];
[ Code B ]; // This is for the second LED
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
[ Code C ];
[ Code D ];
}
// the loop routine runs over and over again forever:
void loop() {
[ Code E ]; // turn the LED on (HIGH is the voltage level)
digitalWrite(led2, LOW); // [ Instructions A ]
[ Code F ]; // wait for a second
digitalWrite(led1, LOW); // [ Instructions B ]
digitalWrite(led2, HIGH); // [ Instructions C ]
[ Code G ]; // wait for a second
}

2) What is the difference between a microcontroller and a microprocessor?

3) Describe the function of the following program codes;

(i) pinMode(pin, mode);

(ii) digitalRead(pin);

(iii) digitalWrite(pin, value);

(iv) delay (1000);

(v) int led = 7;


pinMode(led, OUTPUT);
4) Figure 4(c) show the connection of a simple circuit that controls a light emitting
diode (LED) and a piezo speaker to blink or beep continuously. The LED is
connected to pin 4 and the speaker to pin 5 on the Arduino. Evaluate and fill in the
program codes or instructions given below:

Figure 4(c)

/*Task: A LED and a piezo speaker are supposed to blink or beep continuously.*/

// The LED is connected to pin 4.


//give it a name:
[ Code A ];

// The speaker is connected to pin 5.


//give it a name:
[ Code B ];

void setup()
{
[ Code C ]; //pin 4 (pin “LED”) is supposed to be an output
[ Code D ]; //Pin 5 (pin “speaker”) is supposed to be an output
}

void loop()
{ //The main part starts
[ Code E ]; //turn on the LED
[ Code F ]; //turn on the speaker
[ Code G ]; //wait for 1000 milliseconds (sound and light)
[ Code H ]; //turn off the LED
[ Code I ]; //turn off the speaker
[ Code J ]; //wait for 1000 milliseconds (no sound and no light)
}
5) A soil moisture sensor has two probes, and the resistance between the two probes
is determined by the moisture in the soil. The function of soil moisture sensor is
measuring the volumetric water in soil. If more the moisture, then the resistance will
be less and vice- versa. The concept of this sensor can be used to remote sensing in
hydrology and agriculture.

Given the algorithm: -


Step 1 Assign analog pin A3 to moisture sensor
Step 2 Define and initialize sensor value 0.
Step 3 Delay in 1 minutes
Step 4 Read sensor and store the value in sensor variable
Step 5 Delay in 2 minutes
Step 6 If sensor value is equal to or greater than 500 then print " WET

Step 7 If sensor value is equal to or less than 200 then print " DRY "
Based on the algorithm;
(i) Design a flowchart for the system

(ii) Write the coding for the system based on Arduino IDE code

6) Figures Q2(b)(i) and Q2(b)(ii) present an example of Arduino’s programming.


Rewrite the coding and explain the program by adding comments for all of the
instructions as in an IDE environment.

(i) Program 1
int led = 7;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
delay(500);
}

Figure Q2(b)(i)
(ii) Program 2
Hint: sensorPOT is a potentiometer.

int PinLED = 11;


int sensorPOT;

void setup()
{
pinMode(PinLED, OUTPUT);
}

void loop()
{
sensorPOT = analogRead(A0);
digitalWrite(PinLED, HIGH);
delay(sensorPOT);
digitalWrite(PinLED, LOW);
delay(sensorPOT);
}

Figure Q2(b)(i)

You might also like