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
Create Project Directory:
For each sketch, create a new directory with a name that describes the project. For example, if your sketch was named example.ino, create a directory called ExampleProject.
Create Subdirectories:
Inside each project directory, create the following subdirectories:
include/ lib/ src/
Move and Rename Sketch File:
Rename your .ino file to main.cpp and move it into the src/ directory of the respective project.
Create platformio.ini:
In the root of each project directory, create a platformio.ini file with the necessary configuration. For instance, for an ESP32-CAM project, the platformio.ini might look like this:
[env:esp32cam] platform = espressif32 board = esp32cam framework = arduino monitor_speed = 115200 upload_port = /dev/ttyUSB0 lib_deps = ESP Async WebServer StringArray SPIFFS
Summary
‘pio init’ command creates Subdirectories and platformio.ini file in the current directory. So finally, our ExampleProject directory should look like below:
ExampleProject/ ├── include/ ├── lib/ ├── src/ │ └── main.cpp └── platformio.ini
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
- Created a new Firebase Project ESP-demo Project ID: esp-demo-4e84c Project number : 84228781455
- Set Email and Password as Authentication Mechanism
- Added the following user Google Email ID with password as 0nly$E$p User ID is 2p7ZZrqXptc3euZolF2CrjEC3sJ2
- Got the Project API Key as follows from Project Settings: Web API key AIzaSyCevXSdKPKzElrWz3JxSFdiDH0c5fs5Ris
- Created Realtime databased and with Test Mode. The database web URL is https://esp-demo-4e84c-default-rtdb.asia-southeast1.firebasedatabase.app/↗
- Uploaded the Nodes database as json. The json can be found here /home/prabu/Books/arduino/NodeMCU/Firebase_Tutorial
- Install the Firebase Arduino Client Library for ESP8266 and ESP32 to Arduino IDE.
- Created/Copied a new sketch named Firebasedemo.ino with above information to connect to Firebase database for 2-way Communication.
- 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/↗
- 70 x Solid core jumper wires,
- 1 x Easy-to-assemble wooden base,
- 1 x 9v battery snap,
- 1 x Stranded jumper wires (black),
- 1 x Stranded jumper wires (red),
- 6 x Phototransistor,
- 3 x Potentiometer 10kOhms,
- 10 x Pushbuttons,
- 1 x Temperature sensor [TMP36],
- 1 x Tilt sensor,
- 1 x alphanumeric LCD (16×2 characters),
- 1 x LED (bright white),
- 1 x LED (RGB),
- 8 x LEDs (red),
- 8 x LEDs (green),
- 8 x LEDs (yellow),
- 3 x LEDs (blue),
- 1 x Small DC motor 6/9V,
- 1 x Small servo motor,
- 1 x Piezo capsule [PKM22EPP-40],
- 1 x H-bridge motor driver [L293D],
- 1 x Optocouplers [4N35],
- 2 x Mosfet transistors [IRF520],
- 3 x Capacitors 100uF,
- 5 x Diodes [1N4007],
- 3 x Transparent gels (red, green, blue),
- 1 x Male pins strip (40×1),
- 20 x Resistors 220 Ohms,
- 5 x Resistors 560 Ohms,
- 5 x Resistors 1 kOhms,
- 5 x Resistors 4.7 kOhms,
- 20 x Resistors 10 kOhms,
- 5 x Resistors 1 MOhms,
- 5 x Resistors 10 MOhms
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.
- Micro Switch
- Line Sensor
- RGB LED
- Power Distributor
- HC-05 Bluetooth Module - csr-bc417 143bqn K210528R
- 300 RPM BO Motor-Straight VIGOR -2 Nos
- 1 x TowerPro MG90S Mini Digital 180 Degree Servo
Naresh Electronics
In 2023
- breadboard
- JHD 16×2 Character LCD Display With Yellow Backlight
- LED’s
- Jump Wires
- 3 male to male wires
- 3 male to female wires
- 2 male to free wires
- Fan 1 No
- High Torque RF 370 DC Motor
2024-04-24
10 Resistors of 2 each from Naresh @₹10
- 220 Ohms
- 1k Ohms
- 4.7k Ohms
- 10k Ohms
- 1M Ohms
2024-04-30
- 10M Ohms Resistor 3 Nos
- 1K Ohms Resistor 5 Nos
- LDR 2 Nos
- Alligator to Banana plug converter
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:
- 1 x Set of Horns (One Point,Two Point,Four Point) for TowerPro MG90S Mini Digital 180 Degree Servo motor(with motor ₹250)
- Crocodile clips (or probes with Crocodile clips) for multimeter
- 1k and 10M resistors 5 each
- LDR
Books and References
Downloaded few books related to Arduino
- Arduino Cookbook
- Getting Started With Arduino 3rd Edition
- Making Things Talk 1st and 2nd Edition by Tom Igoe
- Physical Computing Sensing and Controlling
- Lowtech sensors and actuators
Lessons
Hardware
- Always use a resistor with an LED to prevent burning out the LED.(2 LED’s spoiled in less than 2 hours)
- To avoid damaging the IC, the current going through an Arduino I/O
pin should be limited to 20 milliamps.
- Avoid or prevent short circuits(?) i.e direct connection of Power and Ground through wire or other mean.
- Resistors come with 4 rings or 5 rings. Final ring indicates tolerance Gold(5%)/Silver(10%)/Red(2%)/Brown(1%)
- For connecting LED and LDR use 220 Ohm and 10K ohm resistors respectively(?)
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 */
}
}
- https://www.electronicwings.com/sensors-modules/bluetooth-module-hc-05↗ -
- https://docs.arduino.cc/learn/built-in-libraries/software-serial/↗
- https://www.makerguides.com/arduino-and-hc-05-bluetooth-module-complete-tutorial/↗
- https://electronics.stackexchange.com/questions/280500/why-do-you-have-to-use-a-voltage-divider-with-hc-05-bluetooth-module-arduino↗
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
- Understand how calculations are to be done for a circuit to decide on correct resistors.
- How to find and understand datasheets.
- Voltage dividers https://learn.sparkfun.com/tutorials/voltage-dividers↗
- pull-up resistors
What do i want from Arduino
- Turn ON and OFF solar switch at FF through mobile or from computer
- Turn ON and OFF solar pump through mobile
- Monitor the farm through cctv from mobile
- Create sounds or make physical changes to ward off animals and humans from mobile
- Monitor the moisture level at any point and record the same for further action
- Control valves remotely
© Prabu Anand K 2020-2026