Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Learning C for Arduino
Learning C for Arduino

Learning C for Arduino: A comprehensive guide that will help you ace C's fundamentals using the powerful Arduino board

eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning C for Arduino

Chapter 2. Our First Program!

In this chapter, we will be learning how to connect our Arduino to our system and make it ready for uploading our very first C program with Arduino IDE.

Let's get started. I am assuming you have got your own Arduino Uno and an A-B cable to connect it to your PC. If you haven't, I recommend you pick up an Arduino Uno (any version will do, but Arduino Uno is preferred) and follow this chapter. You can buy Arduinos from any electronics shop or order online. You can go to https://www.arduino.cc/en/Main/buy to find a store in your locality to buy an Arduino.

Connecting your Arduino

In the previous chapter, we learned how to connect an Arduino to our system. Let's do it again.

First, connect your A-B cable to your PC, and then connect the cable to the board. Your PC will make a sound to confirm that the Arduino has connected to the PC, and the on-board on/off LED will turn on.

Now open the Arduino IDE. From the menu, go to Tools | Board | Arduino/Genuino Uno. You can select any board you have bought from the list. See the following screenshot for the list:

Connecting your Arduino

Now let's do the tricky part. You have to select the port on which the Arduino is connected. There are a lot of things you can do to find out. We will discuss few of them in Chapter 10, Few Error Handlings. If you have the latest version of Arduino IDE and go to Tools | Port , and you will see a bunch of port lists, but on the port on which your Arduino is connected, you will see something similar to the following. In my case, it is port number COM13 (on Windows). Select the...

Hello Arduino!

Let's write our first program on the Arduino IDE. Go to File and click New. A text editor will open with a few lines of code. Delete those lines first. Then, on the editor section, type the following code. Don't worry, the code will be explained later:

void setup() { 
  Serial.begin(9600); 
} 
 
void loop() { 
  Serial.print("Hello Arduino!\n"); 
} 

From the menu, go to Sketch and click Upload. It is a good practice to verify/compile the code before uploading it to the Arduino board. There will be a prompt to save the code on your system. Just give it any name you want and save it. To verify/compile the code, you need to go to Sketch and click Verify/Compile. You will see the message Done Compiling  on the bottom of the IDE if the code is error-free. See the following screenshot:

Hello Arduino!

After the successful upload, you need to open the Serial Monitor of the Arduino IDE. To open the Serial Monitor, you need to go to Tools and click Serial Monitor...

Things to remember

The following sections cover some things you need to remember.

Watch your case

C is case sensitive. So, we need to take care about what we type, or our code won't compile. For example, loop() and Loop() are not the same thing in C. We cannot use serial.print("Hello Arduino!"); instead of Serial.print("Hello Arduino!");.

Don't forget your semicolon!

Now look at the following code. Can you tell where it went wrong?

void setup() {
 Serial.begin(9600)
 Serial.println("Arduino is fun");
}
void loop() {
}

Exactly! On the second line, we missed a semicolon. Let's see if our Arduino IDE can detect the error. We wrote the code in the editor of our Arduino IDE and clicked the verify button (Don't forget your semicolon!), and found the following result:

Don't forget your semicolon!

From this screen, we can see that our Arduino IDE could detect the error. The log (the black portion of the Arduino IDE) shows where the error occurred. The log says,  expected ';' before 'Serial...

Summary

In this chapter, we have learned how to connect the Arduino to our system and how to verify/compile the code. We then uploaded some sample code to our board. We have learned how the Arduino code works. We also learned how to play with an LED. We made the LED blink indefinitely. I would suggest you change the delay time and play with the blinking code. Who knows, you might find something interesting or invent a Morse-code generator!

Left arrow icon Right arrow icon

Key benefits

  • Get hands-on experience with the Ardruino board and learn to control it with your programming skills
  • Learn the essential concepts of C such as variables, data structures, functions, loops, and pointers
  • Work with electronic devices such as LEDs, switches, and motors and connect them to Arduino using C

Description

