Last Updated 13/11/2024

Arduino/C++ Lessons Various Arduino tutorial courses

Learning to program takes time and patience. For many it means learning not only the programming side but the electronics as well. By the time I started to program the Arduino I had already learnt a number of different languages and so followed the tradition way of learning to program.

That means learning the core structures of the language and then using that core to control components. It's the way I have always learnt and if I ever have to learn another language it is the method I would always choose. The upside of this method is you can start with just the Arduino and add a starter kit later.
The downside is that you don't get to see LED's turning on and off or press buttons etc in the early lessons. That all comes once you understand the language. However, you will be able to understand code quicker and this has advantages later as you wish to add other peoples code into your own projects.

Click here for the Traditional Language Course.

Getting Started and the Arduino IDE


Preperation 1: Getting Started - What you need, Choosing a kit, downloading the Arduino IDE 17/02/2024

How to Download and Install Arduino IDE 14/07/2021

Getting Started - Arduino IDE quick tour (Version 2.3.0 or greater) 15/02/2024

A Tour of the Arduino IDE (Classic Version 1.8) 15/07/2021

Basics of C++ - Traditional Language Learning

These C++ lessons are lessons in learning C++ in the way that a traditional programmer would learn to program any computer language. The initial sections may not have any blinking LED's, but it is designed to give a good understanding of programming structure to enable the programmer to understand the code that others have written as well as understanding the various errors that occur.

Although C++ is used by Arduino IDE and desktop programming IDE's and a lot of the syntax and structure is the same. Desktop programming tends to output to the screen in a way that the Arduino IDE does not makng a lot of code examples difficult to understand for beginners.

A simple example is the" Hello World" code below, Arduino IDE on the left and desktop C++ on the right.

C++

With all the lessons I have tried to reuse as much of the previous lessons as possible, introducing new items lesson by lesson, while reinforcing what has been learnt in earlier lessons.

Arduino 2.3 IDE Series

I decided to re record and try and improve on the original series of lessons using better cameras and production software.

Lesson (Click to watch)
Lesson Resources
Lesson 1 Getting Started

Arduino IDE Arduino Integrated Development Envirment software. The program used to write code and upload it to the Arduino boards.

CH340 Drivers Many boards use the CH340 communication chip and therefore require CH340 drivers to be installed.

Other information:

Windows 11 and CH340 drivers Under Windows 11 there has been a driver issue with a few boards using a certain type of CH340 chip. This includes the UNO and some ESP8266 boards. If you have issues with your board not being recognised this video explains how to fix the issue.

Lesson 2 Syntax and Serial Monitor


Basic syntax, line ends, brackets and common errors and how to spot them.

Creating a variable.

The basics of using the Serial Monitor
The differences between sending text and numeric values.

 

Download the code for Lesson 2

Ascii Table

Lesson 3 Controlliong timings with if() and millis()

How to control program timings using if() and millis()

Controlling multiple items with different timings.

Download the code for Lesson 3

 

Lesson 4 Digital Pins digitalWrite()

Introduction to controlling outputs with digitalWrite().

Using pinMode()

Controlling multiple LED's with different timings.

Download the code for Lesson 4

Click image for larger versionLesson 4 Circuit Diagram

Lesson 5 Digital Pins digitalRead(), pull down resistors, debouncing buttons

Introduction to controlling inputs.

Introduction to digitalRead() and pull down resistors.

Basic button debouncing and why it is needed.

Download the code for Lesson 5

Click image for larger versionLesson 5 Circuit Diagram

Arduino C++ Lesson 5B, Arduino UNO with toggle switches

This is an extra lesson that has been added to show how to control items with toggle switches with the Arduino UNO, rather than the usually push to contact switches that come in most kits.

As always the code is non blocking (state machine) style code and in the example a pair of LED's are turned on and off although the code can be easily adated to control other items.

Download the code for Lesson 5b

Technical explanation of the different types of toggle switches

Click image for larger versionLesson 5B Circuit Diagram

Lesson 6 Analog Pins analogRead(), pmap() function, switch() statement

Reading analog Pins with analogRead()

map() function

float variable type

switch() statement

Download the code for Lesson 6

Click image for larger versionLesson 5 Circuit Diagram

Lesson 7 Combining Sensors

Combining Sensors and Outputs.

PIR Sensor
Photoresistor
LED
Relay

if( && ) control structure

Component timers using millis()

Download the code for Lesson 7

Click image for larger versionLesson 7 Circuit Diagram

Lesson 8 Combining sensors part 2

Combining Sensors and Outputs.

2 x IR Sensor
LED's

if( || ) control structure (if(OR))

Component timers using millis() and process control using switch() and State

Download the code for Lesson 8

Click image for larger versionLesson 7 Circuit Diagram

Lesson 9 - Arrays and for() loop

Array basics

Using the for() loop

random()

Download the code for Lesson 9

Click image for larger versionLesson 7 Circuit Diagram

Lesson 10 - Arduino UNO servos

Servos

Servo Library
individual Servos
Multiple Servos
Servo Speed control

Non blocking Code

Download the code for Lesson 10

Click image for larger versionLesson 10 Circuit Diagram UNO and Servos

Lesson 11 Arduino UNO advanced servo control

Advanced Servo Control

This lessons shows how to prapare the servo code so that it can be triggered by buttons/sensors/potentiometer etc.

Servo control code is placed in arrays and functions to allow for easy expansion.

Servos speed and direction controlled by buttons

