arduino

The Arduino board we’ve at home is Arduino Uno. Arduino Uno is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header and a reset button.

Arduino Uno board contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.

Using Arch homepc2 to learn Arduino. Instead of Arduino-IDE, decided to use Emacs as IDE with arduino-mode and arduino-cli. Arduino uses C++ .

Software

Reply from Claude on lightweight alternatives for IoT:

PHP Implementation:

Pros:

Easier to write and maintain for many developers More extensive ecosystem and libraries Can be used for more complex processing if needed

Cons:

Slightly higher overhead due to PHP-FPM process management Potentially slower for very simple operations

Lua in Nginx:

Pros:

Lower overhead, as it runs directly in Nginx Potentially faster for simple operations Can handle requests without invoking a separate process

Cons:

Less familiar to many developers More limited ecosystem compared to PHP

Lightweight Alternatives for IoT:

a. Node.js with Express:

Lightweight and efficient Event-driven, non-blocking I/O model Good for handling many concurrent connections

b. Python with Flask or FastAPI:

Simple and lightweight FastAPI is particularly fast and good for API development

c. Golang HTTP server:

Extremely efficient and lightweight Compiled language, resulting in fast execution

d. Rust with Actix or Rocket:

Very efficient and safe Good for systems with limited resources

e. MQTT (Message Queuing Telemetry Transport):

Specifically designed for IoT applications Lightweight publish-subscribe messaging protocol Efficient for constrained devices and low-bandwidth networks

For your specific use case on a Pi Zero handling uploads from ESP devices, here are my recommendations:

If you’re comfortable with Lua and your current setup is working well, stick with the Lua module in Nginx. It’s likely the most efficient for your simple upload scenario. If you need more complex processing or are more comfortable with PHP, the PHP implementation would be fine and unlikely to cause significant performance issues on a Pi Zero for your use case. For a more IoT-focused approach, consider MQTT. It’s designed for IoT scenarios and could be more efficient for communication between your ESP devices and the server. If you’re open to learning a new technology, Go (Golang) could provide an excellent balance of ease of use and efficiency for your IoT application.

The “best” choice depends on your specific requirements, your familiarity with different technologies, and the exact nature of your IoT application. For simple file uploads from ESP devices, your current Lua in Nginx setup is likely already quite optimal.

Arduino-cli

Emacs arduino-mode

To use Emacs as IDE, installed and modified the arduino-mode.el to include information related to arduino-executable and modified the command in functions arduino-upload and arduino-verfiy:

