Lesson 3 MRSM
Lesson 3 MRSM
Lesson 3 MRSM
WORKSHOP
#TrailblazingTheFutureOfConnectedObjects#
LESSON 3
#TrailblazingTheFutureOfConnectedObjects#
Module 1 - LED
#TrailblazingTheFutureOfConnectedObjects#
8
Let Do Practical
HIGH
LOW
Let Do Practical
Continued…Exercise 1 – LED BLINKING
/ Project 1 - LED
Flasher
void loop() {
LOW
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
HIGH
LOW
Arduino Code Basics
Arduino programs run on two basic sections:
void setup() {
}
void loop() {
}
SETUP
• The setup section is used for assigning input
and outputs (Examples: motors, LED’s, sensors
etc) to ports on the Arduino
• It also specifies whether the device is OUTPUT
or INPUT
• To do this we use the command “pinMode”
14 14
SETUP
void setup() {
port #
pinMode(9, OUTPUT);
Input or Output
}
http://www.arduino.cc/en/Reference/HomePage
LOOP
void loop() { Port # from setup
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(1000);
Turn the LED on
or off
} Wait for 1 second
or 1000 milliseconds
16
Let Do Practical
Exercise 2 – LED RUNNING LIGHT
Module 2 - BUTTON
#TrailblazingTheFutureOfConnectedObjects#
18
Let Do Practical
Button Schematic
Let Do Practical
22
Let Do Practical
Module 3 : Running Light with IR Sensor
PragmaticEdu Media
Let Do Practical
Continued…Running Light with IR Sensor
void setup()
{
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output
pinMode(SensorPin , INPUT); // initialize the IR sensor pin as an input
}
void loop()
{
SensorState = digitalRead(SensorPin); // read the state of the IR sensor value
if (SensorState == HIGH) // check if the IR sensor is pressed
{ // if it is, the IR sensor is HIGH
digitalWrite(ledPin, HIGH); // turn LED on
}
else
{
digitalWrite(ledPin, LOW); // turn LED off:
}
}
PragmaticEdu Media
ARDUINO – MOBILE ROBOTICS WORKSHOP