Servo position controlled by potentiometer

This code can control multiple servos.

Non blocking Code

Download the code for Lesson 11

The circuit remains the same as Lesson 10

Click image for larger versionLesson 10 Circuit Diagram UNO and Servos

Lesson 12 - 28BYJ-48 ULN2003 Arduino UNO tutorial

Arduino UNO with ULN2003 and 28BYJ-48 Stepper motor tutorial using non blocking (State Machine) examples.


This is the first part of how to use a stepper motor in Arduino projects.
This lesson focuses on the basics of creating non blocking code.

Download the code for Lesson 12

Click image for larger version
Lesson 12 Circuit Diagram UNO and ULN2003 28BYJ-48 Stepper Motor

Lesson 12 - 28BYJ-48 ULN2003 Arduino UNO tutorial

Arduino UNO with ULN2003 and 28BYJ-48 Stepper motor tutorial Part 2 using non blocking (State Machine) examples.


This lessons simplifies the code to a function as well as showing how to change the stepper speed, acceleration and decceleration, repeating movement cycles as well as showing how to make the stepper move constantly using the function created.

In the examples changes are sent to the stepper using button commands but these could be changed to sensors to suit your project.

Download the code for Lesson 13

Click image for larger version
Lesson 12 Circuit Diagram UNO and ULN2003 28BYJ-48 Stepper Motor

Lesson 14 - External Interrupts part 1 - Rotary Encoder

How to set up and use External Interrupts with the Arduino UNO.

Part 1 deals with slower speed interrupts and uses the rotary encoder to generate the interrupt.

Different examples of how to use the Rotary Encoder with interrupts are in the sample code.

Download the code for Lesson 14

Click image for larger version
Lesson 14 Circuit Rotary Encoder

Lesson 14 - External Interrupts part 1 - Rotary Encoder

How to set up and use External Interrupts with the Arduino UNO.

Part 2 deals with reading signals from devices and shows the basics of how to process the signals.

Download the code for Lesson 15

There is no circuit diagram for this lesson. However the following links may be useful.

Understanding FIFO buffers

DCC decoder circuit for Arduino UNO/ESP32

Lesson 16 - Arduino Multi Mode Button

In this lesson a single button will be used to change the mode in the Arduino sketch allowing the Arduino to change the LED pattern depending on the mode.

The sketch shows how to combine the a debounced button with millis() being used to control the LED pattern timings.

Download the code for Lesson 16

Click image for larger version
Lesson 16 Multi mode button circuit

1602A I2C LCD Screen with Arduino UNO

Using the 1602A I2C LCD screen with the Arduino UNO including how to
deal with string padding to get a better display.

1602A I2C LCD Screen

Download the code for Lesson 17

Click image for larger version1602A I2C LCD Screen with Arduino UNO Circuit diagram

1602A I2C LCD Screen

8 - Project design, choosing sensors for railway speedometer project

In this lesson I will go through the steps and considerations when choosing sensors for a project, in this case a speedometer for a model railway.
The project will use the LCD screen from lesson 17, a debounced button from Lesson 5 and the IR sensors from Lesson 7.

Download the code for Lesson 18

Click image for larger version
Lesson 18 Railway speedometer

 

Arduino 1.8 IDE Series

This is the original Arduino C++ course that was created in 2021 using the Arduino Classic (version 1.8 IDE). It is being replaced by the new series.

Lesson 1: Basic sketch layout and how to comment code 15/07/2021

Lesson 2: "Hello World" Basics of printing to Serial Window 17/07/2021

Lesson 3: Using "if else" to control code 19/07/2021

Lesson 4: Using "for loop" to control code 21/07/2021

Lesson 5: Using "switch" to control code 21/07/2021

Lesson 6: Basic Numeric variables, boolean, byte, int, unsigned int, long, unsigned long 23/07/2021

Lesson 7: delay() v's millis(), controlling timing of programs 23/07/2021

Lesson 8: Basic mathematics, addition, subtraction, multiplication and division 27/07/2021

Lesson 9: Basic of creating and using functions 28/07/2021

Lesson 10: Using Global and Local variables 11/08/2021

Lesson 11: Arrays 28/08/2021

Arduino Functions

Functions 1 : digitalWrite() Using digital pins to turn things on and off 05/08/2021

Functions 2 : digitalRead() Reading a digital pin and pullup resistors 11/08/2021

Functions 3 : analoglRead() Reading an Analog pin, converting to Voltage 03/09/2021

Functions 4 : tone() and noTone(), creating sounds with a piezo speaker 24/09/2021

map() function 19/03/2024

How To's

How To 1 : Debouncing buttons 15/09/2021

How To 2 : Multiple HC-SR04 Ultrasonic sensors using bit shifting with 74HC595 05/10/2021

How To 3 : Issues when joining two sketches together 22/10/2021

How To 4 : Creating a Project - Alarm example 25/10/2021

How To 5 : Nema 17 stepper motor using micros() for timing. 08/12/2021

How To 6 : FIFO (Circular) Buffer 29/04/2024

Servo speed control with millis()

Problems and Errors

Windows 11 CVH340 driver issues 10/02/2024

Fixing a Slow IDE 10/02/2024

Arduino IDE Error messages and solutions 30/07/21

Contact

If you have a particular subject you want covered please email the address in this image: and use Arduino/C++ Lessons Various Arduino tutorial courses as a reference.
Please be aware that this is a hobby that fits around work so please be patient.