Tutorial MEK575
Tutorial MEK575
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
}
(ii) digitalRead(pin);
Figure 4(c)
/*Task: A LED and a piezo speaker are supposed to blink or beep continuously.*/
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.
(ii) Write the coding for the system based on Arduino IDE code
(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.
void setup()
{
pinMode(PinLED, OUTPUT);
}
void loop()
{
sensorPOT = analogRead(A0);
digitalWrite(PinLED, HIGH);
delay(sensorPOT);
digitalWrite(PinLED, LOW);
delay(sensorPOT);
}
Figure Q2(b)(i)