Digital I/O - Sketch Programming - Arduino Development for OSX and iOS (2015)

Arduino Development for OSX and iOS (2015)

2. Sketch Programming

2.5 Digital I/O

In this section, we try to build Arduino program by utilizing digital I/O. We can write digital data using digitalWrite(). To read digital input, you can use digitalRead().

To implement our demo, you need a pushbutton and a LED. Connect LED to Arduino digital pin 8. You also attach a pushbutton on Arduino digital pin 6.

Open Arduino software and write this code.

int led = 8;

int pushButton =6;

int state = 0;

void setup() {

pinMode(led, OUTPUT);

pinMode(pushButton, INPUT);


void loop() {

state = digitalRead(pushButton);




Save this code, called ButtonLed.ino.

Compile and upload the program. After that, press pushbutton so you should lighting LED.