Lesson 2: Core Programming Basics – Variables, Data Types, and Operators

Lesson 2: Core Programming Basics – Circuits and Coding 101


📌 Introduction

Welcome back to Lesson 2 of Circuits and Coding 101! In the last lesson, we introduced programming, microcontrollers, and how to write and upload your first program.


🎯 What You’ll Learn Today

  • Variables – How to store and manipulate data
  • Data Types – Understanding different value types
  • Constants – How to use fixed values in your code
  • Operators – Performing math and logic operations
  • Serial Communication – Sending and receiving data
  • Hands-on exercises – Using a potentiometer, photoresistor, and button


📝 Variables and Data Types

What are Variables?

Variables act as containers for data that your program can use and modify.

Common Data Types in Arduino:

  • int – Whole numbers (e.g., 10, -5)
  • float – Decimal numbers (e.g., 3.14, -0.01)
  • boolean – True or false values (truefalse)
  • char – A single character (e.g., 'A''B')

🔒 Constants: Fixed Values in Code

Why Use Constants?

Constants store values that do not change while the program is running.

🔢 Operators: Performing Actions in Code

Arithmetic Operators: +-*/%

Comparison Operators: ==!=<><=>=

Assignment Operators: =+=-=*=/=

✅ Wrap-Up & Next Steps

What You Learned Today:

  • How to declare and use variables and constants
  • Understanding data types and operators
  • Using Serial Communication to send and receive data
  • Building circuits with a potentiometer, photoresistor, and button


💡 Homework:

Write a program that:

  • Declares and uses three different types of variables
  • Prints their values to the Serial Monitor
  • Uses a button input to control an LED


🎉 Great job!

In the next lesson, we’ll explore control structures, allowing us to make more dynamic programs.


🔔 Stay tuned, and happy coding!


USEFUL LINKS:

Push Button Video --> CLICK HERE