(defcustom arduino-executable "/usr/bin/arduino-cli"
(list arduino-executable "compile" buffer-name "--fqbn" "arduino:avr:uno") # compile only
(list arduino-executable "upload" (buffer-file-name) "-v" "-p" "/dev/ttyACM0" "--fqbn" "arduino:avr:uno") # upload only
(list arduino-executable "compile" (buffer-file-name) "-v" "--upload" "-p" "/dev/ttyACM0" "--fqbn" "arduino:avr:uno") #compile and upload

arduino-cli

Installed arduino-cli using pacman. Installed ardunino-mode from install-package option of emacs.

After installing the package arduino-cli, added the user prabu to uucp group.

prabu@homepc2 ~> sudo usermod -a -G uucp $USER

Sources: https://wellys.com/posts/esp32_cli/ β†—

platformio

Sketch Conversion Process

Step-by-Step Conversion Process for Each Sketch

Example Directory Structure for Multiple Projects

Here’s how you can organize multiple projects in PlatformIO:

Projects/
β”œβ”€β”€ Project1/
β”‚   β”œβ”€β”€ include/
β”‚   β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── main.cpp
β”‚   └── platformio.ini
β”œβ”€β”€ Project2/
β”‚   β”œβ”€β”€ include/
β”‚   β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── main.cpp
β”‚   └── platformio.ini
β”œβ”€β”€ Project3/
β”‚   β”œβ”€β”€ include/
β”‚   β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── main.cpp
β”‚   └── platformio.ini
└── ...

This structure ensures that each sketch is treated as a separate project in PlatformIO, with its own configuration and source files.

Initialize a Project

cd path/to/ExampleProject  # Navigate to the project directory

# Initialize PlatformIO (if not done already)
pio init --board esp32cam

Compile and upload a project

cd path/to/ExampleProject  # Navigate to the project directory

# Initialize PlatformIO (if not done already)
pio init --board esp32cam

# Compile the project
pio run

# Upload the project to the board
pio run --target upload

# Monitor the serial output
pio device monitor

Arduino Uno

Identify FQBN and port

Identify the board’s Fully Qualified Board Name (FQBN) and the port. For Arduino Uno, identified the board name and installed the necessary drivers as per arduino-cli quick start guide in Arduino website.

prabu@homepc2 ~ [1]> arduino-cli board list
Port         Protocol Type              Board Name  FQBN            Core
/dev/ttyACM0 serial   Serial Port (USB) Arduino Uno arduino:avr:uno arduino:avr
/dev/ttyS0   serial   Serial Port       Unknown

Compile and Upload code

prabu@homepc2 ~> arduino-cli --fqbn arduino:avr:uno compile sketches/MyFirstSketch
prabu@homepc2 ~> arduino-cli upload -v -p /dev/ttyACM0 --fqbn arduino:avr:uno sketches/MyFirstSketch

Serial Communication


prabu@homepc2 ~> arduino-cli monitor -p /dev/ttyACM0
Connected to /dev/ttyACM0! Press CTRL-C to exit.

ESP8266

Configure Board Manager

Edit the configuration file, to add an entry in the additional_urls list under board_manager.

prabu@homepc2 ~/sketches> cat ~/.arduino15/arduino-cli.yaml
board_manager:
    additional_urls:
      # []
      - http://arduino.esp8266.com/stable/package_esp8266com_index.json

Download and Install cores

Now update the index of cores. You should see that the ESP8266 index has been downloaded.

prabu@homepc2 ~/.a/p/a/t/a/6/etc [0|1]> arduino-cli core update-index
Downloading index: package_index.tar.bz2 downloaded
Downloading index: package_esp8266com_index.json downloaded
Downloading index: package_index.tar.bz2 downloaded
Downloading index: package_esp8266com_index.json downloaded

Install the ESP8266 cores.

prabu@homepc2 ~/.a/p/a/t/a/6/etc> arduino-cli core install esp8266:esp8266
Downloading packages...
esp8266:xtensa-lx106-elf-gcc@3.1.0-gcc10.3-e5f9fec downloaded
esp8266:mkspiffs@3.1.0-gcc10.3-e5f9fec downloaded
esp8266:mklittlefs@3.1.0-gcc10.3-e5f9fec downloaded
esp8266:python3@3.7.2-post1 downloaded
esp8266:esp8266@3.1.2 downloaded
Installing esp8266:xtensa-lx106-elf-gcc@3.1.0-gcc10.3-e5f9fec...
Configuring tool....
esp8266:xtensa-lx106-elf-gcc@3.1.0-gcc10.3-e5f9fec installed
Installing esp8266:mkspiffs@3.1.0-gcc10.3-e5f9fec...
Configuring tool....
esp8266:mkspiffs@3.1.0-gcc10.3-e5f9fec installed
Installing esp8266:mklittlefs@3.1.0-gcc10.3-e5f9fec...
Configuring tool....
esp8266:mklittlefs@3.1.0-gcc10.3-e5f9fec installed
Installing esp8266:python3@3.7.2-post1...
Configuring tool....
esp8266:python3@3.7.2-post1 installed
Installing platform esp8266:esp8266@3.1.2...
Configuring platform....
Platform esp8266:esp8266@3.1.2 installed

Identify FQBN and port

Identify the board’s Fully Qualified Board Name (FQBN) and the port

prabu@homepc2 ~/.a/p/a/t/a/6/etc> arduino-cli board list
Port         Protocol Type              Board Name FQBN Core
/dev/ttyS0   serial   Serial Port       Unknown
/dev/ttyUSB0 serial   Serial Port (USB) Unknown
prabu@homepc2 ~/.a/p/a/t/a/6/etc> arduino-cli board listall | grep -i 'nodemcu'
NodeMCU 0.9 (ESP-12 Module)      esp8266:esp8266:nodemcu
NodeMCU 1.0 (ESP-12E Module)     esp8266:esp8266:nodemcuv2

Source: https://ericslenk.com/posts/getting-started-with-the-nodemcu-esp8266-and-arduino-cli β†—

Compile and Upload code

prabu@homepc2 ~> arduino-cli compile --fqbn esp8266:esp8266:nodemcuv2 sketches/MyFirstSketch
prabu@homepc2 ~> arduino-cli upload --port /dev/ttyUSB0 --fqbn esp8266:esp8266:nodemcuv2 MyFirstSketch

Serial Communication

Serial communication is quite tricky for ESP8266. Need to use special serial monitoring tool like picocom where DTR and RTS signals needs to be turned OFF so as not to interupt the running sketch. Otherwise, on opening serial monitor, running sketch stops.

prabu@homepc2 ~> picocom -b 115200 --lower-dtr --lower-rts /dev/ttyUSB0

ESP32

PIN diagram of esp32-CAM ?

Configure Board Manager

Edit the configuration file, to add an entry in the additional_urls list under board_manager.

prabu@homepc2 ~> cat ~/.arduino15/arduino-cli.yaml
board_manager:
   additional_urls:
      # []
      - http://arduino.esp8266.com/stable/package_esp8266com_index.json
      - https://espressif.github.io/arduino-esp32/package_esp32_index.json

Download and Install cores

Update the index of cores. You should see that the ESP32 index has been downloaded.

prabu@homepc2 ~> arduino-cli core update-index
Downloading index: package_index.tar.bz2 downloaded
Downloading index: package_esp8266com_index.json downloaded
Downloading index: package_esp32_index.json downloaded

Install the core. The command automatically downloads the packages

prabu@homepc2 ~> arduino-cli core install esp32:esp32
Downloading packages...
esp32:esp32-arduino-libs@idf-release_v5.1-442a798083 42.41 MiB / 356.11 MiB [===>--------------------------]  11.91% 04m52s

Around 1GB of new packages got installed in home/prabu.arduino15/staging/packages/

Identify FQBN and port

As per the website cytron given below, the board FQBN should be esp32:esp32:esp32wrover for the board model number HW-818. However the pin configuration is not matching with the board and the chip is only ESP32-S. So decided to use esp32cam as the pin and chip matches with AI Thinker board but has an extra usb.

prabu@homepc2 ~> arduino-cli board list
Port          Protocol Type              Board Name                   FQBN                      Core
192.168.1.231 network  Network Port      NodeMCU 1.0 (ESP-12E Module) esp8266:esp8266:nodemcuv2 esp8266:esp8266
/dev/ttyS0    serial   Serial Port       Unknown
/dev/ttyUSB0  serial   Serial Port (USB) Unknown
prabu@homepc2 ~> arduino-cli board listall |grep 'AI Thinker ESP32-CAM'
AI Thinker ESP32-CAM                               esp32:esp32:esp32cam

https://www.cytron.io/tutorial/getting-started-with-esp32-cam β†—

Flashing mode in ESP32-CAM

Important: GPIO 0 needs to be connected to GND so that you’re able to upload code.

GPIO 0 determines whether the ESP32 is in flashing mode or not. This GPIO is internally connected to a pull-up 10k Ohm resistor.

When GPIO 0 is connected to GND, the ESP32 goes into flashing mode and you can upload code to the board.

To make the ESP32 run β€œnormally”, you just need to disconnect GPIO 0 from GND.

Compile and Upload code

prabu@homepc2 ~/sketches (master)> arduino-cli compile --fqbn esp32:esp32:esp32cam blink
prabu@homepc2 ~/sketches (master)> arduino-cli compile --upload --fqbn esp32:esp32:esp32cam --port /dev/ttyUSB0 blink

Serial Communication

Serial monitoring can be done using arduino-cli or special tool like picocom.

prabu@homepc2 ~> arduino-cli monitor -p /dev/ttyUSB0 --config baudrate=115200
Monitor port settings:
baudrate=115200
Connected to /dev/ttyUSB0! Press CTRL-C to exit.
prabu@homepc2 ~> picocom -b 115200 /dev/ttyUSB0

References

https://github.com/easytarget/esp32-cam-webserver β†— https://github.com/espressif/arduino-esp32/tree/master/libraries/ESP32/examples/Camera/CameraWebServer β†—

OTA

Uploading code using OTA is also Available

arduino-cli upload --fqbn "esp8266:esp8266:nodemcuv2" --board-options "ip=lm6f" --protocol network --port "192.168.1.113" "OTA_Test"

source: https://github.com/esp8266/Arduino/issues/8962#issue-1812978154 β†—

ESP on the Internet

****Firebase

  1. Created a new Firebase Project ESP-demo Project ID: esp-demo-4e84c Project number : 84228781455
  2. Set Email and Password as Authentication Mechanism
  3. Added the following user Google Email ID with password as 0nly$E$p User ID is 2p7ZZrqXptc3euZolF2CrjEC3sJ2
  4. Got the Project API Key as follows from Project Settings: Web API key AIzaSyCevXSdKPKzElrWz3JxSFdiDH0c5fs5Ris
  5. Created Realtime databased and with Test Mode. The database web URL is https://esp-demo-4e84c-default-rtdb.asia-southeast1.firebasedatabase.app/ β†—
  6. Uploaded the Nodes database as json. The json can be found here /home/prabu/Books/arduino/NodeMCU/Firebase_Tutorial
  7. Install the Firebase Arduino Client Library for ESP8266 and ESP32 to Arduino IDE.
  1. Created/Copied a new sketch named Firebasedemo.ino with above information to connect to Firebase database for 2-way Communication.
  2. firebase config object
   // Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
const firebaseConfig = {
  apiKey: "AIzaSyCevXSdKPKzElrWz3JxSFdiDH0c5fs5Ris",
  authDomain: "esp-demo-4e84c.firebaseapp.com",
  databaseURL: "https://esp-demo-4e84c-default-rtdb.asia-southeast1.firebasedatabase.app",
  projectId: "esp-demo-4e84c",
  storageBucket: "esp-demo-4e84c.appspot.com",
  messagingSenderId: "84228781455",
  appId: "1:84228781455:web:32967bbe7eb677bd7c47fa"
};

Initialize Firebase

const app = initializeApp(firebaseConfig);

Sources:

https://randomnerdtutorials.com/firebase-control-esp32-gpios/ β†— https://github.com/aabbtree77/esp32-vpn β†—

Sample Sketches

The example Arduino sketches built in to the Arduino IDE can be found here https://github.com/arduino/arduino-examples/tree/main β†—

Libraries

NTPClient https://github.com/arduino-libraries/NTPClient β†—

Connect to an NTP server and get information like current time etc..

prabu@homepc2 ~/B/a/N/Firebase_Tutorial> arduino-cli lib install "Firebase Arduino Client Library for ESP8266 and ESP32"
prabu@homepc2 ~/B/a/N/Firebase_Tutorial> arduino-cli lib install FirebaseClient
Downloading FirebaseClient@1.1.1...
FirebaseClient@1.1.1 downloaded
Installing FirebaseClient@1.1.1...
Installed FirebaseClient@1.1.1
prabu@homepc2 ~/B/a/N/Firebase_Tutorial> arduino-cli lib list
Name                                                  Installed Available    Location              Description
Firebase Arduino Client Library for ESP8266 and ESP32 4.4.14    -            LIBRARY_LOCATION_USER -
FirebaseClient                                        1.1.1     -            LIBRARY_LOCATION_USER -

prabu@homepc2 ~/B/a/N/Firebase_Tutorial> arduino-cli lib search FirebaseJson
....
prabu@homepc2 ~/B/a/N/Firebase_Tutorial> arduino-cli lib install FirebaseJson
Downloading FirebaseJson@3.0.7...
FirebaseJson@3.0.7 downloaded
Installing FirebaseJson@3.0.7...
Installed FirebaseJson@3.0.7
prabu@homepc2 ~/B/a/N/Firebase_Tutorial> arduino-cli lib list
Name                                                  Installed Available     Location              Description
Firebase Arduino Client Library for ESP8266 and ESP32 4.4.14    -             LIBRARY_LOCATION_USER -
FirebaseClient                                        1.1.1     1.1.8         LIBRARY_LOCATION_USER Async Firebase Client library for Ard...
FirebaseJson                                          3.0.7     -             LIBRARY_LOCATION_USER -

prabu@homepc2 ~/B/a/N/Firebase_Tutorial> arduino-cli lib upgrade
Downloading FirebaseClient@1.1.8...
FirebaseClient@1.1.8 downloaded
Installing FirebaseClient@1.1.8...
Replacing FirebaseClient@1.1.1 with FirebaseClient@1.1.8...
Installed FirebaseClient@1.1.8
prabu@homepc2 ~/B/a/N/Firebase_Tutorial> arduino-cli lib list
Name                                                  Installed Available    Location              Description
Firebase Arduino Client Library for ESP8266 and ESP32 4.4.14    -            LIBRARY_LOCATION_USER -
FirebaseClient                                        1.1.8     -            LIBRARY_LOCATION_USER -
FirebaseJson                                          3.0.7     -            LIBRARY_LOCATION_USER -

For Information Only

main() function

Arduino build process creates an intermediate file that includes the sketch code and the following additional statements:

int main( void )
{
  init();

  initVariant();

#if defined(USBCON)
  USBDevice.attach();
#endif

  setup();

  for (;;)
    {
    loop();
    if (serialEventRun) serialEventRun();
    }

  return 0;
}

init() function initializes arduino hardware, then setup() and loop() from the sketch are called. Since loop is called over and over and the for loop is never exited, return satatement is never executed.

Hardware

official Uno starter Kit

https://robu.in/product/arduino-starter-kit-with-170-pages-project-book/ β†—

Reddit Starter components

https://us.reddit.com/r/AskElectronics/wiki/starter_components#wiki_resistors β†—

Solar powered setup

Photovoltaic Panel (5V, 3W) I = 600mA TP4056 1A Li-Ion Battery Charging Board Micro USB with Current Protection Battery (3.7V, 2000mAh) MT3608 based DC/DC Converter - between the battery and the device to raise the voltage from 3.7V to 5V. https://www.techrm.com/solar-power-for-arduino-esp8266-and-iot-complete-guide-to-energy-independence/ β†—

List of Hardware items

The Arduino Uno board currently being used at home belongs to Srivatsan, Aniruth’s school friend.

krishanth

Items brought by Krishanth from his academy DIYA.

Naresh Electronics

In 2023

2024-04-24

10 Resistors of 2 each from Naresh @β‚Ή10

2024-04-30

Ktron.in

2024-04-25

1K Ohm resistor and 10M Ohm out of stock.

[Order #109615] (April 25, 2024)
Product 	Quantity 	Price
Resistor 100 Ohms 0.25W 5% TH 	50 	β‚Ή10.00
Resistor 220 Ohms 0.25W 5% TH 	50 	β‚Ή10.00
Resistor 560 Ohms 0.25W 5% TH 	50 	β‚Ή10.00
Resistor 4.7K Ohms 0.25W 5% TH 	50 	β‚Ή10.00
Resistor 10K Ohms 5% 0.25W TH 	50 	β‚Ή10.00
Resistor 1M Ohms 0.25W 5% TH 	50 	β‚Ή10.00
Male to Female Jumper Wire 40pin - 20cm Length 	1 	β‚Ή38.90
Male to Male Jumper Wire 40pin - 20cm Length 	1 	β‚Ή38.99
Female to Female jumper wire 40pin - 20cm Length 	1 	β‚Ή38.90
Berg Strip Female 40 pins - 40x1 - Brass 	4 	β‚Ή30.40
Header Pins 40x1 - 2.54mm Pitch - Brass 	4 	β‚Ή22.00
10K Ohms 3296 Multiturn Trimpot Potentiometer 	5 	β‚Ή43.00
3V Buzzer - PCB Mountable 	1 	β‚Ή12.95
102 - 1K Ohms NTC Thermistor - 1K NTC 	3 	β‚Ή21.00
Diode 1N4148 TH 	25 	β‚Ή17.50
1N4007 Rectifier Diode - DO-41 	25 	β‚Ή19.00
Rocker Switch DPDT - 6A 	1 	β‚Ή21.24
Rocker Switch SPST - 6A 	2 	β‚Ή14.86
LM2596HVS Step Down Module 	2 	β‚Ή120.00
NodeMCU ESP8266 CH340G Wifi Development Board 	1 	β‚Ή187.00
Subtotal: 	β‚Ή685.74
Shipping: 	β‚Ή70.80 via Tirupati Courier (Delivery within 2 to 7 days)
Payment method: 	Credit Card / Debit Card / UPI / Netbanking / PayTM
Total: 	β‚Ή756.54 (includes β‚Ή115.40 18% IGST)

Robu.in

2024-05-02

[Order #2035210] (May 2, 2024) Product Quantity Price SW-520D Vibration Sensor Metal Ball Tilt Switch (pack of 2) 1 β‚Ή 15.00 4N35 IC - Optocoupler Phototransistor IC 1 β‚Ή 21.00 LM2596S DC-DC Buck Converter Plastic Case 2 β‚Ή 46.00 Tact Switch TVDP01- 6.0X6.0mm 5 β‚Ή 8.85 SSR-40DA Solid State Relay Module 3-32VDC/24-380VAC 40A 1 β‚Ή 294.00 Sound Detection Module Sensor for Intelligent Vehicle Compatible With Arduino 1 β‚Ή 40.00 Anti Static ESD Wrist Strap Elastic Band with Clip for Sensitive Electronics Repair Work Tool 1 β‚Ή 38.00 Soil Moisture Meter, Soil Humidity Sensor, Water Sensor, Soil Hygrometer for Ardunio 1 β‚Ή 36.00 Universal Aluminium Heat Sink 11 x 11 x 5 mm - 5Pcs. 1 β‚Ή 29.00 5-200V SSR-25DD Solid State Relay 1 β‚Ή 374.00 NodeMCU ESP8266 Serial Port Baseboard Lua WIFI Development Board 1 β‚Ή 102.00 Subtotal: β‚Ή 1,003.85

To Buy:

Books and References

Downloaded few books related to Arduino

  1. Arduino Cookbook
  2. Getting Started With Arduino 3rd Edition
  3. Making Things Talk 1st and 2nd Edition by Tom Igoe
  4. Physical Computing Sensing and Controlling
  5. Lowtech sensors and actuators

https://circuitdigest.com/microcontroller-projects/smart-irrigation-system-using-esp32-and-blynk-app β†—

Lessons

Hardware

pin should be limited to 20 milliamps.

Array Errors

In arrays it is a common error to access an element beyond the dimension of the array. The below idea prevents this error.

const int PIN_COUNT = 4; // define a constant for the number of elements
int inputPins[PIN_COUNT] = {2,3,4,5};
   for(int index = 0; index < PIN_COUNT; index++)
     pinMode(inputPins[index], INPUT);

Source:Cookbook pg:27

Bluetooth HC-05

Setup for connecting HC-05 Bluetooth Module code for Arduino. The below code is heavily influnced by the electronicwings article referred below:

#include<SoftwareSerial.h>
/* #define ledPin 7 */
const int ledPin = 9;
/* char state = 1; */
int state = 1;
/* Create object named bt of the class SoftwareSerial */
SoftwareSerial bt(2,3); /* (Rx,Tx) */

void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  bt.begin(9600);
  Serial.begin(9600); // Default communication rate of the Bluetooth module
  /* Serial.begin(38400); // Default communication rate of the Bluetooth module */
}

void loop() {
  if(bt.available() > 0){ // Checks whether data is comming from the serial port
    state = bt.read(); // Reads the data from the serial port
 }
 if (state == '0') {
  digitalWrite(ledPin, LOW); // Turn LED OFF
  Serial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON"
  bt.println("BTLED: OFF"); // Send back, to the phone, the String "LED: ON"
  state = 0;
 }
 else if (state == '1') {
  digitalWrite(ledPin, HIGH);
  Serial.println("LED: ON");;
  bt.println("BTLED: ON");;
  state = 0;
 }
}

Below code from electronicwings article cited below:


#include<SoftwareSerial.h>

/* Create object named bt of the class SoftwareSerial */
SoftwareSerial bt(2,3); /* (Rx,Tx) */

void setup() {
  bt.begin(9600); /* Define baud rate for software serial communication */
  Serial.begin(9600);  /* Define baud rate for serial communication */
}

void loop() {
  if (bt.available()) /* If data is available on serial port */
    {
        Serial.write(bt.read());      /* Print character received on to the serial monitor */
    }
}

Software

Functions with references must be declared before use. “&” indicate a parameter is a references. Function declaration(different from function header in a function definition) is a prototype which is usually done automatically by Arduino build process.

Conditional Debug

Conditional Debug is explained in ConditionalDebug .

To Learn

What do i want from Arduino


Β© Prabu Anand K 2020-2026