ARDUINO – MOBILE ROBOTICS
WORKSHOP
#TrailblazingTheFutureOfConnectedObjects#
LESSON 3
#TrailblazingTheFutureOfConnectedObjects#
Module 1 - LED
#TrailblazingTheFutureOfConnectedObjects#
8
Let Do Practical
Module 1 : Blink LED
10
Let Do Practical
Exercise 1 – LED BLINKING
HIGH
LOW
Let Do Practical
Continued…Exercise 1 – LED BLINKING
/ Project 1 - LED
Flasher
/ int ledPin = 10;
void setup() {
pinMode(ledPin, OUTPUT);
}
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() {
//setup motors, sensors etc
}
void loop() {
// get information from sensors
// send commands to motors
}
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
Module 2 : Push Button with LED
Let Do Practical
Button Schematic
Let Do Practical
Exercise 1 – 1 PUSH BUTTON and 3 LED
Refer page 10 your module
Module 3 – IR Sensor
22
Let Do Practical
Module 3 : Running Light with IR Sensor
PragmaticEdu Media
Let Do Practical
Continued…Running Light with IR Sensor
const int SensorPin = 2; // set pin numbers for IR sensor pin
const int ledPin = 13; // the number of the LED pin
int SensorState = 0; // variable for reading the pushbutton status
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