This book will start with the fundamentals of C programming and programming topics, such data types, functions, decision making, program loops, pointers, and structures, with the help of an Arduino board. Then you will get acquainted with Arduino interactions with sensors, LEDs, and autonomous systems and setting up the Arduino environment. Moving on you will also learn how to work on the digital and analog I/O, establish serial communications with autonomous systems, and integrate with electronic devices. By the end of the book, you will be able to make basic projects such as LED cube and smart weather system that leverages C.

Who is this book for?

This book is for hobbyists who have no knowledge about programming and microcontrollers, but are keen to learn C programming using a very affordable hardware device.

What you will learn

  • Play with mathematical operations using C
  • Use logical operations and loops to play with LEDs and the Arduino board
  • Create custom functions using C and connect an SD card to the Arduino
  • Use Object-oriented Programming to connect a GSM module to the Arduino board
  • Play with an LCD board and Servo using standard Arduino libraries
  • Build projects using Arduino such as a LED cube, a smart weather system, and home security
  • Identify and fix common errors on an Arduino board

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 24, 2017
Length: 378 pages
Edition : 1st
Language : English
ISBN-13 : 9781787123571
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Mar 24, 2017
Length: 378 pages
Edition : 1st
Language : English
ISBN-13 : 9781787123571
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 99.97
Learn Arduino Prototyping in 10 days
€29.99
Learning C for Arduino
€36.99
Mastering Arduino
€32.99
Total 99.97 Stars icon
Banner background image

Table of Contents

10 Chapters
1. Getting Started Chevron down icon Chevron up icon
2. Our First Program! Chevron down icon Chevron up icon
3. Exploring C with Arduino IDE Chevron down icon Chevron up icon
4. Blinking with Operations and Loops Chevron down icon Chevron up icon
5. Functions and Files with Arduino Chevron down icon Chevron up icon
6. Arduino and C++ Chevron down icon Chevron up icon
7. Using Pointers and Structure Chevron down icon Chevron up icon
8. Working with Arduino Libraries Chevron down icon Chevron up icon
9. Lets Build Something Awesome Chevron down icon Chevron up icon
10. Few Error Handlings Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9
(8 Ratings)
5 star 37.5%
4 star 0%
3 star 12.5%
2 star 12.5%
1 star 37.5%
Filter icon Filter
Top Reviews

Filter reviews by




John LISOWSKI Aug 22, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great
Amazon Verified review Amazon
Fillock Jul 25, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is the best book for learning C / C++ that I come across (despite it's name; "Learning C for Arduino" the book is also about OOP, C and C++ concepts). If your in for the Arduino, this book teach you how to write effective code for the Arduino platform, and also shows you the smaller tweeks needed to make the C++ concepts work on the Arduino platform.The best about the book is how it explains the hard parts of C++ in a simple and easy way. Every general C++ book I have read struggle trying to do so, but this book does it specially good. The book helped me break down difficult C++ concepts to understandable chunks, explained in small practical code examples, where the concepts come in use and make sense to me.If there is a downside to this book, it's how it's using almost half the book explaining the syntax an simple things in C, surely it's important for the absolut beginner. But for someone with a little experience in coding this part feels a little over-done.Overall I love this book, it helped me reach my next level in C++. I would recommend it to everyone interested in learning C / C++ coding, even if you are not interested in Arduino.
Amazon Verified review Amazon
Towaha Apr 10, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book does not teach actual C. It teaches the combination of C and C++. I was a complete dummy before buying my first Arduino. I started reading the book and followed all the line by line words of the book. Finally, I got this book very interesting. The author did do a great effort trying to explain things shortly. To me, it is the best book I borrowed from the school library in programming.
Amazon Verified review Amazon
Rosco Bell Apr 05, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
As a newcomer to Arduino and C programming, I would have appreciated if the book had included solutions to the various exercises, especially in the earlier chapters. I wasted a lot of time trying to solve certain exercises and eventually just gave up on them, effectively learning nothing from them, certainly not what the author had in mind in devising them. Since there is no teacher available to answer questions, there should be some way to get an answer that doesn't involve hours of frustrating trial and error.
Amazon Verified review Amazon
Amazon Customer May 22, 2019
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
It's not easy to understand for the beginners.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.