The book illustrates simple Do It Yourself (DIY) experiments for Intel Galileo Board novices. This repository includes the codes to basic Galileo experiments such as Controlling LED, More LED work, Coloring the RGB and Push Button.

Page 1

What will you make?

Page 2

Page 3

if (((button1State == LOW) || (button2State == LOW)) // if we’re pushing
button 1 OR button 2
&& ! / / AND we’re NOT
((button1State == LOW) && (button2State == LOW))) / / pushing button 1
AND button 2
/ / then...
digitalWrite(ledPin, HIGH); / / turn the LED on
digitalWrite(ledPin, LOW); / / turn the LED off
/ / Well, that was the code for Push button.
/ / I hope you enjoyed the journey.
Well, I am not telling you the uses of a push button...
“We cannot teach people anything; we can only help them discover it within themselves.”
- Galileo Galilei

Page 4

I’ll Make In nity
Project 04
Push Button!
Buttons to the rescue!
This code is written by Nirman Dave,
This code is completely free for use.
/ / First we’ll set up constants for the pin numbers.
/ / This will make it easier to follow the code below.
const int button1Pin = 2; // pushbutton 1 pin
const int button2Pin = 3; // pushbutton 2 pin
const int ledPin = 13; / / LED pin
void setup()
/ / Command pushbutton pins as input
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
/ / Command LED pin to be an output:
pinMode(ledPin, OUTPUT);
void loop()
int button1State, button2State; // variables to hold the pushbutton states
/ / Since a pushbutton has only two states, we can use it as a digitalRead
/ / function. And we’ll read the current pushbutton states into
/ / two variables.
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);
/ / If the button is being pressed, it will be
/ / connected to GND. If the button is not being pressed,
/ / the pullup resistor will connect it to 5 Volts.
/ / So the state will be LOW when it is being pressed,
/ / and HIGH when it is not being pressed.
Code continues on next page...

Page 5

Page 6

Page 7

Writing the code
Open up the Galileo Arduino IDE and get ready to code this project!
We need to defi ne to Galileo if the digital input we are using, is
used as an input or an output. The code below, does that.
pinMode(button2Pin, INPUT);
To read the digital input, we use the following code with the d igi-
button1State = digitalRead(button1Pin); Since we have connected button to GND, it has to read LOW when being pressed. The code below, does that.
if (button1State == LOW)
Read the code on the next page com- pletely. This will be helpful.

Page 8

Getting Started
This is how your board should look like!
Connect any pin on pushbutton 2 to ground (GND).
Connect the opposite diagonal pin of the pushbutton to digital pin 3.
Also connect 10K resistors (brown/black/red) between
digital pins 2 and 3 and GND. These are called “pull-up” resistors. They ensure that the input pin will be either
5V (unpushed) or GND (pushed), and not somewhere in be- tween.
(Remember that unlike analog inputs, digital inputs are onl y
Most Arduinos, including the Uno, already have an LED
and resistor connected to pin 13, so you don’t need any additional circuitry.
But if you’d like to connect a second LED to pin 13,
Connect the positive side of your LED to Arduino digital pi n 13
Connect the negative side of your LED to a 330 Ohm resistor Connect the other side of the resistor to ground

Page 9

Attaching strings
Until now we have only talked about projects that deal with out-
puts. Here is a project that deals with inputs, believe me, it’ s cool!
The way a push button works with Galileo is that when the but-
ton is pushed, the voltage goes LOW. The Galileo reads this and
reacts accordingly.
A pull up resistor will be used too, to keep the voltage HIGH when the button is not pressed.
-------------------------------------------------------- Pushbuttons
The easiest way to hook up
the pushbutton is to connect two wires to any opposite
corners. Connect any pin on pushbutton 1 to ground (GND). Connect the opposite diagonal pin of the pushbutton to digital pin 2.
Connecting the board
NOTE: Power supplies are NOT interchangeable between the Intel Galileo Gen 2 and Intel Galileo board. The Gen 2 power supply is 12V and will permanently damage Gen 1 boards. Therefore, please use the power supply which has been shipped with the board.
1) Plug the power cable in the wall and than into the Galileo
board. Make sure your board is connected to nothing else. You’ll see some LEDs glow up!
2) Connect Galileo to your computer using the Micro USB cable provided.

Page 10

Installing IDE
In case you’re wondering what IDE is, it stands for Integrated
Development Environment. This board uses the Galileo Ardui-
no IDE. This will allow you to code the behavior of your Galile o
1) Download the Galileo Arduino IDE from
However, if the link seems broken please search “Intel Galileo IDE” on the internet.
2) Unzip your fi le to C:\ drive only . In case you wish to rename
the folder, make sure you do not have any spaces. If your are
upgrading from Gen 1 to Gen 2, you also need to upgrade to the latest IDE. Feel free to uninstall the older version of IDE if you
are upgrading to the latest versions.
(MAC Users: Drag Arduino icon into your /Applications folder)
3) Launch application by double clicking it from Arduino-1.5.3 folder or from the /Applications folder, if you are a mac user.
Hah! Anyone can do that...
Things you’ll need
Here are the things you’ll need for this adventure!
7x Jumper Wires 1x LED1x Galileo Board
1x Breadboard 1x Resistor 330
ohm 2x Resistor 10k
2x Push buttons

show more