Arduino C++ Tutorial
0:000:00
Running Arduino C++ code online without owning an Arduino board.
1️⃣ Tinkercad Circuits (Most beginner-friendly)
-
Website: https://www.tinkercad.com/circuits
-
How it works:
- Create a free account.
- Drag an Arduino Uno into the workspace.
- Add components like LEDs, buttons, servos, or ultrasonic sensors.
- Switch to the “Code” tab → choose “Text” mode.
- Write your Arduino C++ code (
setup()
&loop()
), then click Start Simulation.
-
Good for: School robotics, servo motor control, ultrasonic sensor projects.
2️⃣ Wokwi Arduino Simulator (Faster & More Realistic)
-
Website: https://wokwi.com
-
How it works:
- Click Start Project → choose Arduino Uno.
- Add components from the left panel.
- Write your Arduino C++ code in the online editor.
- Click the green Play button to run.
-
Advantages:
- Very fast simulation.
- Works on mobile and PC.
- Supports more hardware (ESP32, Arduino Nano, LCD displays).
-
Good for: Trying more advanced projects beyond Tinkercad.
3️⃣ Arduino Web Editor (Official)
-
Website: https://create.arduino.cc/editor
-
How it works:
- Official Arduino online IDE.
- You can write Arduino C++ and run it only if you have a real board connected — no virtual simulation.
-
Good for: People who have the physical Arduino kit.
⚡ Suggestion
- If you don’t need a physical board yet, start with Tinkercad Circuits for school robotics projects.
- It’s the easiest and already used in many CBSE/ICSE robotics classes.
- When you want faster simulation or more components, try Wokwi.
Color-coded Arduino C++ command cheat sheet tailored for a robotics course in India.
🎯 Arduino C++ Quick Reference — Robotics
1️⃣ Pin Setup
Command | Meaning | Example |
---|---|---|
pinMode(pin, OUTPUT); | Set a pin to send signals. | pinMode(13, OUTPUT); |
pinMode(pin, INPUT); | Set a pin to receive signals. | pinMode(2, INPUT); |
pinMode(pin, INPUT_PULLUP); | Input with internal resistor. | pinMode(2, INPUT_PULLUP); |
2️⃣ Digital I/O
Command | Meaning | Example |
---|---|---|
digitalWrite(pin, HIGH); | Send HIGH voltage (LED ON). | digitalWrite(13, HIGH); |
digitalWrite(pin, LOW); | Send LOW voltage (LED OFF). | digitalWrite(13, LOW); |
digitalRead(pin) | Read HIGH or LOW from pin. | if (digitalRead(2) == HIGH) { ... } |
3️⃣ Analog I/O
Command | Meaning | Example |
---|---|---|
analogRead(pin) | Read analog value (0–1023). | int sensor = analogRead(A0); |
analogWrite(pin, value) | Output PWM (0–255). | analogWrite(9, 128); |
4️⃣ Time Control
Command | Meaning | Example |
---|---|---|
delay(ms); | Pause for ms milliseconds. | delay(1000); (1 sec) |
delayMicroseconds(us); | Pause in microseconds. | delayMicroseconds(10); |
millis() | Time since start in ms. | if (millis() > 5000) { ... } |
5️⃣ Servo Motor Control
Command | Meaning | Example |
---|---|---|
#include <Servo.h> | Include servo library. | Always at top |
Servo name; | Create servo object. | Servo myservo; |
.attach(pin); | Connect servo to pin. | myservo.attach(9); |
.write(angle); | Move servo to angle 0–180°. | myservo.write(90); |
.detach(); | Stop servo signal. | myservo.detach(); |
6️⃣ Ultrasonic Sensor (HC-SR04)
Command | Meaning | Example |
---|---|---|
digitalWrite(trigPin, LOW); | Clear trigger. | |
delayMicroseconds(2); | Wait 2 μs. | |
digitalWrite(trigPin, HIGH); | Send trigger pulse. | |
delayMicroseconds(10); | 10 μs pulse. | |
duration = pulseIn(echoPin, HIGH); | Measure echo time. |
7️⃣ Serial Monitor
Command | Meaning | Example |
---|---|---|
Serial.begin(9600); | Start serial at 9600 baud. | In setup() |
Serial.print(data); | Print without new line. | Serial.print("Value: "); |
Serial.println(data); | Print with new line. | Serial.println(value); |
📌 Color tips for notes:
- Blue → Setup & Library commands
- Green → Output commands
- Orange → Input commands
- Purple → Timing commands
If you want, I can also make this as a single colorful PNG sheet so you can print and keep in your robotics notebook — all commands in one page with colors exactly like above. Do you want me to prepare that image?