PICO 2 ऑल इन वन स्टार्टर किट
वापरकर्ता मॅन्युअल
परिचय
PICO 2 साठी ऑल-इन-वन स्टार्टर किटसाठी वापरकर्ता मॅन्युअलमध्ये आपले स्वागत आहे. चला PICO 2 डेव्हलपमेंट बोर्ड आणि त्याच्या सेन्सर्सच्या जगात आपला प्रवास सुरू करूया.
खात्री बाळगा, या विकास मंडळात २१ अभ्यासक्रम आहेत जे उत्तरोत्तर आव्हानात्मक, आकर्षक आणि विचार करायला लावणारे बनतील. हे अभ्यासक्रम तुम्हाला आवश्यक ज्ञानाद्वारे चरण-दर-चरण मार्गदर्शन करतील. येथे, तुम्ही इलेक्ट्रॉनिक मॉड्यूल्सशी परिचित व्हाल, तुमचे तार्किक विचार कौशल्य वाढवाल, तुमच्या सर्जनशील डिझाइन क्षमता वाढवाल आणि प्रोग्रामिंगद्वारे या मॉड्यूल्सची कार्यक्षमता अंमलात आणाल.
शिकण्याची प्रक्रिया प्रोग्रामिंग सॉफ्टवेअर कसे स्थापित करायचे हे समजून घेण्यापासून सुरू होते, त्यानंतर PICO 2 डेव्हलपमेंट बोर्ड आणि त्याच्या विविध सेन्सर्सची ओळख करून दिली जाते. त्यानंतर तुम्ही या सेन्सर्सच्या प्रोग्रामिंग फंक्शन्स आणि ते वापरत असलेल्या प्रोग्रामिंग भाषेचा सखोल अभ्यास कराल, शेवटी हे सेन्सर्स व्यावहारिक अनुप्रयोगांमध्ये कसे वापरायचे ते शिकाल. प्रत्येक पायरी बारकाईने स्पष्ट केली आहे, ज्यामुळे नवशिक्यांसाठी C/C++ प्रोग्रामिंग जलदपणे समजणे सोपे होते.
PICO 2 साठी ऑल-इन-वन स्टार्टर किटमध्ये 17 इलेक्ट्रॉनिक मॉड्यूल समाविष्ट आहेत, प्रत्येकाची स्वतःची अद्वितीय वैशिष्ट्ये आणि कार्ये आहेत, विशेषतः नवशिक्यांसाठी डिझाइन केलेली आहेत आणि सुरुवात करण्यासाठी एक आदर्श पर्याय आहे. उदा.ampबरं, लाईट सेन्सर नवशिक्यांना प्रोग्रामिंगद्वारे वास्तविक जगातील प्रकाश उपकरणे नियंत्रित करण्याची परवानगी देतो.
थोडक्यात, या डेव्हलपमेंट बोर्डसोबत काम करून, तुम्ही सेन्सर्सचे मूलभूत ज्ञान आणि तत्त्वे शिकाल, डिजिटल आणि अॅनालॉग सिग्नल, अॅनालॉग-टू-डिजिटल रूपांतरण आणि प्रोग्रामिंग लॉजिक यासारख्या महत्त्वाच्या संकल्पना समजून घ्याल आणि काही जटिल इलेक्ट्रॉनिक मॉड्यूल्सचा वापर करण्यात प्रभुत्व मिळवाल. सर्वात महत्त्वाचे म्हणजे, PICO 2 प्रोग्रामिंगद्वारे, तुम्ही तुमचे तार्किक विचार कौशल्य आणखी वाढवाल.
प्रोग्रामिंग सॉफ्टवेअरसाठी, आपण Arduino IDE वापरू. Arduino IDE हे वापरण्यास सोपे ओपन-सोर्स प्लॅटफॉर्म आहे आणि प्रोग्रामिंग शिकण्यासाठी सर्वोत्तम पर्यायांपैकी एक आहे.
प्रारंभ करणे
Arduino IDE स्थापित करत आहे
Download Arduino in Windows system
- पायरी 1:
Login to Arduino official website, download Arduino.
Arduino अधिकारी webसाइट: https://www.arduino.cc/en/software/ - पायरी 2:
Select your computer’s corresponding system to download, such as Window system.
- पायरी 3:
Click JUST DOWNLOAD and select the save location to start the download.
पायरी 4:
- When installing Arduino, please locate the executable file with the .exe extension within the folder where you previously saved, which is the Arduino installation package.

- After double-clicking the installation package, this page will appear. Click on ‘I Agree ‘.

- Check all options by default and click Next.

- Click on ‘Browse’ to select the installation location, it is recommended to install it on any drive other than the C: drive. Then click ‘Install ‘.

- Installation Complete, click ‘Close’.

PICO डेव्हलपमेंट बोर्ड पर्याय डाउनलोड करा
After waiting for the Arduino IDE installation to complete, open the Arduino IDE.
- Find the settings in Arduino IDE

- Put this link up:
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
- साठी शोधा rp2040 (जर तुम्ही पूर्वी RP2040 च्या इतर आवृत्त्या डाउनलोड आणि स्थापित केल्या असतील, तर कृपया आवृत्ती 4.2.0 पुन्हा स्थापित करण्यापूर्वी मागील आवृत्ती पूर्णपणे अनइंस्टॉल करा.)
This way, we can run the code we will write later on the All-in-one Starter Kit for Pico2.
Arduino IDE परिचय

- Flie: This lets you create, open, save, and manage sketch fileएस, अॅक्सेस एसample code, adjust editor preferences, export compiled files, and exit the Arduino IDE—making it easy to handle project files आणि तुमचे कार्यक्षेत्र कॉन्फिगर करा.
- Edit: This is for editing your code, including undo, redo, cut, copy, paste, find and replace, select all, as well as commenting and uncommenting code—helping you modify your program quickly and efficiently.
- Sketch: This handles compiling and uploading your code, allowing you to verify syntax, upload programs to your board, manage libraries, and export build results—streamlining your development and debugging process.
- Tools: Choose your board model, serial port, and programmer, open the serial monitor and plotter, manage libraries, and check board details—essential for hardware setup and debugging.
- Help: Provide official Arduino reference materials, FAQs, troubleshooting guides, and software version information to help users learn, use, and resolve issues they may encounter during development.
- Verify: Compile the Arduino code to check for syntax errors and issues without uploading it, ensuring the code is correct and executable.
- Upload: Upload the compiled code to the Arduino board to run and test the program on the actual hardware.
- Sketchbook: Used for managing and quickly accessing all saved Arduino sketches, making it easy for users to open, edit, and organize their project code.
- Boards manager: Used to install, update, and manage various Arduino board support packages, extending the IDE’s compatibility with different hardware.
- Library manager: Used to search for, install, and manage Arduino libraries, helping users easily integrate various functional modules and streamline the development process.
- Debug: Used to assist with code debugging by printing messages and errors through the serial port, helping identify issues in the program and improving development efficiency.
- Search: The Search feature allows quick find-and-replace within the code, making it easier to locate and edit specific content and boosting editing efficiency.
- Serial Plotter: Used to plot numerical data sent from the Arduino board via the serial port in real time, helping users visually analyze sensor readings and variable changes.
- Serial Monitor: Used for serial communication with the Arduino board, allowing real-time sending and displaying of text to facilitate debugging and monitoring program status.
अभ्यासक्रम वापरण्याच्या सूचना
The course firmware is provided for use only. The function description and download firmware address in the firmware are as follows: Source code address: https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/factory_sourcecode/All_in_one_Starter_Kit_for_Pico2_SPI_Curriculum_V02_20250114
गेम वापर ट्यूटोरियल
गेम ट्यूटोरियल
- Game 1: Little Dinosaur Game
How to Play: Control the little dinosaur to jump and avoid obstacles by tapping the screen. - Game 2: Bouncing Ball Game
How to Play: Use the left and right buttons to move the paddle left or right and bounce the ball. - Game 3: Snake Game
How to Play: Use the up, down, left, and right buttons to control the movement of the snake and eat the fruits.
For the above games, swiping up on the screen will bring up the menu. Clicking the “Return” button will exit to the factory UI interface. Clicking the “Start/Stop” button can control the game status. Once the “Start” button is clicked, the menu interface will automatically exit.
The functions are the implementation functions for the four types of lighting effects in the UI interface.
या चार फंक्शन्समध्ये बदल करून, तुम्ही फॅक्टरी-डिफॉल्ट लाइटिंग इफेक्ट्स कस्टमाइझ करण्याचे ध्येय साध्य करू शकता.
धडा १ – एलईडी नियंत्रण
परिचय
In this lesson, we’ll focus on hands-on programming with LED control. By writing code to configure GPIO pins and implement control logic, students will learn how to make LEDs blink alternately at fixed intervals. Along the way, they’ll gain practical experience with basic hardware control while developing a deeper understanding of time management and loop logic—key concepts in embedded programming. This foundational knowledge will lay the groundwork for tackling more complex projects in the future.
या धड्यात वापरलेले हार्डवेअर:
एलईडीचे कार्य तत्व
LED (प्रकाश उत्सर्जक डायोड) च्या केंद्रस्थानी एक अर्धसंवाहक PN जंक्शन असते. जेव्हा फॉरवर्ड बायस व्हॉल्यूमtage is applied, electrons from the N-type region recombine with holes from the P-type region near the junction. During this recombination, electrons drop from a higher energy level to a lower one, releasing the excess energy in the form of photons—producing light. The color (or wavelength) of the emitted light is determined by the energy band gap of the semiconductor material. This process is a direct application of electroluminescence.
ऑपरेशन इफेक्ट डायग्राम
After Running:
You can see: The blinking effect of the red, green, and yellow lights on the All in One Starter Kit for Pico2.
प्रमुख स्पष्टीकरणे
- Hardware Connection and Initialization
#define Red_LED 18
#define Yellow_LED 20
#define Green_LED 19
कोडचा हा भाग तीन LEDs शी जोडलेल्या पिन परिभाषित करतो, ज्यामुळे उर्वरित प्रोग्राममध्ये त्यांचा संदर्भ घेणे आणि वापरणे सोपे होते. - Time Control Mechanism
unsigned long previousMillis = 0;
const long interval = 1000;
previousMillis is used to keep track of the last time the LED state changed.
interval defines how often the LED should toggle; in this case, it’s set to 1000 milliseconds, or 1 second. - LED State Management
int redState = LOW;
int yellowState = LOW;
int greenState = LOW;
These three variables keep track of the current state of the red, yellow, and green LEDs. In
Arduino, HIGH means the LED is on, and LOW means it’s off. - इनिशियलायझेशन फंक्शन
शून्य सेटअप() {
pinMode(Red_LED, OUTPUT);
pinMode(Yellow_LED, OUTPUT);
pinMode(Green_LED, OUTPUT);
digitalWrite(Red_LED, redState);
digitalWrite(Yellow_LED, yellowState);
digitalWrite(Green_LED, greenState);
}
pinMode() फंक्शन LED पिनना आउटपुट म्हणून सेट करते, ज्यामुळे Arduino ला त्यांचा व्हॉल्यूम नियंत्रित करता येतो.tage
पातळी
The digitalWrite() function sets the voltage level of each LED pin based on the values of
redState, yellowState, and greenState. At the beginning, all three LEDs are off. - Main Loop and Time Judgment
void loop() {
unsigned long currentMillis = millis();
if (currentMillis – previousMillis >= interval) {
previousMillis = currentMillis;
redState = (redState == LOW) ? HIGH : LOW;
yellowState = (yellowState == LOW) ? HIGH : LOW;
greenState = (greenState == LOW) ? HIGH : LOW;
digitalWrite(Red_LED, redState);
digitalWrite(Yellow_LED, yellowState);
digitalWrite(Green_LED, greenState);
}
}
The millis() function returns the number of milliseconds that have passed since the Arduino was powered on.
By checking the condition currentMillis – previousMillis >= interval, the code can determine whether the set 1-second interval has passed.
Once the interval is reached, the following actions are performed:
• previousMillis is updated to record the time of the current state change.
The states of the three LEDs are toggled using the ternary operator (redState == LOW) ? HIGH :
LOW, which flips the state from off to on or vice versa.
“(redState == LOW) ? HIGH : LOW” is a ternary operator expression whose core logic is to invert
the state of “redState”. Specifically:
When “redState” equals “LOW”, the condition is true, and the expression returns “HIGH”.
When “redState” does not equal “LOW” (i.e., it is “HIGH”), the condition is false, and the expression returns “LOW”.
• Finally, the new states are applied to the LED pins using the digitalWrite() function so that the
LEDs reflect the updated status.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
प्रोग्रामिंग स्टेप्स
पिको२ साठी ऑल-इन-वन स्टार्टर किटमध्ये कोड अपलोड करण्यासाठी, बोर्ड तुमच्या संगणकाशी कनेक्ट करून सुरुवात करा.
Next, you can copy the complete code from the folder into the Arduino IDE.
Make sure to select the correct development board you’re using from the Tools > Board menu before uploading.
Before uploading the code, make sure to put the All-in-One Starter Kit for Pico2 into bootloader mode:
- Press and hold the BOOT button on the board.
- While holding BOOT, press and release the RESET button.
- Then, release the BOOT button.
The board will now enter bootloader mode. Your computer should detect it as a new serial device. In the Arduino IDE, select this new port from the Tools > Port menu, and you’ll be ready to upload the code.
प्रक्रिया सुरू करण्यासाठी "चालवा" वर क्लिक करा.
Once everything runs successfully, a window will pop up.
In that window, you’ll see a file with the .uf2 extension—this represents the executable file generated from your code upload.
Seeing the .uf2 file कोड बोर्डवर यशस्वीरित्या फ्लॅश झाला आहे याची पुष्टी करतो!
Finally, you will be able to see the display of relevant experimental results.
परिचय
In this lesson, we’ll use the All-in-One Starter Kit for Pico2 to learn how to control red, green, and yellow LEDs using button input. The course covers how to connect buttons to the development board, initialize the corresponding input pins, write logic to detect button states, and control the LEDs—turning them on or off—based on button presses.
या धड्यात वापरलेले हार्डवेअर:
एमसीयू-आधारित बटण-नियंत्रित एलईडी सिस्टमचे कार्य तत्व
ही प्रणाली अॅनालॉग व्हॉल्यूम वापरतेtage detection to handle multiple button inputs. Its core functionality is divided into three key components:
- Button Detection: Multiple buttons are wired through a resistor voltagएमसीयूच्या एडीसी (अॅनालॉग-टू-डिजिटल कन्व्हर्टर) पिनशी ई डिव्हायडर नेटवर्क जोडला जातो. जेव्हा बटण दाबले जाते तेव्हा ते एक अद्वितीय व्हॉल्यूम तयार करतेtagई पातळी. एमसीयू एसampहे खंडtagस्थिर वाचन मिळविण्यासाठी मध्यक फिल्टरिंग वापरते आणि नंतर पूर्वनिर्धारित व्हॉल्यूमशी निकालाची तुलना करतेtagकोणते विशिष्ट बटण दाबले गेले हे ओळखण्यासाठी e श्रेणी.
- Logic Processing: Once a button is identified, the MCU updates internal state flags (such as redOn, yellowOn, etc.) accordingly.
A debouncing mechanism—typically using a flag like keyIsPressed—ensures that each press is registered only once, preventing multiple toggles due to signal noise or rapid mechanical bouncing. - LED Driving: The MCU’s GPIO pins control the LEDs based on the state flags. When a flag is set to true, the corresponding GPIO outputs a HIGH signal. This current, limited by a resistor (eg: 220Ω), powers the LED, turning it on. For exampआणि, जेव्हा redOn खरे असते, तेव्हा लाल LED पॉवर प्राप्त करतो आणि उजळतो.
ऑपरेशन इफेक्ट डायग्राम
- When pressing button 0, the red light, yellow light, and green light are lit simultaneously.

- When pressing button 0 again, all three lights are turned off simultaneously.
- Pressing button 1 lights the red light;
- Pressing button 1 again turns off the red light;

- Pressing button 2 lights the yellow light;
- Pressing button 2 again turns off the yellow light;

- Pressing button 3 lights the green light;
- Pressing button 3 again turns off the green light.

प्रमुख स्पष्टीकरणे
- Hardware Connection and Constant Definition
#define Red_LED 18
#define Yellow_LED 20
#define Green_LED 19
#define Button_pin 27
#define B0_L 740
#define B0_H 750
The code defines the GPIO pins for the three LEDs as well as the analog pin connected to the button input.
It also sets specific ADC value ranges for each button, which will later be used to identify which button has been pressed. - LED State Management
bool redOn = false;
bool yellowOn = false;
bool greenOn = false;
bool allOn = false;
असत्य मूल्य म्हणजे LED बंद आहे, तर सत्य मूल्य म्हणजे LED चालू आहे. - Button Denounce Processing
bool keyIsPressed = खोटे;
एका बटण दाबल्याने वारंवार होणारे ट्रिगर रोखण्यासाठी हा ध्वज वापरला जातो, ज्यामुळे प्रत्येक दाब फक्त एकदाच ओळखला जातो. - Median Filter Function
int readMedianADC(int pin) {
int readings[5];
साठी (int i = 0; i < 5; i++) {
readings[i] = analogRead(pin);
विलंब(3);
}
साठी (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 5; j++) {
if (readings[i] > readings[j]) {
int temp = readings[i];
readings[i] = readings[j];
readings[j] = temp;
}
}
}
return readings[2];
}
या दृष्टिकोनाचा उद्देश अधूनमधून येणारा आवाज किंवा हस्तक्षेप दूर करणे, ADC रीडिंगची अचूकता आणि स्थिरता सुधारणे आहे. - इनिशियलायझेशन सेटिंग्ज
शून्य सेटअप() {
Serial.begin(115200);
pinMode(Red_LED, OUTPUT);
pinMode(Yellow_LED, OUTPUT);
pinMode(Green_LED, OUTPUT);
pinMode(Button_pin, INPUT);
digitalWrite(Red_LED, LOW);
digitalWrite(Yellow_LED, LOW);
digitalWrite(Green_LED, LOW);
Serial.println(“System Ready.”);
}
Initializes serial communication, making it easier to output debug information.
एलईडी पिन आउटपुट म्हणून आणि बटण पिन इनपुट म्हणून सेट करते.
सुरुवातीच्या स्थितीत सर्व LEDs बंद करते. - Main Loop Logic
void loop() {
int adcValue = readMedianADC(Button_pin);
Serial.print(“ADC: “);
Serial.println(adcValue);
bool inRange =
(adcValue >= B0_L && adcValue <= B0_H) ||
(adcValue >= B1_L && adcValue <= B1_H) ||
(adcValue >= B2_L && adcValue <= B2_H) ||
(adcValue >= B3_L && adcValue <= B3_H);
if (inRange && !keyIsPressed) {
keyIsPressed = true;
if (adcValue >= B0_L && adcValue <= B0_H) {
allOn = !allOn;
redOn = yellowOn = greenOn = allOn;
digitalWrite(Red_LED, redOn ? HIGH : LOW);
digitalWrite(Yellow_LED, yellowOn ? HIGH : LOW);
digitalWrite(Green_LED, greenOn ? HIGH : LOW);
Serial.println(“Button 0: Toggle ALL LEDs”);
}
else if (adcValue >= B1_L && adcValue <= B1_H) {
redOn = !redOn;
digitalWrite(Red_LED, redOn ? HIGH : LOW);
Serial.println(“Button 1: Toggle RED”);
}
}
if (!inRange && keyIsPressed) {
keyIsPressed = false;
}
विलंब(20);
}
बटण इनपुटमधून ADC मूल्य वाचण्यासाठी आणि फिल्टर करण्यासाठी readMedianADC फंक्शनला कॉल करते.
Checks whether the ADC value falls within a predefined range to determine if a specific button has been pressed.\
When a new button press is detected:
- Uses the key Is Pressed flag to prevent repeated triggers from the same press.
- Executes the corresponding LED control logic based on the detected ADC range.
- Applies the ternary operator (eg: red On ? HIGH : LOW) to set each LED’s state.
- Once the button is released, the denounce flag is reset, preparing the system to detect the next valid button press.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the code above, you can start modifying the functionality—such as using button presses to control the LEDs in different ways. In upcoming lessons, we’ll also explore how to work with even more hardware features available on the All-in-One Starter Kit for Pico2.
प्रोग्रामिंग स्टेप्स
तुम्ही मार्गदर्शक म्हणून धडा १ (पृष्ठ १०-१५) मधील फ्लॅशिंग स्टेप्सचा संदर्भ घेऊ शकता.
धडा ३ - श्वासोच्छवास एलईडी
परिचय
The slider module is a linear potentiometer with a maximum resistance of 10kΩ. Moving the wiper from left to right linearly increases the output voltage 0V पासून VCC पर्यंत. या धड्यात, आपण नियंत्रण इनपुट म्हणून पोटेंशियोमीटर वापरू. s द्वारेampमायक्रोकंट्रोलरच्या ADC शी त्याचे अॅनालॉग सिग्नल जोडून आणि PWM मॉड्युलेशन लागू करून, आम्ही स्लाइडरच्या स्थितीला प्रतिसाद देणारा एक गुळगुळीत, श्वास घेण्यासारखा LED ब्राइटनेस इफेक्ट तयार करू. हे अॅनालॉग सिग्नल नियंत्रण आणि डिजिटल सिग्नल प्रक्रिया एकत्र कसे कार्य करतात याचे स्पष्ट प्रात्यक्षिक प्रदान करते.
या धड्यात वापरलेले हार्डवेअर:
एलईडी ब्राइटनेस नियंत्रित करण्यासाठी स्लाइडिंग रिओस्टॅटचे तत्व
ही प्रणाली आउटपुट व्हॉल्यूम समायोजित करण्यासाठी स्लाइडिंग रिओस्टॅट (पोटेंशियोमीटर) वापरते.tagखंडाचा etage divider circuit. The microcontroller’s ADC (12-bit resolution, range 0–4095) reads this analog voltage and linearly maps it to an 8-bit PWM value (0–255). The PWM signal is then output through the microcontroller’s GPIO pin. By adjusting the duty cycle, the system controls the average current flowing through the LED: a higher duty cycle means the LED stays on longer during each cycle, making it appear brighter; a lower duty cycle shortens the on-time, dimming the LED.
ऑपरेशन इफेक्ट डायग्राम
- When I slide the potentiometer all the way to the left, the LED is at its dimmest.

- When I slide it all the way to the right, the LED reaches its maximum brightness.

- Hardware Connections and Pin Definitions
#define SLIDER_PIN 28
#define RED_LED_PIN 18
#define YELLOW_LED_PIN 20
#define GREEN_LED_PIN 19
पोटेंशियोमीटर आणि तीन एलईडींना जोडलेले पिन कोडमध्ये परिभाषित केले आहेत.
LED पिन PWM-सक्षम GPIO ला नियुक्त केले आहेत याची खात्री करणे महत्वाचे आहे; अन्यथा, PWM द्वारे ब्राइटनेस नियंत्रण कार्य करणार नाही. - इनिशियलायझेशन सेटअप
शून्य सेटअप() {
Serial.begin(115200);
करताना (! अनुक्रमांक);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(YELLOW_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
Serial.println(“LED Brightness Control with Slider Ready.”);
}
The serial communication is initialized to allow relevant information to be printed during debugging.
The LED pins are set as output so that the Arduino can control them properly. - Main Loop Logic
void loop() {
इंट अॅनालॉग व्हॅल्यू = अॅनालॉग रीड(स्लाइडर_पिन);
int pwmValue = map(analogValue, 0, 4095, 0, 255);
analogWrite(RED_LED_PIN, pwmValue);
analogWrite(YELLOW_LED_PIN, pwmValue);
analogWrite(GREEN_LED_PIN, pwmValue);
Serial.print(“ADC: “);
Serial.print(analogValue);
Serial.print(” | PWM: “);
Serial.println(pwmValue);
विलंब(100);
}
Reading the Analog Value:
- analogRead(SLIDER_PIN) reads the voltage from the potentiometer and converts it to a digital value.
- On the RP2040, the ADC has 12-bit resolution, meaning it maps the 0–3.3V input range to values between 0 and 4095.
Mapping the Value Range: - The map() function is used to convert the 0–4095 ADC range to the 0–255 range required for PWM.
- उदाample, if the ADC reads 2048, the mapped PWM value would be 127 — roughly 50% brightness.
PWM Brightness Control: - The analogWrite() function uses PWM to control the LED’s brightness.
- A PWM value of 0 turns the LED off completely, while 255 sets it to full brightness.
Debug Output: - The serial monitor prints both the raw ADC value and the mapped PWM value, making it easier to observe how the system is behaving.
- विलंब नियंत्रण:
- delay(100) ensures the loop runs every 100 milliseconds, which reduces serial output clutter and prevents overly frequent readings from the potentiometer.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the code above, you can start modifying the functionality—such as using button presses to control the LEDs in different ways. In upcoming lessons, we’ll also explore how to work with even more hardware features available on the All-in-One Starter Kit for Pico2.
प्रोग्रामिंग स्टेप्स
तुम्ही मार्गदर्शक म्हणून धडा १ (पृष्ठ १०-१५) मधील फ्लॅशिंग स्टेप्सचा संदर्भ घेऊ शकता.
धडा ४ – २.४ इंचाचा TFT डिस्प्ले
परिचय
In this chapter, we’ll use the TFT display module on the All-in-One Starter Kit for Pico2 to display text. The module communicates with the board via an SPI serial interface, making both the hardware connection and software integration relatively straightforward—ideal for beginners and quick prototyping.
या धड्यात वापरलेले हार्डवेअर:
डिस्प्ले स्क्रीनवर डायनॅमिक टेक्स्ट डिस्प्लेचे कार्य तत्व
TFT डिस्प्ले स्क्रीन MCU द्वारे SPI बसद्वारे पाठवलेला पिक्सेल डेटा आणि नियंत्रण सूचना प्राप्त करते. ST7789 ड्रायव्हर चिप प्राप्त झालेल्या RGB डेटाला प्रोग्रेसिव्ह स्कॅन सिग्नलमध्ये रूपांतरित करते आणि व्हॉल्यूम अचूकपणे नियंत्रित करते.tagसोर्स ड्रायव्हर आणि गेट ड्रायव्हरद्वारे प्रत्येक लिक्विड क्रिस्टल सेलचे e, ज्यामुळे इमेज डिस्प्ले साकार करण्यासाठी प्रकाश प्रसारण बदलते. टच फंक्शन मानवी-संगणक परस्परसंवाद साकार करण्यासाठी FT5x06 चिपद्वारे I2C प्रोटोकॉलद्वारे डेटा समन्वयित करते. LED बॅकलाइट स्रोताची चमक नियंत्रित करण्यासाठी बॅकलाइट स्वतंत्र GPIO वापरते.
ऑपरेशन इफेक्ट डायग्राम
एकदा प्रोग्राम चालू झाला की, TFT स्क्रीन खालील डिस्प्ले क्रमाचे अनुसरण करेल:
- 1.First, it shows “HELLO WORLD!”;

- 2. After a 1-second delay, the text changes to “Bye Bye”;

- 3. One second later, the screen is cleared and the display turns off.

प्रमुख स्पष्टीकरणे
- Display Driver and Library Imports
#include <LovyanGFX.hpp>
#include <lvgl.h>
LovyanGFX: This library handles the low-level drivers for the TFT display, such as SPI communication and pixel operations. It simplifies hardware control and makes screen management much easier.
LVGL: A lightweight graphics library used for building user interfaces. In this code, it’s only maintained by calling lv_timer_handler() in the loop() function to keep the library running properly. - Initialization and Display Logic
शून्य सेटअप() {
Serial.begin(115200);
gfx.init();
पिनमोड(१३, आउटपुट);
डिजिटलराइट(0, उच्च);
gfx.setTextSize(2);
gfx.setTextColor(TFT_WHITE);
gfx.setCursor(60, 100);
gfx.print(“HELLO WORLD!”);
विलंब(1000);
gfx.fillScreen(TFT_BLACK);
gfx.setCursor(100, 100);
gfx.print(“Bye Bye”);
विलंब(1000);
gfx.fillScreen(TFT_BLACK);
डिजिटलराइट(0, लो);
}
Key Display Control Functions:
• fillScreen(color): Fills the entire screen with the specified color (using black effectively clears the screen).
• setCursor(x, y): Sets the position of the top-left corner of the text; the origin (0, 0) is at the top-left of the screen.
• setTextSize(n): Sets the text size to n times the default font size (with n = 1 being the smallest). - Main Loop (loop Function)
void loop() {
lv_timer_handler();
विलंब(10);
}
LVGL Timer Handling:
• lv_timer_handler() is a required function call in the LVGL library. It manages internal timers that handle animations, events, and other time-based operations. Even if your interface doesn’t have dynamic effects, this function still needs to be called regularly to keep the library functioning properly.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the above code, you can control a 2.4-inch TFT display based on this development board to achieve dynamic text display: After the program starts, it firs displays “HELLO WORLD!” at a specified position on the screen and pauses for 1 second, then clears the screen to display “Bye Bye” for another second, and finally clears the screen and turns off the backlight. The code configures hardware information such as SPI communication parameters and screen resolution through a custom LGFX class, uses the display interface of the Loyang GFX library to control text output, and integrates the LVGL library to maintain system operation. Once mastered, you can adjust the text content, display position, font size or color, add more display phases, or combine sensor data to achieve dynamic interactive display.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use an additional library (LovyanGFX-develop),so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries डायरेक्टरीमध्ये जा आणि LovyanGFX-develop फोल्डर डाउनलोड करा. - Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा ५ – ट्रॅफिक लाईट
परिचय
In this lesson, we’ll use an LED module to simulate the operation of real-world traffic lights, combined with a TFT display to show a countdown timer. This hands-on project is designed to help you understand the fundamentals of timing control and hardware interaction in embedded systems.
या धड्यात वापरलेले हार्डवेअर:
ट्रॅफिक लाईट सिस्टीमचे काम करण्याचे तत्व
ही ट्रॅफिक लाईट सिस्टीम एका मायक्रोकंट्रोलर (MCU) वर आधारित आहे जी GPIO पिनद्वारे लाल, पिवळ्या आणि हिरव्या LEDs थेट चालवते. ऑपरेटिंग करंट सुरक्षित श्रेणीत राहतो याची खात्री करण्यासाठी प्रत्येक LED करंट-लिमिटिंग रेझिस्टरसह मालिकेत जोडलेले असते. तीन-फेज सायकल अंमलात आणण्यासाठी सिस्टम एका मर्यादित स्टेट मशीन (FSM) वापरते: हिरवा दिवा 30 सेकंदांसाठी चालू राहतो, पिवळा दिवा 3 सेकंदांसाठी चालू राहतो आणि लाल दिवा 20 सेकंदांसाठी चालू राहतो, ज्याचे अचूक वेळ हार्डवेअर टाइमरद्वारे व्यवस्थापित केले जाते. काउंटडाउन टाइमर ST7789 TFT स्क्रीनवर रिअल-टाइममध्ये प्रदर्शित केला जातो (80 MHz घड्याळासह SPI इंटरफेसद्वारे चालवला जातो). शेवटच्या 5 सेकंदांमध्ये, सध्या सक्रिय LED दर 500ms ला चेतावणी म्हणून चमकतो. संपूर्ण सिस्टम नॉन-ब्लॉकिंग प्रोग्रामिंगसह डिझाइन केले आहे जेणेकरून पेरिफेरल्स (LEDs, डिस्प्ले) च्या समन्वयाचा रिअल-टाइम कामगिरीवर परिणाम होत नाही याची खात्री होईल. याव्यतिरिक्त, हार्डवेअर डिबाउंस तंत्रज्ञान स्पर्श शोधण्याची विश्वसनीयता सुनिश्चित करते.
ऑपरेशन इफेक्ट डायग्राम
Green Light Phase
- The green light stays on, and the TFT displays “Countdown: 30 seconds,” with the number decreasing by 1 each second.
- When the countdown reaches 5 seconds, the green light begins to flash.
Yellow Light Phase - The green light turns off, the yellow light stays on, and the TFT displays “Countdown: 3 seconds.”
- After 3 seconds, the yellow light turns off and switches to the red light.
Red Light Phase - The red light stays on, and the TFT displays “Countdown: 20 seconds.”
- When the countdown reaches 5 seconds, the red light begins to flash, and after 20 seconds, the cycle returns to the green light phase.

प्रमुख स्पष्टीकरणे
- Traffic Light Phase Switching Logic
if (remainingTime == 0) {
digitalWrite(Green_LED, LOW);
digitalWrite(Yellow_LED, LOW);
digitalWrite(Red_LED, LOW);
switch(currentStage) {
case GREEN_STAGE:
currentStage = पिवळा_सेTAGE;
remainingTime = 3;
digitalWrite(Yellow_LED, HIGH);
खंडित;
case YELLOW_STAGE:
currentStagई = लाल_एसTAGE;
remainingTime = 20;
digitalWrite(Red_LED, HIGH);
खंडित;
case RED_STAGE:
currentStagई = हिरवा_एसTAGE;
remainingTime = 30;
digitalWrite(Green_LED, HIGH);
खंडित;
}
}
फेज स्विचिंग: कोडचा हा भाग ट्रॅफिक लाईट एका टप्प्यातून दुसऱ्या टप्प्यात स्विच करण्याची कार्यक्षमता लागू करतो.
• When remaining Time (the remaining time of the current phase) reaches 0, it indicates the end of the current phase.
• First, all LEDs are turned off, and then, based on the value of current Stage, सिस्टम पुढील टप्प्यात जाते.
• Each phase has a fixed duration:
• The green light phase (GREEN_STAGई) २० सेकंद टिकते.
• The yellow light phase (YELLOW_STAGई) २० सेकंद टिकते.
• The red light phase (RED_STAGई) २० सेकंद टिकते.
एलईडी नियंत्रण: नवीन टप्प्यावर स्विच करताना, त्या टप्प्यासाठी संबंधित एलईडी चालू केले जाते आणि इतर एलईडी बंद केले जातात.
• During the green light phase, the green LED is turned on.
• During the yellow light phase, the yellow LED is turned on. - Countdown Display Logic
if (now – lastUpdate >= 1000) {
remainingTime–;
lastUpdate = now;
gfx.fillRect(TEXT_AREA_X, TEXT_AREA_Y, TEXT_AREA_WIDTH,
TEXT_AREA_HEIGHT, TFT_BLACK);
gfx.setTextColor(TFT_WHITE);
gfx.setCursor(TEXT_AREA_X, TEXT_AREA_Y);
gfx.printf(“%2ds”, remainingTime);
}
Time Update:
This part of the code implements the functionality of updating the countdown every second.
• The millis() function is used to get the current time in milliseconds.
• If 1000 milliseconds (i.e., 1 second) have passed since the last countdown update, remaining Time is decreased by 1, and last Update is updated to the current time.
Screen Display Update:
• The gfx. fillet () function is used to clear the countdown number area on the screen (to avoid clearing the “Countdown:” text).
• The text color is set to white, and the cursor is moved to the starting position of the countdown number area.
• The gfx. printf() function is used to print the updated countdown value in a formatted manner (eg: “29s”). - Last 5 Seconds Flashing Logic
if (remainingTime > 0 && remainingTime <= 5) {
if (now – lastBlink >= 500) {
blinkState = !blinkState;
lastBlink = now;
switch(currentStage) {
case GREEN_STAGE:
digitalWrite(Green_LED, blinkState);
खंडित;
case RED_STAGE:
digitalWrite(Red_LED, blinkState);
खंडित;
}
}
}
फ्लॅशिंग स्थिती: उर्वरित वेळ 0 पेक्षा जास्त आणि 5 सेकंदांपेक्षा कमी किंवा समान असताना फ्लॅशिंग लॉजिक ट्रिगर होते.
फ्लॅशिंग फ्रिक्वेन्सी: LED स्थिती (चालू किंवा बंद) दर ५०० मिलिसेकंदांनी (०.५ सेकंदांनी) स्विच होते.
• The millis () function is used to get the current time and compare it with last Blink (the last blink time). If the time difference is greater than or equal to 500 milliseconds, the blink State (flashing state) is toggled.
• last Blink is updated to the current time.
एलईडी नियंत्रण:
• During the green light phase (GREEN_STAGE), the green LED will flash.
• During the red light phase (RED_STAGE), लाल एलईडी फ्लॅश होईल. - Screen Initialization and Display Configuration
LGFX gfx;
static const uint16_t screenWidth = 320;
static const uint16_t screenHeight = 240;
Screen Object: LGFX gfx; A screen object gfx is created to control the screen display.
Screen Size: The screen width (screenWidth) and height (screenHeight) are defined as 320
pixels and 240 pixels, respectively
gfx.init();
पिनमोड(१३, आउटपुट);
डिजिटलराइट(0, उच्च);
Screen Initialization:
• The gfx.init() function is called to initialize the screen.
• Pin 0 is set to output mode, and the screen backlight is turned on by calling digital Write(0, HIGH);. - इनिशियलायझेशन सेटिंग्ज
pinMode(Red_LED, OUTPUT);
pinMode(Yellow_LED, OUTPUT);
pinMode(Green_LED, OUTPUT);
Pin Mode Setup: The pinMode() function is used to set the pins for the red, yellow, and green LEDs to output mode.
• The Red_LED (red LED) pin is set to 18.
• The Yellow_LED (yellow LED) pin is set to 20.
• The Green_LED (green LED) pin is set to 19. - Countdown Text Display Area Configuration
const int TEXT_AREA_X = 210;
const int TEXT_AREA_Y = 100;
const int TEXT_AREA_WIDTH = 60;
const int TEXT_AREA_HEIGHT = 30;
Text Area Position and Size: The position and size of the countdown number display area are defined.
• TEXT_AREA_X and TEXT_AREA_Y represent the X and Y coordinates of the text area, respectively.
• TEXT_AREA_WIDTH and TEXT_AREA_HEIGHT represent the width and height of the text area, respectively.
काउंटडाउन क्रमांक प्रदर्शित करताना, इतर भाग (जसे की "काउंटडाउन:" मजकूर) साफ करणे टाळण्यासाठी फक्त या भागातील सामग्री साफ केली जाते. - Time Update and Logic Processing in the Main Loop
uint32_t now = millis();
विलंब(10);
वेळ पुनर्प्राप्ती: लूप() फंक्शनमध्ये, मिलिस() फंक्शनचा वापर मिलिसेकंदांमध्ये वर्तमान वेळ मिळविण्यासाठी केला जातो, जो काउंटडाउन अपडेट करायचा आहे की फेज स्विच करायचा आहे हे निर्धारित करण्यासाठी वापरला जातो.
किमान विलंब: प्रोग्राम खूप वेगाने चालणार नाही याची खात्री करण्यासाठी आणि स्क्रीन रिफ्रेश आणि इतर ऑपरेशन्समध्ये व्यत्यय येऊ नये म्हणून लूपच्या शेवटी एक विलंब (10); जोडला जातो.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the code above, you can adjust the functionality as needed. The overall code implements a traffic light control system based on the Arduino platform, which simulates traffic light changes by controlling different colored LEDs (red, yellow, green) and displays the current countdown time of the traffic light on an LCD screen. When the green light is on, the countdown is displayed. After the yellow light stays on for 3 seconds, it switches to the red light. When the red light is on, the countdown is displayed. In the last 5 seconds, the green or red light will blink to alert.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use an additional library (LovyanGFX-develop),so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries डायरेक्टरीमध्ये जा आणि LovyanGFX-develop फोल्डर डाउनलोड करा.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा ६ – बुद्धिमान स्ट्रीट लाईट
परिचय
या प्रकरणात लाईट मॉड्यूलमधून ब्राइटनेस डेटा कसा गोळा करायचा आणि गोळा केलेल्या डेटाच्या आधारे LED चे बुद्धिमान ऑन/ऑफ नियंत्रण कसे अंमलात आणायचे याचे तपशीलवार स्पष्टीकरण दिले जाईल. वाजवी ब्राइटनेस थ्रेशोल्ड यंत्रणा सेट करून, सिस्टम सभोवतालच्या प्रकाशाच्या तीव्रतेवर आधारित LED ची चालू/बंद स्थिती स्वयंचलितपणे नियंत्रित करू शकते, अनावश्यक प्रकाशयोजना टाळू शकते, प्रभावीपणे ऊर्जेचा वापर कमी करू शकते आणि ऊर्जा संवर्धन आणि कार्यक्षमता सुधारण्याचे ध्येय साध्य करू शकते.
या धड्यात वापरलेले हार्डवेअर:
प्रकाश-नियंत्रित एलईडी प्रणालीचे कार्य तत्व
This system uses a digital light intensity sensor (such as the BH1750) to collect ambient light intensity data and automatically control the on/off state of the LED based on the collected light intensity. The system uses the I2C communication protocol to interact with the light sensor through the microcontroller, obtaining real-time ambient light illuminance.
In terms of hardware, the system connects the sensor to the microcontroller via the I2C bus, periodically reads the sensor data, and determines whether the ambient light intensity meets the criteria for activating the LED based on a set threshold. If the ambient light intensity falls below the set threshold (eg: 100lx), the system will turn on the LED, otherwise, it will turn off. The system uses low-power light sensors (such as the BH1750), with a working current of only 0.12mA, enabling long-term stable operation.
Additionally, the system implements a non-blocking delay mechanism to ensure sampरिअल-टाइम अचूकता राखणे आणि अति जलद अंमलबजावणीमुळे इतर कार्यांमध्ये व्यत्यय टाळणे. हे डिझाइन सभोवतालच्या प्रकाशाच्या तीव्रतेवर आधारित LED च्या चालू/बंद स्थितीचे स्वयंचलित समायोजन सक्षम करते, प्रभावीपणे ऊर्जा वाचवते आणि आवश्यकतेनुसारच प्रकाश चालू आहे याची खात्री करते.
ऑपरेशन इफेक्ट डायग्राम
- Simulating a Dark Environment:
By covering the top of the light sensor with your hand, the ambient light intensity decreases, and the red LED will automatically turn on.
- Simulating a Light Environment: When you remove your hand, the ambient light intensity increases, and the red LED will automatically turn off.

प्रमुख स्पष्टीकरणे
- Hardware Connections and Library Inclusion
#define I2C_SDA 2
#define I2C_SCL 3
#define Red_LED 18
BH1750 lightMeter(0x5c);
I2C संप्रेषण:
Communication between the sensor and Arduino is achieved through two wires (SDA for data, SCL for clock), which is a commonly used low-speed serial communication protocol.
Sensor Address:
Each I2C device has a unique address (0x5C is the default address for the BH1750), which is used by the Arduino to identify the device. - इनिशियलायझेशन सेटिंग्ज
शून्य सेटअप() {
Serial.begin(9600);
विलंब(100);
Wire1.setSDA(I2C_SDA);
Wire1.setSCL(I2C_SCL);
Wire1.begin();
if(lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE, 0x5c,
&Wire1)) {
Serial.println(“BH1750 sensor initialized.”);
} इतर {
Serial.println(“Failed to initialize BH1750 sensor.”);
}
pinMode(Red_LED, OUTPUT);
}
सेन्सर इनिशिएलायझेशन मोड: CONTINUOUS_HIGH_RES_MODE म्हणजे सेन्सर सतत उच्च-रिझोल्यूशन मोडमध्ये कार्य करतो, ज्याची मापन श्रेणी 1-65535 लक्स आहे.
त्रुटी शोधणे: सेन्सर यशस्वी झाला आहे याची खात्री करण्यासाठी त्याचे प्रारंभीकरण if स्टेटमेंट वापरून तपासले जाते, जे डीबगिंगसाठी उपयुक्त आहे. - Last 5 Seconds Flashing Logic
void loop() {
if (lightMeter.measurementReady(true)) {
float lux = lightMeter.readLightLevel();
Serial.print(“Current light level: “);
Serial.print(lux);
Serial.println(” lx”);
if (lux < 100) {
digitalWrite(Red_LED, HIGH);
} इतर {
digitalWrite(Red_LED, LOW);
}
}
विलंब(200);
}
Measurement Readiness Check: measure ment Ready (true) will block the program until the sensor completes a measurement, ensuring the validity of the data.
Light Intensity Reading: read Light Level () returns a floating-point value of light intensity, for example, 50.5 lx represents 50.5 lux.
LED Control Logic: The LED on/off state is controlled through a simple condition check (lux < 100), using digital Write to output high/low voltage.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After learning the above code, you can modify the functionality to create an intelligent lighting control system based on a light sensor. By real-time detection of ambient light intensity and comparing it with a set threshold, the system can automatically control the on/off state of the LED, achieving energy-saving effects.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use an additional library (BH1750),so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries डायरेक्टरीमध्ये जा आणि BH1750 फोल्डर डाउनलोड करा.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा ७ – अल्ट्रासोनिक रेंजिंग डिस्प्ले
परिचय
या विभागात, तुम्ही सेन्सर आणि त्याच्या समोर असलेल्या वस्तूमधील अंतर मोजण्यासाठी अल्ट्रासोनिक सेन्सर मॉड्यूल कसे वापरायचे ते शिकाल. तुम्ही एक साधे अल्ट्रासोनिक अंतर मीटर तयार कराल जे एलसीडी स्क्रीनवर रिअल टाइममध्ये मोजलेले मूल्य प्रदर्शित करेल. या धड्यात अल्ट्रासोनिक अंतर मापनाचे मूलभूत तत्व, सेन्सर आणि डिस्प्लेमधील हार्डवेअर कनेक्शन आणि डेटा गोळा करण्यासाठी आणि परिणाम दृश्यमान करण्यासाठी कोड कसा लिहायचा हे समाविष्ट आहे.
या धड्यात वापरलेले हार्डवेअर:
अल्ट्रासोनिक डिस्टन्स डिस्प्ले सिस्टमचे कार्य तत्व
This ultrasonic distance display system uses the HC-SR04 module for non-contact distance measurement. A 40kHz ultrasonic pulse is triggered via GP9, and the echo is received through GP8. The microcontroller calculates the time difference to determine the distance (with an effective range of 2.8–400 cm). Every 500 ms, the system collects three measurements and applies median filtering to ensure stable readings. The filtered distance data is transmitted to an ST7789 LCD screen over an 80 MHz SPI bus (SCLK = GP6, MOSI = GP7) and displayed in real time at a resolution of 240×320.
Hardware-wise, the ultrasonic module operates at 5V, and its Echo signal is level-shifted to be compatible with the 3.3V system. The display backlight is directly controlled by GPIO0 and configured with a proper refresh rate to prevent flicker. A digital filtering algorithm is integrated to suppress environmental noise, and if invalid data is detected, the screen displays an “Out of range” warning. The entire measurement process uses a non-blocking design to maintain real-time responsiveness.
ऑपरेशन इफेक्ट डायग्राम
एकदा प्रोग्राम चालू झाला की, अल्ट्रासोनिक सेन्सरने मोजलेले रिअल-टाइम अंतर दाखवण्यासाठी एलसीडी स्क्रीन सतत अपडेट होत राहील.
जेव्हा तुम्ही अल्ट्रासोनिक मॉड्यूलसमोर एखादी सपाट वस्तू हलवता तेव्हा स्क्रीनवर प्रदर्शित होणारे अंतर मूल्य गतिमानपणे बदलते.
प्रमुख स्पष्टीकरणे
- Ultrasonic Sensor Initialization and Configuration
const byte triggerPin = 9;
const byte echoPin = 8;
UltraSonicDistanceSensor distanceSensor(triggerPin, echoPin);
अल्ट्रासोनिक सेन्सरसाठी ट्रिगर आणि इको पिन परिभाषित केले जातात आणि सेन्सरचा एक नमुना तयार केला जातो.
The trigger and echo pins for the ultrasonic sensor are defined, and an instance of the sensor is created. The Ultra Sonic Distance Sensor class, provided by a library, simplifies working with ultrasonic sensors. By specifying the trigger and echo pins, you can instantiate a sensor object to begin distance measurements. - Obtaining Stable Distance Readings
float getStableDistance() {
float total = 0;
int validCount = 0;
साठी (int i = 0; i < 3; i++) {
float d = distanceSensor.measureDistanceCm();
if (d > 0 && d < 500) {
total += d;
validCount++;
}
विलंब(20);
}
if (validCount == 0) return -1;
return total / validCount;
}
मापन स्थिरता सुधारण्यासाठी, कोड अनेक वाचन घेतो आणि अधिक अचूक परिणाम देण्यासाठी त्यांची सरासरी काढतो.
The measure Distance Cm function is used to measure distance in centimeters. To reduce errors, the code performs 3 measurements and checks if each value falls within a valid range (greater than 0 and less than 500 cm) using if (d > 0 && d < 500).。If a reading is valid, it is added to the total, and the count of valid readings (valid Count) is incremented. Finally, the average is calculated using total / valid Count. If no valid readings were obtained, -1 is returned to indicate a failed measurement. - Displaying the Distance Value on the Screen
gfx.fillRect(TEXT_AREA_X, TEXT_AREA_Y, TEXT_AREA_WIDTH + 50,
TEXT_AREA_HEIGHT, TFT_BLACK);
gfx.setTextColor(TFT_WHITE);
gfx.setCursor(TEXT_AREA_X, TEXT_AREA_Y);
if (distance > 0) {
gfx.printf(“%.2f cm”, distance);
} इतर {
gfx.print(“Out of range”);
}
कोडचा हा विभाग स्क्रीनवर मोजलेले अंतर प्रदर्शित करणे आणि प्रत्येक अपडेटसह जुने मूल्य साफ करणे हाताळतो.
The gfx. fill Rect function clears a rectangular area of the screen to prevent overlapping digits., gfx. set Text Color sets the text color, gfx. set Cursor defines the text position, and gfx. printf formats and prints the distance value. The format %.2f ensures the number is displayed as a float with two decimal places. If the measured distance is invalid (less than or equal to 0), the message “Out of range” is displayed instead. - Timed Distance Display Update
if (currentTime – lastUpdateTime >= UPDATE_INTERVAL) {
lastUpdateTime = currentTime;
float distance = getStableDistance();
gfx.fillRect(TEXT_AREA_X, TEXT_AREA_Y, TEXT_AREA_WIDTH + 50,
TEXT_AREA_HEIGHT, TFT_BLACK);
gfx.setTextColor(TFT_WHITE);
gfx.setCursor(TEXT_AREA_X, TEXT_AREA_Y);
if (distance > 0) {
gfx.printf(“%.2f cm”, distance);
} इतर {
gfx.print(“Out of range”);
}
}
वारंवार होणाऱ्या अपडेट्समुळे स्क्रीन फ्लिकरिंग किंवा जास्त CPU वापर टाळण्यासाठी अंतर मूल्याची अपडेट वारंवारता टायमरद्वारे नियंत्रित केली जाते.
UPDATE_INTERVAL defines the update interval time (500 milliseconds). The condition current Time – last Update Time
>= UPDATE_INTERVAL checks whether it’s time to update. If it’s time to update, the get Stable Distance function is called to obtain the current stable distance and update the screen display. last Update Time stores the last update timestamp and is used to determine when the next update should occur.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the above code, you can modify its functions to implement an ultrasonic distance measurement system that displays the measured distance on the screen in real time. It periodically (every 500 milliseconds) obtains stable distance data and dynamically updates the display, ensuring both real-time responsiveness and display stability.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use two additional libraries: LovyanGFX-develop and HCSR04.,so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below: https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries डायरेक्टरीमध्ये जा आणि LovyanGFX-develop आणि HCSR04. फोल्डर डाउनलोड करा.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा ८ – अडथळा जवळचा अलार्म
परिचय
In this chapter, we will explore the application of the ultrasonic module and its coordinated control with other modules. By reading distance data from the ultrasonic sensor, we will implement a threshold-based control logic for a vibration motor: when an obstacle is detected within 30 cm, the vibration motor is activated as an alert; when the distance is 30 cm or more, the motor is turned off, indicating a safe state. This mechanism can be used to implement a basic ultrasonic obstacle avoidance function.
या धड्यात वापरलेले हार्डवेअर:
अल्ट्रासोनिक रेंजिंग अँटी-कोलिजन सिस्टमचे कार्य तत्व
The ultrasonic ranging anti-collision system realizes obstacle detection through the HC-SR04 module. It triggers 40kHz ultrasonic pulses via GP9, receives echo signals through GP8, and the MCU calculates the time difference to convert it into a distance value. The system performs measurements every 100ms. When an obstacle within a 30cm range is detected, GP15 outputs a PWM signal to drive the vibration motor for tactile alarm.In hardware design, the 5V-powered ultrasonic module is paired with a 3.3V level conversion circuit. The vibration motor drive uses a MOSFET transistor to ensure sufficient current driving capability (typical operating current: 60mA). The system integrates a digital filtering algorithm to eliminate environmental interference, automatically turns off the motor output in case of anomalies, and outputs distance data and system status in real time via a serial port. It adopts non-blocking programming design to ensure real-time response performance, while reducing system power consumption through
appropriate delay control.
ऑपरेशन इफेक्ट डायग्राम
- Simulating Obstacle Approaching: Slowly move a hand or object closer to the ultrasonic sensor (distance < 30 cm).
The vibration motor should activate, indicating the presence of an obstacle.
- Simulating Obstacle Moving Away: Remove the object (distance ≥ 30 cm). he vibration motor should stop, indicating a safe zone.

प्रमुख स्पष्टीकरणे
- Ultrasonic Sensor Initialization and Configuration
#include <HCSR04.h>
const byte triggerPin = 9;
const byte echoPin = 8;
UltraSonicDistanceSensor distanceSensor(triggerPin, echoPin);
Library Inclusion: #include <HCSR04.h> includes the ultrasonic sensor library, which provides convenient functions for distance measurement.
पिन व्याख्या:
• triggerPin is connected to the sensor’s trigger pin and used to initiate the measurement.
• echo Pin is connected to the sensor’s echo pin and used to receive the reflected ultrasonic signal.
Sensor Object Creation: An ultrasonic sensor object named distance Sensor is created using Ultra Sonic Distance Sensor distance Sensor (trigger Pin, echo Pin); for subsequent distance measurements. - Distance Measurement and Update Logic
const unsigned long UPDATE_INTERVAL = 100;
unsigned long lastUpdateTime = 0;
if (currentTime – lastUpdateTime >= UPDATE_INTERVAL) {
lastUpdateTime = currentTime;
float distance = distanceSensor.measureDistanceCm();
}
अपडेट इंटरव्हल: UPDATE_INTERVAL दोन अंतर मोजमापांमधील वेळ मध्यांतर परिभाषित करते, येथे ते १०० मिलिसेकंदांवर सेट केले आहे.
वेळ परिवर्तनशील: शेवटच्या अंतराच्या अपडेटची वेळ रेकॉर्ड करण्यासाठी lastUpdateTime वापरला जातो.
Time Check: In the loop() function, millis () is used to get the current time (current Time), and it checks whether the time since the last update has reached UPDATE_INTERVAL.
Distance Measurement: If the interval condition is met, the function distance Sensor. measure Distance Cm () is called to measure the distance in centimeters. - Distance Validation and Logic Handling
if (distance > 0) {
Serial.print(“अंतर: “);
अनुक्रमांक.मुद्रण(अंतर);
Serial.println("cm");
if (distance < 30.0) {
digitalWrite(vibratePin, HIGH);
Serial.println(“Obstacle detected! Vibration motor ON.”);
} इतर {
digitalWrite(vibratePin, LOW);
Serial.println(“Safe distance. Vibration motor OFF.”);
}
} इतर {
digitalWrite(vibratePin, LOW);
Serial.println(“Out of range or measurement error.”);
}
प्रमाणीकरण तपासणी: जर मोजलेले अंतर 0 सेमी पेक्षा जास्त असेल, तर मोजमाप वैध मानले जाते.
अंतर प्रदर्शन: मोजलेले अंतर सिरीयल मॉनिटरद्वारे प्रिंट केले जाते.
Logic Processing:
• If the distance is less than 30 cm, it indicates an obstacle is detected. The vibration motor is turned on (digital Write (vibrate Pin, HIGH)), and the message “Obstacle detected! Vibration motor ON.” is printed via serial.
• If the distance is greater than or equal to 30 cm, it indicates a safe distance. The motor is turned off (digital Write (vibrate Pin, LOW)), and the message “Safe distance. Vibration motor OFF.” is printed via serial.
Error Handling: If the measured distance is less than or equal to 0 cm, it indicates an invalid or out-of-range measurement. The motor is turned off and an error message is printed via serial. - Vibration Motor Control
const int vibratePin = 15;
pinMode(vibratePin, OUTPUT);
digitalWrite(vibratePin, LOW);
Pin Definition: vibratePin defines the pin connected to the vibration motor.
Pin Mode Configuration: In the setup() function, pinMode(vibrate Pin, OUTPUT) sets the pin mode to output.
Initial State: The motor is turned off by default using digital Write (vibrate Pin, LOW). - Serial Communication Initialization
Serial.begin(9600);
Serial.println(“System ready. Starting distance monitoring…”);
Serial Initialization:
• Serial.begin(9600) initializes serial communication with a baud rate of 9600.
Waiting for Connection: while (!Serial) waits for the serial port to connect (required on some boards).
Startup Message: Serial. println(“System ready. Starting distance monitoring…”) prints a startup message to indicate the system is ready. - Time Update and Logic Handling in the Main Loop
स्वाक्षरी नसलेला लांब चालू वेळ = मिलिस(); विलंब(१०);
Time Acquisition: In the loop() function, millis() is used to get the current time (in milliseconds) to determine whether it’s time to perform a new distance measurement and control logic.
Minimum Delay: Adding delay(10); at the end of the loop() helps prevent excessively high loop frequency, reducing CPU load and avoiding unnecessary processing.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After completing the code implementation above, you’ve successfully built a proximity alert system using an ultrasonic sensor. This system continuously monitors the distance to obstacles ahead—triggering a vibration motor alarm when objects come within 30 cm, while maintaining a “safe” status at greater distances. It also incorporates error handling and timed detection mechanisms for reliable operation.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use an additional library (HCSR04),so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries डायरेक्टरीमध्ये जा आणि HCSR04 फोल्डर डाउनलोड करा.

- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा ९ – ब्राइटनेस डिस्प्ले
परिचय
या प्रकरणात, तुम्ही स्लाईड पोटेंशियोमीटर वापरून LED ची ब्राइटनेस कशी समायोजित करायची ते शिकाल, ब्राइटनेसला 10 पातळ्यांमध्ये विभागून. पोटेंशियोमीटरच्या रेझिस्टन्समधील बदल वाचून, तुम्ही PWM (पल्स विड्थ मॉड्युलेशन) सिग्नलचे आउटपुट नियंत्रित कराल, ज्यामुळे गुळगुळीत, रेषीय ब्राइटनेस समायोजन आणि लेव्हल-आधारित डिस्प्ले मिळेल.
या धड्यात वापरलेले हार्डवेअर:
पीडब्ल्यूएम डिमिंग सिस्टमचे कार्य तत्व
This intelligent dimming system uses a sliding potentiometer as the input signal. The MCU’s 12-bit ADC module converts the 0–900 mV analog voltage into a digital signal, which is then mapped to a 0–255 range PWM duty cycle. This signal drives RGB LEDs connected to three GPIO pins to achieve smooth brightness adjustment. An 80 MHz SPI bus is used to control a 240×320 ST7789 display in real time to show the brightness level. The hardware includes a voltage divider input circuit, PWM driving circuits (with 220 Ω current-limiting resistors for each LED), SPI display interface, and GPIO-controlled backlight. The system uses a non-blocking architecture to sample and update every 100 ms. With the help of the LVGL graphics library, efficient partial screen refreshing is achieved. Digital filtering ensures signal stability and enhances the system’s responsiveness and reliability.
ऑपरेशन इफेक्ट डायग्राम
पोटेंशियोमीटर स्लाइड करा आणि LED ब्राइटनेस बदल आणि स्क्रीनवरील ब्राइटनेस लेव्हल डिस्प्ले दोन्ही पहा.
- 1. Set to 10 (Maximum Brightness): Slide the potentiometer and observe both the LED brightness change and the on-screen brightness level display.
- 2. Set to 4 (Medium Brightness): Move the potentiometer to the middle position. The LED will glow at a moderate level, and the screen will show: “Brightness: 4”.

- 3. Set to 0 (Off):
Slide the potentiometer completely to the left.The LED will turn off, and the screen will indicate: “Brightness: 0”.
प्रमुख स्पष्टीकरणे
- Display Initialization and Configuration
class LGFX : public lgfx::LGFX_Device { … }
LGFX gfx;
Custom Display Class: A custom LGFX class is defined, inheriting from lgfx::LGFX_Device, to configure display hardware parameters (eg: SPI bus, touchscreen, etc.).
Display Instance: A gfx object is instantiated to control the display.
Display Initialization: In the setup() function, gfx.init() is called to initialize the display. The backlight pin (Pin 0) is set to output mode, and the backlight is turned on.
Screen Clear & Text Setup: The screen is cleared using gfx.fillScreen(TFT_BLACK). Text size and color are configured, and “Brightness:” is printed on the screen. - Reading the Potentiometer (Analog Slider)
इंट अॅनालॉग व्हॅल्यू = अॅनालॉग रीड(स्लाइडर_पिन);
Pin Definition: SLIDER_PIN is defined as the analog input pin connected to the potentiometer (Pin 28).
Reading Analog Values: The potentiometer’s analog value is read using analogRead(SLIDER_PIN), typically returning a range of 0 to 4095 (for 12-bit ADC resolution). - Mapping Analog Values to PWM & Brightness Levels
int pwmValue = map(analogValue, 0, 900, 0, 255);
int level = map(analogValue, 0, 900, 0, 10);
PWM Value Mapping: The potentiometer’s analog input range (0–900) is mapped to a PWM output range (0–255) to control LED brightness.
Brightness Level Mapping: The analog value is also converted to an integer brightness level (0–10) for on-screen display.
Value Clamping: The constrain() function ensures mapped values stay within valid ranges: PWM output (0–255) and brightness level (0–10). - LED PWM Control
analogWrite(RED_LED_PIN, pwmValue);
analogWrite(YELLOW_LED_PIN, pwmValue);
analogWrite(GREEN_LED_PIN, pwmValue);
Pin Definitions: Pins connected to the red, yellow, and green LEDs are defined for PWM output.
PWM Output: The mapped PWM value (0–255) is sent to the LED pins using analogWrite(), controlling LED brightness. - Displaying Brightness Level on Screen
if (level != lastLevel) {
lastLevel = level;
gfx.fillRect(240, 100, 60, 30, TFT_BLACK);
gfx.setCursor(240, 100);
gfx.setTextColor(TFT_GREEN);
gfx.print(level);
}
Brightness Level Change Detection: The display updates only if the current brightness level differs from the previously recorded lastLevel.
Clearing Screen & Setting Cursor: gfx.fillRect() clears the previous brightness level display area.The cursor position is reset for new text output.
Displaying Brightness Level: The text color is set to green, and the new brightness level is printed.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After learning the above code, a brightness adjustment system based on a slide potentiometer is implemented. The system reads the analog value of the slide potentiometer, maps it to a brightness level from 0 to 10, controls the brightness of red, yellow, and green tri-color LEDs, and real-time displays the brightness level on an ST7789 display, while supporting serial port debugging information output.The code implements an LED brightness adjustment system based on a slide potentiometer. By integrating analog signal acquisition and PWM control technology, the brightness is divided into 10 levels, which are real-timely displayed on the TFT display.
It also supports touch interaction functions.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use an additional library (LovyanGFX-develop), so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries directory and download the Lovyan GFX-develop and Lovyan GFX-develop folder.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा १० – तापमान आणि आर्द्रता शोधणारी प्रणाली
परिचय
हा अध्याय तापमान आणि आर्द्रता सेन्सर मॉड्यूलच्या वापरावर लक्ष केंद्रित करेल, ज्यामध्ये सेन्सर डेटा वाचणे आणि स्क्रीनवर तापमान आणि आर्द्रता मूल्ये रिअल-टाइम प्रदर्शित करणे समाविष्ट आहे. सरावाद्वारे, तुम्ही I2C किंवा सिंगल-वायर कम्युनिकेशन प्रोटोकॉल तसेच डेटा संपादन आणि प्रदर्शनाचे परस्परसंवादी तर्कशास्त्र आत्मसात कराल.
या धड्यात वापरलेले हार्डवेअर:
तापमान आणि आर्द्रता देखरेख प्रदर्शन प्रणालीचे कार्य तत्व
The system is based on an SPI-driven 240×320 ST7789 LCD with an FT5x06 touchscreen, and connects to a DHT20 temperature-humidity sensor via I2C (Wire1).
The main controller (eg: ESP32) reads temperature and humidity data once every 1 second. After processing by the LovyanGFX library, the data is centrally displayed on the screen (humidity in blue, temperature in red). The SPI is configured for 80MHz high-speed communication, while I2C operates at 400kHz. The touchscreen is controlled via INT/RST pins. GPIO0 drives the backlight, and non-blocking timing (millis()) ensures real-time refresh to avoid screen afterimages.
ऑपरेशन इफेक्ट डायग्राम
प्रोग्राम सुरू केल्यानंतर, सिस्टम तापमान-आर्द्रता सेन्सरमधून सतत डेटा गोळा करेल आणि तो रिअल टाइममध्ये स्क्रीनवर प्रदर्शित करेल.
- 1. Normal Environment Observation:
Place the sensor in a normal room-temperature environment and observe the temperature and humidity data displayed on the screen.
- 2. Gently press your finger against the surface of the DHT20 temperature-humidity sensor and observe the data changes on the display.
प्रमुख स्पष्टीकरणे
- LGFX Class Constructor
LGFX(void) {
auto cfg = _bus_instance.config();
cfg.spi_host = 0;
cfg.spi_mode = 0;
cfg.freq_write = 80000000;
cfg.pin_sclk = 6;
cfg.pin_mosi = 7;
cfg.pin_miso = -1;
cfg.pin_dc = 16;
_bus_instance.config(cfg);
_panel_instance.setBus(&_bus_instance);
…
_panel_instance.setTouch(&_touch_instance);
setPanel(&_panel_instance);
}
कस्टम डिस्प्ले क्लास: हा कस्टम LGFX क्लासचा कन्स्ट्रक्टर आहे, जो संपूर्ण LovyanGFX स्क्रीन सुरू करण्यासाठी कोर म्हणून काम करतो.
cfg.spi_host = 0;: VSPI निवडते (ESP32 पैकी SPI0)
cfg.freq_write = 80000000;: स्क्रीन रिफ्रेश रेट वाढविण्यासाठी उच्च-फ्रिक्वेन्सी लेखन गती (80MHz) सेट करते.
cfg.pin_*: विशिष्ट स्क्रीन पिन (SCLK, MOSI, DC, इ.) बांधते.
_panel_instance.setBus(…): Binds the SPI bus to the screen panel.
_panel_instance.setTouch(…): Mounts the touchscreen driver to the panel.
setPanel(…): Finally applies the configuration to LGFX_Device.
Function: Constructs and initializes the hardware abstraction layer for SPI display and touchscreen, serving as the foundation for using the LovyanGFX library. - Sensor and I2C Initialization
Wire1.setSDA(2);
Wire1.setSCL(3);
Wire1.begin();
DHT.begin();
This section is responsible for initializing the second I2C bus Wire1 for connecting the DHT20 sensor.
Wire1.setSDA(2); and setSCL(3);: Assigns SDA and SCL pins to GPIO2 and GPIO3 to avoid conflicts with the main I2C bus (eg: the I2C used by the touchscreen).
DHT.begin();: Invokes the initialization function of the DHT20 library.
Function: Enables the I2C communication channel with DHT20 to facilitate reading temperature and humidity data. - Timed Reading and Screen Update
if (currentMillis – preMillis >= interval) {
if (millis() – DHT.lastRead() >= 1000) {
int status = DHT.read();
if (status == DHT20_OK) {
gfx.fillScreen(TFT_BLACK);
…
gfx.printf(“%.1f %%”, humidity);
gfx.printf(“%.1f C”, temperature);
}
}
preMillis = currentMillis;
}
हा लूपचा मुख्य भाग आहे():
• Execute DHT.read() every 1000ms (1 second).
• If the reading is successful
(DHT20_OK), clear the screen and display the latest temperature and humidity data.
• Use gfx.printf() combined with setCursor() to center the data display.
कार्य: ग्राफिकल डिस्प्लेसाठी तापमान/आर्द्रतेचे रिअल-टाइम वाचन आणि रिफ्रेश लॉजिक लागू करा. - Centered Display Technique
int centerX = screenWidth / 2;
gfx.setCursor(centerX – 6 * 3 * 5, 60);
gfx.print(“Humidity:”);
gfx.setCursor(centerX – 6 * 3 * 2, 100);
gfx.printf(“%.1f %%”, humidity);
centerX is the horizontal midpoint coordinate of the screen.
6 * 3 * N is the method to estimate text width:
• Each character is approximately 6 pixels wide (default font).
• 3 is the text magnification factor (set via setTextSize(3)).
• N is the number of characters (estimated based on actual content).
Function: Achieve horizontally centered text alignment by manually calculating the starting coordinates.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
वरील कोड शिकल्यानंतर, Arduino-आधारित पर्यावरणीय देखरेख प्रणाली लागू केली जाते. ही प्रणाली DHT20 सेन्सर वापरून रिअल-टाइम तापमान आणि आर्द्रता डेटा गोळा करते, जो ST7789 स्क्रीनवर दृश्यमानपणे प्रदर्शित होतो. ही प्रणाली दर सेकंदाला एकदा डेटा अपडेट करते, ज्यामुळे सध्याची सभोवतालची आर्द्रता (टक्केवारी) सादर होते.tage) आणि तापमान (सेल्सिअसमध्ये) स्पष्ट आणि वाचनीय पद्धतीने, विविध प्रकारच्या डेटामध्ये फरक करण्यासाठी वेगवेगळ्या रंगांचा वापर केला जातो.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we used two additional library files: DHT20 and LovyanGFX-develop.,so
it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries डायरेक्टरीमध्ये जा आणि DHT20 आणि LovyanGFX-develop फोल्डर डाउनलोड करा.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा ११ – सर्वो नियंत्रण
परिचय
या विभागात सर्वो मोटर मॉड्यूलच्या नियंत्रण पद्धतीचे तपशीलवार वर्णन केले जाईल, ज्यामध्ये PWM नियंत्रण सिग्नल कॉन्फिगर करून 0 ते 180 अंशांच्या श्रेणीत सर्वोचा परस्पर स्विंग लक्षात येईल. कोर्स ऑपरेशन दरम्यान, सर्वो 0 अंशांपासून 180 अंशांपर्यंत फिरण्याची आणि नंतर प्रीसेट लॉजिकनुसार 0 अंशांवर परत येण्याची नियतकालिक गती पूर्ण करेल.
या धड्यात वापरलेले हार्डवेअर:
सर्वो मोटर नियंत्रणाचे कार्य तत्व
The system uses the Arduino Servo library to drive a servo motor connected to pin GP13, employing PWM signals to control the rotation angle. The pulse width is set to range from 450 to 2520 microseconds, corresponding to a mechanical rotation of 0-180 degrees.
The main loop implements a progressive angle adjustment, incrementing or decrementing by 1 degree every 15 milliseconds to achieve smooth reciprocating motion.
ऑपरेशन इफेक्ट डायग्राम
- फॉरवर्ड रोटेशन:
After the program starts, the servo motor will slowly rotate from the 0-degree position to the 180-degree position. - उलट रोटेशन:
Upon reaching the 180-degree position, the servo motor will automatically reverse its rotation and return to the 0-degree position, forming a continuous reciprocating swing cycle.

प्रमुख स्पष्टीकरणे
- LGFX Class Constructor
#समाविष्ट करा
Servo myservo;
#include <Servo.h>: Loads the official Arduino Servo library, which encapsulates the PWM generation and timing control functions required for communicating with servo motors.
Servo myservo;: Instantiates a Servo object named myservo in the global scope. Subsequent operations on myservo (such as attach() and write()) will be mapped to specific hardware pins and signals of the servo motor. - Binding the Servo to a Pin and Setting Pulse Width Range in setup()
शून्य सेटअप() {
myservo.attach(13, 450, 2520);
}
myservo.attach(pin, minPulse, maxPulse);
• pin=13: Connect the servo signal wire to Arduino digital pin 13.
• 450 (minimum pulse width): Unit is microseconds (μs). The pulse width for 0° of a standard servo is ~500μs; adjusting to 450μs ensures the servo can reach or slightly exceed the minimum angle.
• 2520 (maximum pulse width): Corresponds to the servo’s maximum angle (180°). The standard value is ~2500μs; setting to 2520μs ensures the servo can reach or slightly exceed the maximum angle.
Function: By specifying minPulse/maxPulse, calibrate the 0° and 180° output positions to the servo’s actual physical limits. If these parameters are omitted, the library uses default values (544 μs-2400μs), which may need adjustment for servos with different travel ranges. - Forward and Reverse Sweep For Loops in loop()
void loop() {
for (int pos = 0; pos <= 180; pos++) {
myservo.write(pos);
विलंब(15);
}
for (int pos = 180; pos >= 0; pos–) {
myservo.write(pos);
विलंब(15);
}
}
1. for (int pos = 0; pos <= 180; pos++)
• This loop increments pos from 0 to 180 in steps of 1°. Combined with myservo.write(pos), it enables the servo to “smoothly rotate from the minimum angle to the maximum angle”.
• myservo.write(pos): Passes the current angle value (in degrees) to the Servo library, which converts it to the corresponding pulse width signal (450μs→0°, 2520μs→180°) and outputs it to the servo within a 20ms cycle.
• delay(15): Pauses for 15ms after each angle update to allow the servo sufficient time to reach the target position. A 15ms delay with a 1° step produces a smooth sweeping motion. Larger delays result in slower rotation, while smaller delays increase speed but may cause jitter or stuttering.
2.for (int pos = 180; pos >= 0; pos–)
• Reverse logic of the previous loop, decrementing pos from 180 to 0 to rotate the servo “from the maximum angle back to the minimum angle”.
• Similarly uses myservo.write(pos) to update the angle and delay(15) to control speed.
3. Function: These two opposing for loops create a complete “sweep-and-return” operation, causing the servo to oscillate back and forth.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the code above, you have implemented a servo control system that enables the servo to perform slow reciprocating swings between 0 and 180 degrees.
Starting from 0 degrees, the servo gradually rotates to 180 degrees at a rate of 15 milliseconds per step, then returns to 0 degrees at the same speed, repeating this cycle continuously.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use an additional library (Servo),so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries डायरेक्टरीमध्ये जा आणि सर्वो फोल्डर डाउनलोड करा.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा १२ – आयआर कंट्रोल एलईडी
परिचय
हा विभाग इन्फ्रारेड रिमोट कंट्रोल वापरून LEDs चे वैविध्यपूर्ण नियंत्रण कसे अंमलात आणायचे यावर लक्ष केंद्रित करेल, ज्यामध्ये सिंगल-कलर LED लाइटिंग, मल्टी-कलर LED फ्लॅशिंग आणि रनिंग लाइट इफेक्ट्स यांचा समावेश आहे. तुम्ही इन्फ्रारेड सिग्नल रिसेप्शन आणि LED ड्रायव्हिंगमधील परस्परसंवादी लॉजिकमध्ये प्रभुत्व मिळवाल.
या धड्यात वापरलेले हार्डवेअर:
इन्फ्रारेड रिमोट सेन्सर ऑपरेशनचे तत्व
इन्फ्रारेड रिमोट सेन्सर नियंत्रण कार्ये साध्य करण्यासाठी इन्फ्रारेड सिग्नल प्राप्त करून कार्य करतो. ट्रान्समीटर नियंत्रण सूचनांना विशिष्ट वारंवारतेच्या इन्फ्रारेड प्रकाश सिग्नलमध्ये रूपांतरित करतो. सेन्सर हे सिग्नल प्राप्त करतो, त्यांना पुन्हा नियंत्रण सूचनांमध्ये रूपांतरित करतो आणि नंतर मायक्रोकंट्रोलर संबंधित ऑपरेशन्स करतो.
एलईडीचे कार्य तत्व
LED (प्रकाश उत्सर्जक डायोड) च्या केंद्रस्थानी एक अर्धसंवाहक PN जंक्शन असते. जेव्हा फॉरवर्ड बायस व्हॉल्यूमtage is applied, electrons from the N-type region recombine with holes from the P-type region near the junction. During this recombination, electrons drop from a higher energy level to a lower one, releasing the excess energy in the form of photons—producing light. The color (or wavelength) of the emitted light is determined by the energy band gap of the semiconductor material. This process is a direct application of electroluminescence.
इन्फ्रारेड रिमोट कंट्रोल ऑपरेशनचे तत्व
इन्फ्रारेड रिमोट कंट्रोल बटणांद्वारे नियंत्रण आदेश इनपुट करून कार्य करते. मायक्रोकंट्रोलर या आदेशांना इन्फ्रारेड सिग्नलमध्ये एन्कोड आणि मॉड्युलेट करतो, जे नंतर इन्फ्रारेड एमिटरद्वारे प्रसारित केले जातात. रिसीव्हिंग एंडचा इन्फ्रारेड सेन्सर सिग्नल कॅप्चर करतो, त्यांना पुन्हा कमांडमध्ये डीमॉड्युलेट करतो आणि संबंधित ऑपरेशन्स करण्यासाठी डिव्हाइसला चालवतो.
ऑपरेशन इफेक्ट डायग्राम
• Press “5”: The three-color LEDs light up sequentially to create a chasing light effect;
• Press “6”: All LEDs turn off.
प्रमुख स्पष्टीकरणे
- Hardware Connections and Library Inclusion
if (IrReceiver.decode()) {
unsigned long code = IrReceiver.decodedIRData.command;
handleIR(code);
IrReceiver.resume();
}
Function: Receive infrared signals from TV/air conditioner remotes, etc.
महत्त्वाचे मुद्दे:
• decode() acts like “ears” to monitor signals.
• command serves as a unique identifier for each button (eg: 0x0C = Button 1).
• resume() functions as a “continue listening” instruction. - Button Command Processing (Control Hub)
void handleIR(unsigned long code) {
turnOffAll();
effectMode = 0;
switch(code) {
case 0x0C: digitalWrite(RED_LED_PIN, HIGH); break;
case 0x18: digitalWrite(YELLOW_LED_PIN, HIGH); break;
case 0x5E: digitalWrite(GREEN_LED_PIN, HIGH); break;
case 0x08: effectMode = 1; break;
case 0x1C: effectMode = 2; break;
case 0x5A: turnOffAll(); break;
}
}
Core Logic:
• First three buttons: Control red/yellow/green LEDs individually.
• Buttons 4/5: Trigger two lighting effects.
• Button 6: Emergency shutdown for all LEDs.
Special Design:
• Call turnOffAll() before each button press to avoid conflicts.
• Use effect Mode variable to track the current lighting effect. - Lighting Effect Processing (Dynamic Effects)
void handleEffects() {
if(effectMode == 1) {
if(millis() – lastEffectTime > 300) {
bool on = !on;
digitalWrite(RED_LED_PIN, on);
digitalWrite(YELLOW_LED_PIN, on);
digitalWrite(GREEN_LED_PIN, on);
lastEffectTime = millis();
}
}
else if(effectMode == 2) {
if (millis() – lastEffectTime > 300) {
switch (effectStep % 3) {
केस 0:
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(YELLOW_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, LOW);
खंडित;
केस 1:
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(YELLOW_LED_PIN, HIGH);
digitalWrite(GREEN_LED_PIN, LOW);
खंडित;
केस 2:
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(YELLOW_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, HIGH);
खंडित;
}
effectStep++;
lastEffectTime = millis();
}
}
}
फ्लॅशिंग मोड:
• Toggle all LEDs on/off simultaneously every 300ms.
• Use on = !on to invert the state (on → off → on).
लाईट मोडचा पाठलाग:
• Light up LEDs sequentially in the order: red → yellow → green.
• Use effect Step % 3 to cycle between 0-2.
• Increment effect Step++ to advance the lighting sequence. - सहाय्यक कार्य
void turnOffAll() {
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(YELLOW_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, LOW);
}
महत्त्वाची भूमिका: सर्व दिवे कधीही ताबडतोब बंद करता येतील याची खात्री करा.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the provided code, you have successfully implemented an infrared
remote-controlled LED system. This system receives specific infrared signals (corresponding to buttons 1-6 on the remote) to control the on/off states and display modes of three LEDs (red, yellow, and green). The detailed functions are as follows:
- Buttons 1-3: Turn on the corresponding LED (red, yellow, or green, respectively).
- Button 4: Activates synchronized blinking of all three LEDs.
- Button 5: Triggers a running-light effect (sequential cycling through the three LEDs).
- Button 6: Turns off all LEDs.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use an additional library (IRremote),so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries directory and download the IR remote folder.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा १३ – हवामानाची आठवण
परिचय
This project is based on the All_in_one_Starter_Kit_for_Pico2 development board. It uses a DHT20 sensor to collect real-time environmental temperature and humidity data, and controls a TFT display, LED lights, and a buzzer based on set thresholds to achieve graphical display of environmental conditions and abnormal warning functions.
It’s ideal for basic learning and practical applications in intelligent environmental monitoring scenarios. The project uses Square Line Studio to design the screen interface and employs the LVGL library for display and interaction control, enabling dynamic visualization of temperature and humidity information and interface prompts for abnormal conditions.
या धड्यात वापरलेले हार्डवेअर:
तापमान आणि आर्द्रता सेन्सरचे कार्य तत्व
सेन्सर संवेदन घटकांद्वारे पर्यावरणीय मापदंड मोजतो. तापमान शोधणे थर्मिस्टर्स किंवा सेमीकंडक्टर पदार्थांवर अवलंबून असते ज्यांचे प्रतिकार/व्हॉल्यूमtage तापमानानुसार बदलते. आर्द्रता संवेदन सामान्यतः कॅपेसिटिव्ह किंवा रेझिस्टिव्ह घटकांचा वापर करते ज्यामध्ये आर्द्रतेसह डायलेक्ट्रिक स्थिरांक/प्रतिरोध बदल होतो. बिल्ट-इन सिग्नल कंडिशनिंग MCU प्रक्रियेसाठी अॅनालॉग सिग्नलला डिजिटल आउटपुटमध्ये रूपांतरित करते.
बजर ऑपरेशनचे तत्व
The buzzer generates sound by vibrating a diaphragm driven by an electrical signal.
When an alternating current is applied, the diaphragm vibrates rapidly due to magnetic or piezoelectric effects, producing sound. The pitch and frequency are determined by the current frequency, and it is commonly used for alerts or alarms.
एलईडीचे कार्य तत्व
LED (प्रकाश उत्सर्जक डायोड) च्या केंद्रस्थानी एक अर्धसंवाहक PN जंक्शन असते. जेव्हा फॉरवर्ड बायस व्हॉल्यूमtage is applied, electrons from the N-type region recombine with holes from the P-type region near the junction. During this recombination, electrons drop from higher energy level to a lower one, releasing the excess energy in the form of photons—producing light. The color (or wavelength) of the emitted light is determined by the energy band gap of the semiconductor material. This process is a direct application of electroluminescence.
डिस्प्ले स्क्रीनचे कार्य तत्व
डिस्प्ले ड्रायव्हर सर्किट्सद्वारे प्रत्येक पिक्सेलची चमक/रंग नियंत्रित करतो. मुख्य आयसी इमेज डेटाला इलेक्ट्रिकल सिग्नलमध्ये रूपांतरित करतो, जो लाईन-बाय-लाइन रिफ्रेशिंगसाठी रो/कॉलम ड्रायव्हर आयसीमध्ये प्रसारित केला जातो. एलसीडी व्हॉल्यूमसह लिक्विड क्रिस्टल अलाइनमेंट समायोजित करतात.tage प्रकाशाचे मॉड्युलेट करण्यासाठी, तर OLEDs थेट प्रकाश उत्सर्जित करतात. वेळेचे नियंत्रण करणारे उपकरण सिग्नल सिंक्रोनाइझेशन सुनिश्चित करते जेणेकरून कृत्रिमता रोखता येईल.
ऑपरेशन इफेक्ट डायग्राम
- 1. When the temperature from the DHT20 sensor exceeds 25°C, the yellow LED should turn on, and the TFT display shows “Temperature is high”.

- 2. When the temperature rises above 30°C, the red LED turns on, the TFT display shows “It’s hot”, and the yellow LED turns off.

- 3. When humidity drops below 40%, the buzzer sounds, the TFT display shows “Air is dry”, and the yellow LED turns on if the temperature exceeds 25°C.

- 4. Press the LED button once, the green LED turns on. Press the LED button again, the green LED turns off.

Before we begin designing the user interface we need, it’s important to understand a key concept—LVGL. LVGL is a lightweight graphics library that gives us powerful tools to build intuitive and visually appealing interfaces. It forms the core of Square Line Studio and serves as the foundation for the design work ahead.
Once we grasp the basics of how LVGL works, we’ll move on to hands-on practice:
installing Square Line Studio, designing a graphical interface, and exporting it into runnable code.
So, let’s start by exploring the concept of LVGL—this will be the first building block of our UI design journey.
LVGL म्हणजे काय?
LVGL (Light and Versatile Graphics Library) is a free and open-source graphics library designed specifically for embedded systems with limited resources. It provides all the essential features needed to build smooth and visually appealing user interfaces, including a wide range of widgets, graphic effects, animations, and event handling.
LVGL is lightweight, highly portable, and supports hardware acceleration—making it a powerful choice for microcontroller-based projects.
स्क्वेअरलाइन स्टुडिओ
Square Line Studio is a visual UI design tool (IDE) built on top of LVGL. It features an intuitive drag-and-drop interface designer, real-time previews, and powerful property and event editors—all of which allow developers to create embedded interfaces without writing a lot of low-level code. The tool automatically generates C/C++ code based on LVGL, greatly speeding up development and delivering a true “what-you-see-is-what-you-get” design experience.
स्क्वेअरलाइन स्टुडिओ स्थापित करणे
- अधिकाऱ्याला भेट द्या webसाइट
आपले उघडा web browser and go to the official Square Line Studio download page: Square Line Studio: https://squareline.io/
- Choose the right version
Select the installation package that matches your operating system (Windows, macOS, or Linux).
For this guide, we’ll use the Windows version as an exampले. आवृत्ती १.३.४ डाउनलोड करण्याची शिफारस केली जाते, कारण त्यात एक सिम्युलेशन वैशिष्ट्य आहे जे आवृत्ती १.४ मध्ये गहाळ आहे.
- इंस्टॉलर डाउनलोड करा
Click the download button and wait for the download to finish. Once it’s complete, double-click the setup.exe file.
- इंस्टॉलर चालवा
Follow the prompts in the installation wizard.
Click “Install” .
स्थापना प्रक्रिया पूर्ण होण्याची प्रतीक्षा करा.
- 5. Finish installation
स्थापना पूर्ण.
स्क्वेअरलाइन स्टुडिओसह प्रकल्प निर्मिती आणि UI डिझाइन
A detailed operational guide for designing UI with Squareline Studio and integrating it with Arduino code, covering the complete process of project creation, material addition, label setup, code export, and main program integration:
- Launch Squareline Studio
Register or log in to an account as prompted (a 30-day trial period is available for first-time use. Please register an account as instructed. When you log in to your account next time, you will continue to use it.)
या चरणांचे अनुसरण करून एक नवीन प्रकल्प तयार करा:
• 1. Select the creation entry: Click the “Create” button at the top of the interface to start the project creation process.
• 2. Determine the LVGL major version: At “Select major LVGL version,” select version 9.2.
• 3. Select the hardware/platform type: Choose “Desktop.”
• 4. Select the project template: Choose the corresponding template (eg: “CMake/Eclipse/VScode with SDL for development on PC,” a template for developing UI on PC based on SDL).
• 5. Project name: lesson13.spj
• 6.Storage path
• 7 . Screen resolution: 320*240 (designed according to the screen specifications)
• 8. Color depth: 32bit
• 9. LVGL version:9.2.2
• 10. Complete creation: After confirming the parameters are correct, click the green “CREATE” button in the lower-right corner to generate the project. - Add Design Materials
The tasks we need to complete are: real-time display of temperature values, reminder messages, and humidity values through the LVGL graphic interface. When the temperature is too high, turn on the red or yellow light as a prompt; when the humidity is too low, activate the buzzer alarm; and turn the green light on and off by clicking the button in the lower-right corner of the graphic interface (to verify the touch function of the display).
Open the provided images and add them in.
Select the designed background images, temperature-humidity icons, and other materials to add.
Select the designed background images, temperature-humidity icons, and other materials to add.
पुढे, UI इंटरफेसच्या मूलभूत पार्श्वभूमी म्हणून संपूर्ण कॅनव्हास क्षेत्र कव्हर करण्यासाठी पार्श्वभूमी प्रतिमा कॅनव्हासच्या मध्यभागी ड्रॅग करा. उजव्या बाजूच्या प्रॉपर्टीज पॅनेलमध्ये (IMAGE->Transform), पार्श्वभूमी प्रतिमा कॅनव्हासमध्ये पूर्णपणे बसते याची खात्री करण्यासाठी निर्देशांक (उदा. X:0, Y:0) आणि आकार अचूकपणे सेट करा.
Drag the temperature icon, reminder icon, and humidity icon to appropriate positions on the canvas in sequence.
You can arrange them freely according to design requirements, or refine the layout of each icon in the right-side Properties panel by modifying coordinate values, adjusting the scaling ratio, and other parameters.
तुम्ही उजव्या बाजूच्या प्रॉपर्टीज पॅनलमध्ये (IMAGE->Transform) प्रत्येक आयकॉनसाठी विशिष्ट निर्देशांक तपशीलवार सेट करू शकता.
- Add Text Labels and Value Display
• 1. Add text labels:
Find the Text Label tool in the interface elements toolbar and add text labels for temperature, reminder information, and humidity in sequence.
• 2. Set label properties:
Click each text label and make detailed settings in the right-side Properties panel, including the label name, size, style, etc., to enhance the interface aesthetics and readability.
(The temperature label here is TempLable.)
(The reminder information label here is AlarmLable.)
(The humidity label here is HumiLable.)
This allows you to easily call them in the code (TempLable, AlarmLable, HumiLable).
Next, create the button model:
Create a button: Select the BUTTON label from the left sidebar and drag it to the lower-right corner of the interface. In the right-side Properties panel, modify the button’s background color to green, the text content to “LED,” and the text color to black to intuitively display the button function.
बटण आणि लेबल मर्ज करा: डाव्या कॉलममधील "Hierarchy" वर क्लिक करा, LED टेक्स्ट लेबलला संपूर्ण मध्ये मर्ज करण्यासाठी बटण रो वर ड्रॅग करा. नंतर, प्रॉपर्टीज पॅनलमध्ये, बटण लेबलमधील टेक्स्ट मध्यभागी ठेवण्यासाठी LED टेक्स्ट लेबलची स्थिती X:0, Y:0 वर सेट करा.
- Add EVENTS Function to the Button to Turn the Green Light On and Off
• 1. Select the button and add an event: Select the “LED” button in the lower-right corner, click “EVENTS->ADD EVENT” in the right-side Properties panel, and create a new interactive event.
Configure event parameters:
- 2. Name: Enter “LEDEvent” to name the event.
- 3. Select ‘RELEASED’ as the trigger condition, which triggers the event when the button is released.
- 4. Select ‘CALL FUNCTION’ as the action to execute the corresponding operation through a callback function.
- 5. After selection, click “ADD.”

- Add a custom function name to the CALL function, and later write the specific logic of this function in the Arduino code to achieve on/off control of the green light.
सेटअप पूर्ण झाल्यानंतर, बटण इव्हेंट सामान्यपणे ट्रिगर झाला आहे की नाही हे तपासण्यासाठी प्रथम एक साधे सिम्युलेशन रन करा.
डिझाइन पूर्ण झाल्यानंतर, आम्ही प्रकल्प निर्यात करण्यास तयार आहोत.
तुमचा स्वतःचा प्रकल्प निर्यात मार्ग कॉन्फिगर करण्यासाठी या क्रमाचे अनुसरण करा.
सेटअप पूर्ण झाल्यानंतर, तुम्ही डिझाइन केलेल्या प्रोजेक्टचा संबंधित UI कोड एक्सपोर्ट करू शकता.
UI कोड निर्यात करा
तुम्ही आत्ताच डिझाइन केलेला UI कोड खालीलप्रमाणे आहे.
हा निर्यात मार्ग मागील निर्यात मार्गासारखाच आहे. आकृतीमधील क्रमांक २ शी संबंधित, तुम्हाला UI सापडेल file तू इथे बनवलेस.
Copy these codes and place them together with your into main code.
In this way, the overall design of the UI interface you need to display is completed.
Next, you only need to call it in the code!
सध्याच्या काळातtagप्रकल्प विकासाच्या पहिल्या टप्प्यात, UI इंटरफेसचे कोड डिझाइन काम पूर्ण झाले आहे आणि पुढील महत्त्वाचे काम म्हणजे Arduino मुख्य कोड लिहिणे. file to achieve the expected functions. Specifically, the main code needs to implement the collection and processing of emperature-humidity sensor data and send these data to the UI interface through an appropriate communication method to accurately display the temperature and humidity values on the interface.
प्रमुख स्पष्टीकरणे
- LVGL Display Engine Integration
uint32_t draw_buf[DRAW_BUF_SIZE / 4];
lv_display_set_buffers(disp, draw_buf, NULL, sizeof(draw_buf),
LV_DISPLAY_RENDER_MODE_PARTIAL);
void my_disp_flush(…) {
gfx.pushPixels((lgfx::rgb565_t *)px_map, w * h);
}
uint32_t draw_buf[DRAW_BUF_SIZE / 4]; // 320×240/10 * 2bytes = 15KB: Defines a display buffer draw_buf of type uint32_t with a size of DRAW_BUF_SIZE / 4.Since each uint32_t occupies 4 bytes, this allocation results in DRAW_BUF_SIZE bytes of memory.
lv_display_set_buffers(disp,draw_buf,NULL,sizeof(draw_buf), LV_DISPLAY_RENDER_MODE_PARTIAL);: Core LVGL function for setting the display buffer.
• disp: Display device object (created using lv_display_create())
• draw_buf: Address of the drawing buffer (used by the CPU to write pixel data)
• NULL: Indicates single buffering (no double buffer is used)
• sizeof(draw_buf): Size of the buffer in bytes
• LV_DISPLAY_RENDER_MODE_PARTIAL: 分Partial rendering mode — only updates void my_disp_flush(…) : This function is called by LVGL when a portion of the screen needs to be refreshed. The function name is user-defined and must be registered via lv_display_set_flush_cb().
gfx.pushPixels((lgfx::rgb565_t *)px_map, w * h); पिक्सेल डेटाचा एक ब्लॉक डिस्प्लेवर ढकलतो.
• gfx is the display object from LovyanGFX.
• pushPixels(…) is a high-speed pixel transfer function from LovyanGFX, optimized using low-level SPI acceleration.
• (lgfx::rgb565_t *)px_map:Casts the pixel data pointer px_map from LVGL to rgb565_t* (compatible with the screen’s RGB565 format)
• w * h:Total number of pixels in the region to be refreshed - Sensor Data Handling
int status = DHT.read();
if (status == DHT20_OK) {
float humidity = DHT.getHumidity();
float temperature = DHT.getTemperature();
snprintf(tempStr, sizeof(tempStr), “%.1f C”, temperature);
}
int status = DHT.read();Calls DHT.read() to initiate a measurement request from the DHT20 sensor.The function returns an integer status code (eg: DHT20_OK) indicating whether the read was successful.
if (status == DHT20_OK) : Checks whether the sensor read was successful.Data is processed only if the status equals DHT20_OK (typically defined as macro value 0).
float humidity = DHT.getHumidity(); Retrieves humidity data from the sensor, in %RH (relative humidity), typically with a resolution of 0.1%.
float temperature = DHT.getTemperature(); Gets the current ambient temperature in degrees Celsius (°C),with a typical precision of 0.1°C.
snprintf(tempStr, sizeof(tempStr), “%.1f C”, temperature);
• Uses snprintf() to format the floating-point temperature into a string, eg: “24.5 C”
• tempStr: Destination string buffer (predefined as char tempStr[…])
• sizeof(tempStr): imits the maximum write length to prevent buffer overflow
• “%.1f C”:Format specifier
• %.1f formats the float to one decimal place
• C is the unit suffix (Celsius) - Alarm Control Logic
if (temperature > 30) {
डिजिटलराइट(18, उच्च);
lv_label_set_text(ui_AlarmLabel, “It’s hot”);
} else if (temperature > 25) {
डिजिटलराइट(20, उच्च);
}
if (humidity < 40.0) {
tone(10, 1300);
} इतर {
noTone(10);
}
When the temperature exceeds 30°C, turn on the red LED (GPIO18) and display the warning message
“It’s hot” on the interface. If the temperature is between 25°C and 30°C, turn on the yellow LED (GPIO20) to indicate a mildly warm condition.
When humidity drops below 40%, drive the buzzer by outputting a 1.3 kHz PWM square wave on GPIO10 to sound the alarm. Otherwise, call no Tone (10) to stop the buzzer and mute the alarm. - सहाय्यक कार्य
unsigned long currentMillis = millis();
if (currentMillis – lastUpdate >= interval) {
lastUpdate = currentMillis;
}
lv_timer_handler();
millis() millis() obtains the number of milliseconds elapsed since the system started (non-blocking and continuously increasing).
Check whether currentMillis – lastUpdate has reached the predefined interval.
When the condition is met, execute the critical task and update lastUpdate to record the current time. DHT.begin() initializes the sensor and prepares it for data reading. - Core Functions for Touch Functionality
• 1. Touch Configuration (Touch Settings in LGFX Class)
auto touch_cfg = _touch.config();
touch_cfg.x_min = 0;
touch_cfg.x_max = 239;
touch_cfg.y_min = 0;
touch_cfg.y_max = 319;
touch_cfg.pin_int = 25;
touch_cfg.pin_rst = 24;
touch_cfg.i2c_port = 0;
touch_cfg.i2c_addr = 0x38;
touch_cfg.pin_sda = 4;
touch_cfg.pin_scl = 5;
touch_cfg.freq = 400000;
_touch.config(touch_cfg);
_panel.setTouch(&_touch);
The code configures parameters for the FT5x06 touch controller:
Defines the X/Y coordinate range of the touchscreen.
Sets the interrupt pin and reset pin.
Configures I2C communication parameters (port, address, SDA/SCL pins, frequency).
Finally, associates the touch controller with the display panel.
• 2. Touch Read Callback Function (my_touchpad_read)
void my_touchpad_read(lv_indev_t *indev, lv_indev_data_t *data)
{
uint16_t touchX, touchY;
bool touched = gfx.getTouch(&touchX, &touchY);
if (touched) {
data->state = LV_INDEV_STATE_PRESSED;
data->point.x = touchX;
data->point.y = touchY;
} इतर {
data->state = LV_INDEV_STATE_RELEASED;
}
}
This function serves as the LVGL input device read callback.
1. Obtain the current touch status and coordinates via gfx.getTouch().
2. If a touch is detected (touched is true):
• Set the state to PRESSED.
• Store the touch coordinates into data->point.
3. If no touch is detected:
• Set the state to RELEASED.
• 3. Touch Device Initialization (in setup() function)
lv_indev_t *indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, my_touchpad_read);
lv_indev_t *indev = lv_indev_create();Creates a new input device instance. lv_indev_create() is an LVGL API that allocates and initializes a new input device structure.It returns a pointer to an lv_indev_t object representing this input device, which will be used for subsequent touch input handling.
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER); Sets the input device type to LV_INDEV_TYPE_POINTER, indicating a pointer-type device such as a touchscreen.
lv_indev_set_read_cb(indev, my_touchpad_read); Assigns the input device’s read callback function, used to fetch touch coordinates and status.
• 4. Controlling the Green LED On/Off
Add the following code to event.c to implement button-controlled green LED toggling:
void LED_Control(lv_event_t * e)
{
static bool ledState = false;
ledState = !ledState;
digitalWrite(19, ledState ? HIGH : LOW);
Function Definition and Trigger Logic: LED_Control(lv_event_t * e) is an event callback function of LVGL (embedded GUI library). When the associated “LED button” on the display is clicked, LVGL will automatically call this function to execute the logic.
State Switching: static bool ledState = false; : A static boolean variable ledState is defined to record the current state of the green light.
ledState = !ledState; : Each time the button is clicked, ledState is flipped (switching between on → off / off → on).
Controlling Hardware Pins: digitalWrite(19, ledState ? HIGH : LOW); : According to the value of ledState, control Arduino pin 19 to output a high level (HIGH, turning on the green light) or a low level (LOW, turning off the green light), implementing the function of “clicking the button to switch the state of the green light”.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After learning the above code, a touchscreen-based temperature and humidity monitoring alarm system is implemented. The system uses a DHT20 sensor to collect temperature and humidity data, and displays it in real time through an LVGL graphical interface. When the temperature is too high, red or yellow LEDs are lit for prompt; when the humidity is too low, a buzzer is activated for alarm, achieving a complete function of sensor data collection, screen display, and hardware linkage.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use an additional library (DHT20, LovyanGFX-develop, lvgl and lv_conf.h),so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries डायरेक्टरीमध्ये जा आणि DHT20, LovyanGFX-develop, lvgl आणि lv_conf.h फोल्डर डाउनलोड करा.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा १४ – सर्वो अँगल कंट्रोल
परिचय
या विभागात, आपण इन्फ्रारेड रिमोट वापरून सर्वो मोटरचा रोटेशन अँगल कसा नियंत्रित करायचा आणि TFT स्क्रीनवर अँगल कसा प्रदर्शित करायचा ते शिकू. इन्फ्रारेड रिमोटवरील वेगवेगळे बटणे यासाठी वापरली जाऊ शकतात: अँगल व्हॅल्यूज इनपुट करणे, अँगल सेटिंगची पुष्टी करणे, सर्वो मोटर सुरू/थांबवणे आणि TFT स्क्रीनवर रिअल-टाइममध्ये करंट अँगल प्रदर्शित करणे.
या धड्यात वापरलेले हार्डवेअर:
सर्वो मोटरचे कार्य तत्व
सर्वो मोटर क्लोज्ड-लूप कंट्रोलद्वारे अचूक अँगुलर पोझिशनिंग प्राप्त करते. कंट्रोल सर्किट लक्ष्य स्थिती निश्चित करण्यासाठी PWM सिग्नलचा अर्थ लावते. मोटर गीअर्स चालवते तर पोटेंशियोमीटर तुलनाकर्त्याला रिअल-टाइम पोझिशनल फीडबॅक प्रदान करते. त्रुटी दूर होईपर्यंत कोणतेही विचलन सुधारात्मक रोटेशन सुरू करते. मानक सर्वो उच्च टॉर्क आणि जलद प्रतिसादासह 0°~180° रोटेशन देतात.
इन्फ्रारेड रिमोट कंट्रोल ऑपरेशनचे तत्व
इन्फ्रारेड रिमोट कंट्रोल बटणांद्वारे नियंत्रण आदेश इनपुट करून कार्य करते. मायक्रोकंट्रोलर या आदेशांना इन्फ्रारेड सिग्नलमध्ये एन्कोड आणि मॉड्युलेट करतो, जे नंतर इन्फ्रारेड एमिटरद्वारे प्रसारित केले जातात. रिसीव्हिंग एंडचा इन्फ्रारेड सेन्सर सिग्नल कॅप्चर करतो, त्यांना पुन्हा कमांडमध्ये डीमॉड्युलेट करतो आणि संबंधित ऑपरेशन्स करण्यासाठी डिव्हाइसला चालवतो.
डिस्प्ले स्क्रीनचे कार्य तत्व
डिस्प्ले ड्रायव्हर सर्किट्सद्वारे प्रत्येक पिक्सेलची चमक/रंग नियंत्रित करतो. मुख्य आयसी इमेज डेटाला इलेक्ट्रिकल सिग्नलमध्ये रूपांतरित करतो, जो लाईन-बाय-लाइन रिफ्रेशिंगसाठी रो/कॉलम ड्रायव्हर आयसीमध्ये प्रसारित केला जातो. एलसीडी व्हॉल्यूमसह लिक्विड क्रिस्टल अलाइनमेंट समायोजित करतात.tage प्रकाशाचे मॉड्युलेट करण्यासाठी, तर OLEDs थेट प्रकाश उत्सर्जित करतात. वेळेचे नियंत्रण करणारे उपकरण सिग्नल सिंक्रोनाइझेशन सुनिश्चित करते जेणेकरून कृत्रिमता रोखता येईल.
ऑपरेशन इफेक्ट डायग्राम
- Enable IR Remote Control:
Press the button labeled “CH+” on the device. This operation will activate the infrared remote control function, preparing it for subsequent command reception.
- Angle Setting and Motor Control (Numeric Keys: 0-9)
• Set 180 degrees: Press the numeric keys and sequentially enter “1”, “8”, “0” on the input interface. The display will real-time show “Input:180”. After confirming the input is correct, press the “Confirm” button
on the remote control. The system will drive the servo motor to rotate to the target angle of 180 degrees based on this command. Meanwhile, the TFT screen will simultaneously update to display “Rotated to :180”, providing an intuitive feedback on the current angle of the motor.
• Set 90 degrees: Repeat the above operation process. Press the numeric keys to enter “9” and “0”. The display will show “Input:90”. Press the “Confirm” button. The servo motor will then rotate to the 90-degree position, and the TFT screen will display “Rotated to :90”.
• Set 0 degrees: Press the numeric key to enter “0”. The display will show “Input:0”.
Press the “Confirm” button. The servo motor will precisely rotate to 0 degrees, and the TFT screen will show “Rotated to :0”.
- Disable IR Remote Control:
जेव्हा तुम्हाला सर्वो मोटर चालवण्यासाठी IR रिमोट कंट्रोल वापरणे थांबवायचे असेल, तेव्हा डिव्हाइसवरील "CH-" बटण दाबा. ही क्रिया IR रिमोट कंट्रोल फंक्शन अक्षम करेल. त्यानंतर, कोणतीही संख्यात्मक की दाबली तरी, सिस्टम प्रतिसाद देणार नाही आणि सर्वो मोटर सुरू होणार नाही, ज्यामुळे अनपेक्षित ऑपरेशन्समध्ये डिव्हाइस सुरक्षितपणे स्थिर राहील याची खात्री होते.
प्रमुख स्पष्टीकरणे
- IR Signal Reception & Denounce Mechanism
if (IrReceiver.decode()) {
unsigned long code = IrReceiver.decodedIRData.command;
static uint32_t lastKeyCode = 0;
static unsigned long lastKeyTime = 0;
const unsigned long debounceDelay = 300;
if (code == lastKeyCode && (millis() – lastKeyTime) < debounceDelay) {
IrReceiver.resume();
परत
}
lastKeyCode = code;
last KeyTime = millis();
Ir Receiver. decode() checks if an IR signal from the remote control is received.
Ir Receiver. decoded IR Data. command extracts the key code of the pressed button, which is used later to determine which button was pressed.
Debounce Mechanism: When a button is held down or the remote is jiggled, the same key code is repeatedly sent. This code uses two static variables to ensure that the same key press is processed only once within 300ms, preventing multiple responses.
This is a standard practice in remote control input programming, resulting in a smoother user experience. - IR Button Function Mapping
switch (code) {
केस ०x०००१:
servoEnabled = false;
Serial.println(“Servo disabled”);
खंडित;
केस ०x०००१:
servoEnabled = true;
Serial.println(“Servo enabled”);
खंडित;
केस ०x०००१:
angleInput = constrain(angleInput, 0, 180);
if (servoEnabled) {
myservo.write(angleInput);
showRotatedAngle(angleInput);
} इतर {
Serial.println(“Servo is disabled. Cannot rotate.”);
}
angleInput = 0;
विलंब(1000);
खंडित;
case 0x16: angleInput = angleInput * 10 + 0; break;
case 0x0C: angleInput = angleInput * 10 + 1; break;
case 0x18: angleInput = angleInput * 10 + 2; break;
case 0x5E: angleInput = angleInput * 10 + 3; break;
case 0x08: angleInput = angleInput * 10 + 4; break;
case 0x1C: angleInput = angleInput * 10 + 5; break;
case 0x5A: angleInput = angleInput * 10 + 6; break;
case 0x42: angleInput = angleInput * 10 + 7; break;
case 0x52: angleInput = angleInput * 10 + 8; break;
case 0x4A: angleInput = angleInput * 10 + 9; break;
डीफॉल्ट:
Serial.print(“Unknown code: “);
Serial.println(code, HEX);
खंडित;
}
[CH-] Button: Set the control variable servo Enabled to false, preventing the servo from acting when the confirmation button is pressed later.
[CH+] Button: Resume servo control by setting servo Enabled to true.
[प्ले/पॉज] बटण:
• Use constrain( angle Input, 0, 180) to ensure the angle is within the servo’s safe range.
• If the servo is enabled, execute my servo. write(angle Input) to rotate the servo to that angle, and use show Rotated Angle (angle Input) to display “Rotated to xxx°” on the screen.
• If disabled, the serial port will prompt “Servo not enabled”.
• Clear the input angle and delay for 1000ms to allow the user 1 second to observe the result. Numeric Keys 0-9:
• Use the “cumulative input method” for angle entry. For example, “1” नंतर “2” दाबल्याने कोन इनपुट = 1*10 + 2 = 12 मिळतो.
• Support continuous multi-digit input (up to three digits) for convenient entry of large angles like 100 or 120.
डीफॉल्ट: त्यानंतरच्या डीबगिंगसाठी अपरिचित कोड प्रिंट केले जातात. - Alarm Control Logic
if (angleInput > 999) angleInput = 0;
showAngleInput();
IrReceiver.resume(); - सहाय्यक कार्य
myservo. attach(13, 450, 2520); my servo. write (angle Input);
Limit input to a maximum of three digits (prevents overflow from miso perations).
For each new input, call show Angle Input() to display the current input angle on the screen in real time, keeping the user informed.
IR रिसेप्शन पुन्हा सुरू करा आणि पुढील बटण दाबण्याची वाट पहा.
Servo. attach(pin, min, max) binds the servo to a pin and specifies the minimum/maximum pulse width, ensuring compatibility with different servo brands.
myservo.write(angle) थेट कोन इनपुट करते आणि लायब्ररी सर्वो चालविण्यासाठी कोनला पल्स रुंदी आउटपुटमध्ये स्वयंचलितपणे रूपांतरित करते. - स्क्रीन डिस्प्ले फंक्शन्स
void showAngleInput() {
gfx.fillScreen(TFT_BLACK);
gfx.setTextSize(3);
gfx.setCursor(30, 100);
gfx.setTextColor(TFT_WHITE);
gfx.printf(“Input: %d”, angleInput);
}
void showRotatedAngle(int angle) {
gfx.fillScreen(TFT_BLACK);
gfx.setCursor(30, 100);
gfx.setTextSize(3);
gfx.setTextColor(TFT_GREEN);
gfx.printf(“Rotated to: %d”, angle);
}
During input, show Angle Input() displays “Input: [current input angle]” to inform the user of the entered value.
After confirmation, show Rotated Angle() displays “Rotated to: [angle]” to confirm the servo has executed the command.
कंटेंट ओव्हरले टाळण्यासाठी प्रत्येक वेळी स्क्रीन साफ करा.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the above code, you have implemented a servo angle adjustment system controlled by an infrared remote control. Combined with a TFT display and touch configuration, the system can achieve the following functions:
Input an angle value via the infrared remote control to rotate the servo to the specified angle, while the TFT screen simultaneously displays the input angle and execution results in real time.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use three additional library (IRremote, LovyanGFX-develop, Servo), so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries डायरेक्टरीमध्ये जा आणि IRremote, LovyanGFX-develop आणि Servo फोल्डर डाउनलोड करा.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा १५ – सभ्य स्वयंचलित दरवाजा
परिचय
या विभागात, रिले नियंत्रित करण्यासाठी टच मॉड्यूलचा वापर केला जातो, जो सर्वो मोटरच्या प्रगत ऑपरेशन्सना सक्षम करतो जेणेकरून स्वयंचलित दरवाजा उघडणे आणि बंद करणे शक्य होते. टच बटण सक्रिय झाल्यावर, रिले दरवाजा उघडण्यासाठी चालू होतो, नंतर तो बंद करण्यासाठी 10 सेकंदांनंतर स्वयंचलितपणे बंद होतो. प्रक्रियेदरम्यान TFT स्क्रीन रिअल-टाइम स्थिती अद्यतने प्रदान करते.
या धड्यात वापरलेले हार्डवेअर:
रिले ऑपरेशनचे कार्य तत्व
रिले हे एक स्विच उपकरण आहे जे नियंत्रण मिळविण्यासाठी इलेक्ट्रोमॅग्नेटिक किंवा यांत्रिक तत्त्वांचा वापर करते. जेव्हा कॉइलला ऊर्जा दिली जाते, तेव्हा ते एक चुंबकीय क्षेत्र निर्माण करते जे आर्मेचरला आकर्षित करते, ज्यामुळे सामान्यतः बंद संपर्क उघडतात आणि सामान्यतः उघडलेले संपर्क बंद होतात. जेव्हा ऊर्जा काढून टाकली जाते, तेव्हा चुंबकीय क्षेत्र अदृश्य होते आणि संपर्क त्यांच्या मूळ स्थितीत परत येतात. ते कमी-धारा/व्हॉल्यूम सक्षम करतेtagउच्च-प्रवाह/व्हॉल्यूमचे e नियंत्रणtagई सर्किट्स, सर्किट नियंत्रण आणि सिग्नल रूपांतरणासाठी मोठ्या प्रमाणावर वापरले जातात, अलगाव प्रदान करतात आणि ampबंधन
टच सेन्सरचे कार्य तत्व
A touch sensor detects touches by monitoring capacitance or resistance changes.
Capacitive types measure field variation when body capacitance alters electrode charge; resistive types register pressure-induced contact between conductive layers. Signal processing converts subtle changes to digital outputs with noise immunity. Supports multi-touch and gesture recognition, widely used in smart devices.
डिस्प्ले स्क्रीनचे कार्य तत्व
डिस्प्ले ड्रायव्हर सर्किट्सद्वारे प्रत्येक पिक्सेलची चमक/रंग नियंत्रित करतो. मुख्य आयसी इमेज डेटाला इलेक्ट्रिकल सिग्नलमध्ये रूपांतरित करतो, जो लाईन-बाय-लाइन रिफ्रेशिंगसाठी रो/कॉलम ड्रायव्हर आयसीमध्ये प्रसारित केला जातो. एलसीडी व्हॉल्यूमसह लिक्विड क्रिस्टल अलाइनमेंट समायोजित करतात.tage प्रकाशाचे मॉड्युलेट करण्यासाठी, तर OLEDs थेट प्रकाश उत्सर्जित करतात. वेळेचे नियंत्रण करणारे उपकरण सिग्नल सिंक्रोनाइझेशन सुनिश्चित करते जेणेकरून कृत्रिमता रोखता येईल.
ऑपरेशन इफेक्ट डायग्राम
- System Startup and Initialization Once the power is turned on, the program starts automatically:
• The TFT screen lights up and displays the initial message: “Please open the door.”
• The relay remains off by default (no power), waiting for a touch input.
- Touch-Triggered Door Opening
जेव्हा वापरकर्ता बोटाने सेन्सरला स्पर्श करतो तेव्हा सिस्टम इनपुट शोधते:
• The relay is energized, simulating the door opening; the relay’s indicator light turns on.
• The TFT screen clears and displays “Welcome” to indicate the door is now open.
- Auto-Closing After Delay
The door remains open for 10 seconds:
• After the countdown finishes, the relay is turned off, simulating the door closing; the indicator light turns off.
• The TFT screen returns to the “Please open the door” message, and the system goes back to standby mode, ready for the next touch activation.
प्रमुख स्पष्टीकरणे
- Display Initialization and Welcome Message
gfx.init();
gfx.fillScreen(TFT_BLACK);
gfx.setTextColor(TFT_WHITE);
gfx.setTextSize(2);
gfx.setCursor(20, 100);
gfx.print(“Please open the door”);
Initialize the display module.
Set text color, size, and position.
Show the startup message: “Please open the door.” - Touch Button Detection and Door Lock Control Logic
if (digitalRead(touchPin)) {
digitalWrite(relayPin, HIGH);
gfx.fillScreen(TFT_BLACK);
gfx.setCursor(60, 100);
gfx.print(“Welcome”);
विलंब(10000);
digitalWrite(relayPin, LOW);
…
}
सेन्सरमधून टच इनपुटसाठी मॉनिटर करा.
जेव्हा स्पर्श आढळतो: रिले सक्रिय करा (दरवाजा उघडण्याचे अनुकरण करण्यासाठी) आणि स्वागत संदेश प्रदर्शित करा.
१० सेकंदांनंतर, रिले बंद करा आणि सुरुवातीच्या “कृपया दरवाजा उघडा” प्रॉम्प्टवर परत या. - पिन व्याख्या
const int relayPin = 12;
const int touchPin = 14;
const int backlightPin = 0;
रिलेपिन: रिलेद्वारे दरवाजाचे कुलूप नियंत्रित करते.
टचपिन: बाह्य कॅपेसिटिव्ह टच सेन्सरकडून इनपुट प्राप्त करते.
बॅकलाइटपिन: डिस्प्लेचा बॅकलाइट नियंत्रित करते.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the code above, you will have built a smart automatic door control system.
The system uses an SPI bus to drive the ST7789 display and an I2C interface to connect the FT5x06 touch module. While in standby mode, the screen displays the message “Please open the door.” When the touch sensor is activated, the relay powers on to simulate the door opening, and the display switches to a “Welcome” screen. After 10 seconds, the relay automatically powers off to simulate door closing, and the screen returns to the original prompt. The entire operation is managed through a state machine, enabling intelligent door control and smooth user interaction.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use an additional library (LovyanGFX-develop), so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries डायरेक्टरीमध्ये जा आणि LovyanGFX-develop फोल्डर डाउनलोड करा.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा १६ - ध्वनी स्मरणपत्र
परिचय
In this section, a sound sensor is used to monitor ambient noise levels. When the noise exceeds a preset threshold, a buzzer is triggered to emit a 1-second alert tone, creating a “noise detection–buzzer alert” linkage. The system continuously monitors sound intensity; if the noise persists, the buzzer repeats the alert. Once the noise stops, the reminders automatically cease.
या धड्यात वापरलेले हार्डवेअर:
ध्वनी सेन्सरचे कार्य तत्व
A sound sensor transduces acoustic vibrations into electrical signals via transducer elements. Electret microphones generate signals through capacitance variation between diaphragm and backplate, while piezoelectric types rely on deformation potentials.
Signals are pre-ampADC द्वारे लिफाइड, फिल्टर आणि डिजिटायझेशन. संवेदनशीलता आणि वारंवारता प्रतिसाद डायफ्राम मटेरियल आणि स्ट्रक्चरल डिझाइनवर अवलंबून असतात, ज्यामुळे विशिष्ट ध्वनी दाब शोधणे शक्य होते.
बजर ऑपरेशनचे कार्य तत्व
The buzzer generates sound by vibrating a diaphragm driven by an electrical signal.
When an alternating current is applied, the diaphragm vibrates rapidly due to magnetic or piezoelectric effects, producing sound. The pitch and frequency are determined by the current frequency, and it is commonly used for alerts or alarms.
ऑपरेशन इफेक्ट डायग्राम
Once the program starts, the system continuously monitors ambient sound in real time:
- Sound Trigger:
जेव्हा आजूबाजूचा आवाज निर्धारित मर्यादेपेक्षा जास्त असतो, तेव्हा बझर ३ सेकंदांपर्यंत चालणारा "बीप" आवाज उत्सर्जित करतो.
- Continuous Alerts:
जर आवाजाची पातळी जास्त राहिली तर बजर नियमित अंतराने वारंवार वाजेल. - Auto-Silence:
जेव्हा वातावरण पुन्हा शांत होते, तेव्हा बझर आपोआप थांबतो.
प्रमुख स्पष्टीकरणे
- Pin Definitions for Sound Sensor and Buzzer
#define SOUND_PIN 29
int buzzerPin = 10;
SOUND_PIN ची व्याख्या पिन २९ म्हणून केली जाते, जी ध्वनी सेन्सरला जोडते.
बझरपिन हा एक व्हेरिएबल आहे जो पिन १० शी जोडलेल्या बझरचे प्रतिनिधित्व करतो.
त्यानंतरचा कोड इनपुट वाचण्यासाठी आणि आउटपुट नियंत्रित करण्यासाठी या दोन पिनचा वापर करेल. - Reading Analog Values from the Sound Sensor
इंट साउंड व्हॅल्यू = अॅनालॉग रीड(साउंड_पिन);
analogRead(…) हे फंक्शन अॅनालॉग सिग्नल वाचण्यासाठी वापरले जाते, जे व्हॉल्यूमशी संबंधित आहेtage output by the sound sensor (range: 0–1023).
The louder the sound, the higher the voltage, and thus the larger the soundValue.
This value determines whether the buzzer alarm is triggered. - Determining if the Sound Exceeds the Set Threshold
जर (ध्वनी मूल्य >= ३००)
ही महत्त्वाची अट आहे: जर ध्वनी सेन्सरमधील अॅनालॉग मूल्य 300 पेक्षा जास्त किंवा समान असेल, तर ते वातावरणात लक्षणीय आवाज (जसे की टाळ्या वाजवणे किंवा ओरडणे) दर्शवते.
मूल्य ३०० हे एक अनुभवजन्य थ्रेशोल्ड आहे आणि प्रत्यक्ष पर्यावरण संवेदनशीलतेनुसार ते समायोजित केले जाऊ शकते. - Controlling the Buzzer On or Off
• 1. When the sound is loud:
tone(buzzerPin, 1300);
विलंब(1000);
टोन (बजरपिन, १३००); बजर पिनवर १३०० हर्ट्झ टोन वाजवतो.
विलंब (१०००); अलर्ट वाढविण्यासाठी बजर १ सेकंदासाठी वाजत ठेवतो
• 2. When the sound is quiet:
noTone(…) बजर थांबवतो, तो शांत ठेवतो.
हे वापरकर्त्यांना त्रास देऊ शकणारे सतत होणारे गोंधळ टाळते.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the code above, you will have developed an intelligent environmental monitoring system based on a sound sensor and buzzer. The system continuously reads the ambient sound intensity in real time and compares it to a preset threshold. When the detected sound exceeds the threshold, the buzzer automatically triggers a continuous alert.
The design supports customizable sound sensitivity, alert duration, and sampलिंग फ्रिक्वेन्सी, आणि प्रोग्राममध्ये व्यत्यय आल्यास बझर बंद करण्यासाठी सुरक्षा वैशिष्ट्य समाविष्ट आहे.
प्रोग्रामिंग स्टेप्स
तुम्ही मार्गदर्शक म्हणून धडा १ (पृष्ठ १०-१५) मधील फ्लॅशिंग स्टेप्सचा संदर्भ घेऊ शकता.
धडा १७ – प्रवेगाची गणना
परिचय
हा विभाग डेव्हलपमेंट बोर्डच्या X, Y आणि Z अक्षांसह प्रवेग डेटा सतत कॅप्चर करण्यासाठी LSM6DS3TRC प्रवेगमापक सेन्सरचा वापर करतो. मोजमाप TFT स्क्रीनवर रिअल टाइममध्ये प्रदर्शित केले जातात. जेव्हा बोर्ड वेगाने हलवला जातो तेव्हा संबंधित अक्षांवरील प्रवेग मूल्ये गतिमानपणे बदलतात, ज्यामुळे गती आणि प्रवेग यांच्यात दृश्य सहसंबंध निर्माण होतो.
या धड्यात वापरलेले हार्डवेअर:
अॅक्सिलरोमीटरचे कार्य तत्व
An accelerometer measures acceleration by detecting inertial force. MEMS types use silicon microstructures where proof mass displacement alters capacitance/piezoresistance, converted to electrical signals. Piezoelectric variants generate charges when stressed.
Integrated signal conditioning enables static (gravity) and dynamic acceleration
डिस्प्ले स्क्रीनचे कार्य तत्व
डिस्प्ले ड्रायव्हर सर्किट्सद्वारे प्रत्येक पिक्सेलची चमक/रंग नियंत्रित करतो. मुख्य आयसी इमेज डेटाला इलेक्ट्रिकल सिग्नलमध्ये रूपांतरित करतो, जो लाईन-बाय-लाइन रिफ्रेशिंगसाठी रो/कॉलम ड्रायव्हर आयसीमध्ये प्रसारित केला जातो. एलसीडी व्हॉल्यूमसह लिक्विड क्रिस्टल अलाइनमेंट समायोजित करतात.tage प्रकाशाचे मॉड्युलेट करण्यासाठी, तर OLEDs थेट प्रकाश उत्सर्जित करतात. वेळेचे नियंत्रण करणारे उपकरण सिग्नल सिंक्रोनाइझेशन सुनिश्चित करते जेणेकरून कृत्रिमता रोखता येईल.
ऑपरेशन इफेक्ट डायग्राम
- System Auto-Initialization The TFT screen displays the title “Accelerometer data” with labels for the X, Y, and Z axes and their initial values shown below.

- Observing Movement Along Axes Shake the board rapidly in any direction: the X, Y, and Z axis values update dynamically in real time, reflecting the direction and magnitude of acceleration in 3D space

प्रमुख स्पष्टीकरणे
- Display Initialization and Configuration
gfx.init();
पिनमोड(१३, आउटपुट);
डिजिटलराइट(0, उच्च);
gfx.fillScreen(BG_COLOR);
gfx.init(): Calls the LovyanGFX library method to initialize the TFT display.
pinMode(0, OUTPUT) and digitalWrite(0, HIGH): Turns on the backlight to ensure the screen is lit.
gfx.fillScreen(BG_COLOR): Fills the screen with the background color (black) to prevent ghosting. - Display Initialization and Configuration
Wire1.setSDA(2);
Wire1.setSCL(3);
Wire1.begin();
Specifies using Wire1 (the second I2C bus) for communication.
Sets SDA to GPIO2 and SCL to GPIO3.
Starts the I2C bus to prepare for communication with the LSM6DS3TR-C sensor.
if (!lsm6ds3trc.begin_I2C(0x6B, &Wire1)) {
gfx.setTextColor(TFT_RED);
gfx.setCursor(20, SCREEN_HEIGHT / 2 – 20);
gfx.print(“Sensor initialization failed!”);
while (1) delay(10);
}
begin_I2C(0x6B, &Wire1): Initializes the LSM6DS3TR-C sensor at address 0x6B.
If initialization fails, an error message is displayed on the screen, and the system enters an infinite loop to prevent ignoring the error. - Data Refresh Control Logic
static unsigned long lastUpdate = 0;
if (millis() – lastUpdate < UPDATE_INTERVAL) return;
lastUpdate = millis();
स्टॅटिक अनसिग्न्ड लाँग लास्टअपडेट = ०; टाइमस्ट साठवण्यासाठी स्टॅटिक व्हेरिएबल लास्टअपडेट परिभाषित करतेamp of the last accelerometer data refresh. Using static ensures that the variable retains its value between function calls instead of being reinitialized every time.
if (millis() – lastUpdate < UPDATE_INTERVAL) return; is the core logic for controlling data refresh frequency. It prevents excessive updates that could cause screen flickering or waste system resources.
• Does the current time minus the last update time fall short of the preset refresh interval (UPDATE_INTERVAL = 150 ms)?
• If yes, the refresh time has not yet arrived, so return exits the loop() early, skipping data acquisition and screen update during this cycle.
millis() is a built-in Arduino function returning the number of milliseconds since the device powered on, useful for timing intervals.
lastUpdate = millis(); updates lastUpdate to the current timestamp एकदा मध्यांतराची आवश्यकता पूर्ण झाली की, पुढील रिफ्रेश सायकलची तयारी करणे. - Retrieving Three-Axis Acceleration Data
sensors_event_t accel;
lsm6ds3trc.getEvent(&accel, nullptr, nullptr);
sensors_event_t is a data structure from the Adafruit Sensor library.
getEvent() fetches the latest acceleration values from the sensor in meters per second squared (m/s²).
Only acceleration data is requested here; the second and third parameters are set to nullptr, indicating that gyroscope and temperature data are not retrieved - Displaying Data on the Screen (Clearing Old Values + Writing New Values)
साठी (int i = 0; i < 3; i++) {
float value = 0;
स्विच (i)
case 0: value = accel.acceleration.x; break;
case 1: value = accel.acceleration.y; break;
case 2: value = accel.acceleration.z; break;
}
gfx.fillRect(
AXIS_AREA[i].x_value,
AXIS_AREA[i].y_value,
AXIS_AREA[i].w,
AXIS_AREA[i].h,
BG_COLOR
);
gfx.setTextColor(TEXT_COLOR);
gfx.setCursor(AXIS_AREA[i].x_value, AXIS_AREA[i].y_value);
gfx.printf(“%.2f m/s^2”, value);
}
gfx.fillRect(…) — clears the screen area first to prevent ghosting.
• Before displaying new values, the previous value area is erased using the background color.
• This avoids leftover digits caused by changes in number length (eg: from 9.88 to 10.12),
gfx.printf(…) — formats and prints the new value.
• Uses gfx.printf(“%.2f m/s^2”, value); to output acceleration values rounded to two decimal places.
• Ensures the display remains neat and the precision is appropriate.。
The loop updates the X, Y, and Z axis data separately:
• Uses predefined position and size info from AXIS_AREA[i] to locate where each axis is shown on the screen.
• Each axis’s data is refreshed individually to maintain an organized display.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the code above, you’ve built a real-time 3-axis acceleration monitoring system using the LSM6DS3TRC sensor. The system reads acceleration data via the I2C interface, processes it, and dynamically displays the X, Y, and Z values (in m/s²) on a 240×320 resolution TFT screen. Data updates every 150 milliseconds, and when the development board moves, the corresponding axis values change in real time, creating a visual link between motion and acceleration.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use four additional library (LovyanGFX-develop, Adafruit_BuslO, Adafruit_LSM6DS and Adafruit_Unified_Sensor), so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries directory and download the Lovyan GFX-develop, Adafruit_BuslO, Adafruit_LSM6DS and Adafruit_Unified_Sensor folder.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा १८ – स्मार्ट कॉरिडॉर लाईट
परिचय
In this chapter, you’ll learn how to integrate a sound sensor, a light sensor, and an LED to build a smart hallway lighting system. By coordinating multiple sensors, the system can automatically control the LED based on ambient light and sound input—mimicking real-world intelligent lighting behavior.
या धड्यात वापरलेले हार्डवेअर:
ध्वनी सेन्सरचे कार्य तत्व
A sound sensor transduces acoustic vibrations into electrical signals via transducer elements. Electret microphones generate signals through capacitance variation between diaphragm and backplate, while piezoelectric types rely on deformation potentials.
Signals are pre-ampADC द्वारे लिफाइड, फिल्टर आणि डिजिटायझेशन. संवेदनशीलता आणि वारंवारता प्रतिसाद डायफ्राम मटेरियल आणि स्ट्रक्चरल डिझाइनवर अवलंबून असतात, ज्यामुळे विशिष्ट ध्वनी दाब शोधणे शक्य होते.
Working Principle of a Light Sensor
A light sensor converts light signals to electrical signals via the photoelectric effect.
Ambient light strikes a photosensitive component (eg: photoresistor, photodiode, or phototransistor), where photons excite charge carriers, altering resistance or generating photocurrent. Signal conditioning (eg: ADC/amplifier) processes the output, and an MCU calculates light intensity खंड पासूनtage/current changes. Different sensors detect visible, IR, or UV wavelengths.
एलईडीचे कार्य तत्व
LED (प्रकाश उत्सर्जक डायोड) च्या केंद्रस्थानी एक अर्धसंवाहक PN जंक्शन असते. जेव्हा फॉरवर्ड बायस व्हॉल्यूमtage is applied, electrons from the N-type region recombine with holes from the P-type region near the junction. During this recombination, electrons drop from a higher energy level to a lower one, releasing the excess energy in the form of photons—producing light. The color (or wavelength) of the emitted light is determined by the energy band gap of the semiconductor material. This process is a direct application of electroluminescence.
ऑपरेशन इफेक्ट डायग्राम
After the system is powered on, the smart corridor light follows this logic:
- Bright Environment:
When there is sufficient natural light, the LED remains off regardless of any sound detected.
- Low-Light Environment:
When the lighting is dim or the light sensor is covered, the LED stays off by default.
Once a sound is detected, the LED turns on and stays lit for 10 seconds before automatically turning off.
If the sound continues, the LED remains on continuously. Once the sound stops, it stays on for another 10 seconds before shutting off automatically. This demonstrates that the system operates as expected in all scenarios.
प्रमुख स्पष्टीकरणे
- I2C Initialization and Light Sensor Setup
Wire1.setSDA(I2C_SDA);
Wire1.setSCL(I2C_SCL);
Wire1.begin();
if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE,
0x5c, &Wire1)) {
Serial.println(F(“BH1750 begin success”));
} इतर {
Serial.println(F(“BH1750 init failed”));
}
This section of code initializes the I2C communication and sets up the BH1750 light sensor:
Wire1.setSDA() and Wire1.setSCL() define the pins used for I2C communication;
Wire1.begin() starts the I2C bus;
lightMeter.begin() initializes the light sensor with the following parameters:
• CONTINUOUS_HIGH_RES_MODE: sets the sensor to continuous high-resolution measurement mode;
• 0x5c: the I2C address of the sensor;
• &Wire1: specifies the I2C interface to use. - Main Control Logic Entry
static bool isSoundDetected = false;
static bool isLedOn = false;
static unsigned long ledOnTimestamp = 0;
The core logic consists of a three-stagई प्रक्रिया:
Light intensity judgment → Sound trigger detection → Timed LED control, This is implemented through state flags (isSoundDetected, isLedOn) and a timestamp (ledOnTimestamp) to manage smart linkage behavior.
The main logic is handled inside the if (light Meter. measurement Ready (true)) function, with the following process:
• 1. Light Sensor Reading
int lux = light Meter. read Light Level();
measurementReady(true) checks if the sensor has new data available
The returned lux value determines the subsequent logic branch (bright/dim light handling).
• 2. Bright Light Handling (lux ≥ 100)
digitalWrite(LedPin, LOW);
isLedOn = false;
isSoundDetected = false;
ledOnTimestamp = 0;
Serial.println(“[ACTION] Light strong – turning OFF LED”);
Immediately turn off the LED (digitalWrite(LedPin, LOW))
Reset all state flags:
• isLedOn = false (LED status)
• isSoundDetected = false (sound detection flag)
• ledOnTimestamp = 0 (timestamp)
• 3. Dim Light Handling (lux < 100)
if (digitalRead(SOUND_PIN)) {
digitalWrite(LedPin, HIGH);
isLedOn = true;
isSoundDetected = true;
ledOnTimestamp = millis();
} इतर {
if (isSoundDetected) {
if (millis() – ledOnTimestamp < 10000) {
digitalWrite(LedPin, HIGH);
isLedOn = true;
} इतर {
digitalWrite(LedPin, LOW);
isLedOn = false;
isSoundDetected = false;
}
} इतर {
digitalWrite(LedPin, LOW);
isLedOn = false;
}
}
When a sound signal is detected (digital Read (SOUND_PIN) returns HIGH):
• Immediately turn on the LED (digital Write (Led Pin, HIGH)):
• Set the relevant state flags: isLedOn = true isSoundDetected = true
• Record the current time (millis()) as the LED activation timestamp
Sustained Sound:
If no new sound is detected but one was detected previously:
• Keep the LED on for up to 10 seconds (Millis() – led On Timestamp < 10000)
• After 10 seconds, turn off the LED and reset flags
If no sound is detected:
• Turn off the LED directly (digital Write (Led Pin, LOW))
• Update the is Led On flag to false - Pin Mode Configuration
pinMode(LedPin, OUTPUT);
pinMode(SOUND_PIN, INPUT);
LedPin is a defined constant (value 18), representing the physical pin number connected to the LED
OUTPUT is a predefined constant that sets the pin to output mode.
उद्देश:
• Configures the pin as a digital output, capable of outputting HIGH (3.3V/5V) or LOW (0V)
• In this mode, the pin can drive an LED, relay, or other load
SOUND_PIN is a defined constant (value 29), representing the physical pin number connected to the sound sensor
INPUT is a predefined constant that sets the pin to input mode.
उद्देश:
• Configures the pin as a digital input, capable of reading HIGH/LOW levels from external signals
• In this mode, the pin can detect switch states or digital sensor outputs
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the above code, you have implemented an intelligent corridor lighting control system based on a light sensor and a sound sensor. The system controls the LED light through the interaction of ambient light intensity and sound signals:
- When the light intensity exceeds 100 lux, the LED remains off;
- In dim lighting, if a sound is detected, the LED turns on and stays lit for 10 seconds;
- If continuous sound is detected during this period, the timer resets;
- Once the sound stops and the countdown ends, the LED automatically turns off.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use an additional library (BH1750), so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries डायरेक्टरीमध्ये जा आणि BH1750 फोल्डर डाउनलोड करा.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code (You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board.Make sure the compilation completes without errors before running the program.
धडा १९ – साधे कॅल्क्युलेटर
परिचय
In this chapter, a basic calculator function will be implemented using an IR remote control. Users can input numbers and operators via the remote, and the expressions will be displayed and evaluated on a TFT screen.The main objective is to master input handling from the IR remote, number parsing, and the programming of simple arithmetic logic.
या धड्यात वापरलेले हार्डवेअर:
इन्फ्रारेड रिमोट सेन्सर ऑपरेशनचे तत्व
इन्फ्रारेड रिमोट सेन्सर नियंत्रण कार्ये साध्य करण्यासाठी इन्फ्रारेड सिग्नल प्राप्त करून कार्य करतो. ट्रान्समीटर नियंत्रण सूचनांना विशिष्ट वारंवारतेच्या इन्फ्रारेड प्रकाश सिग्नलमध्ये रूपांतरित करतो. सेन्सर हे सिग्नल प्राप्त करतो, त्यांना पुन्हा नियंत्रण सूचनांमध्ये रूपांतरित करतो आणि नंतर मायक्रोकंट्रोलर संबंधित ऑपरेशन्स करतो.
इन्फ्रारेड रिमोट कंट्रोल ऑपरेशनचे तत्व
इन्फ्रारेड रिमोट कंट्रोल बटणांद्वारे नियंत्रण आदेश इनपुट करून कार्य करते. मायक्रोकंट्रोलर या आदेशांना इन्फ्रारेड सिग्नलमध्ये एन्कोड आणि मॉड्युलेट करतो, जे नंतर इन्फ्रारेड एमिटरद्वारे प्रसारित केले जातात. रिसीव्हिंग एंडचा इन्फ्रारेड सेन्सर सिग्नल कॅप्चर करतो, त्यांना पुन्हा कमांडमध्ये डीमॉड्युलेट करतो आणि संबंधित ऑपरेशन्स करण्यासाठी डिव्हाइसला चालवतो.
डिस्प्ले स्क्रीनचे कार्य तत्व
डिस्प्ले ड्रायव्हर सर्किट्सद्वारे प्रत्येक पिक्सेलची चमक/रंग नियंत्रित करतो. मुख्य आयसी इमेज डेटाला इलेक्ट्रिकल सिग्नलमध्ये रूपांतरित करतो, जो लाईन-बाय-लाइन रिफ्रेशिंगसाठी रो/कॉलम ड्रायव्हर आयसीमध्ये प्रसारित केला जातो. एलसीडी व्हॉल्यूमसह लिक्विड क्रिस्टल अलाइनमेंट समायोजित करतात.tage प्रकाशाचे मॉड्युलेट करण्यासाठी, तर OLEDs थेट प्रकाश उत्सर्जित करतात. वेळेचे नियंत्रण करणारे उपकरण सिग्नल सिंक्रोनाइझेशन सुनिश्चित करते जेणेकरून कृत्रिमता रोखता येईल.
ऑपरेशन इफेक्ट डायग्राम
Operator and Control Key Functions

| की प्रकार | की लेबल | कार्य वर्णन |
| अंकीय की | 0-9 | Inputs numeric values; LCD displays “Input: [value]”. |
| Operator Keys | Performs addition; LCD shows current input (eg: “Input: 3+”). | |
| Performs subtraction; LCD shows current input (eg: “Input: 3—”). | ||
| Performs multiplication (equivalent to “x”); LCD shows current input (eg: “Input: 3*”). | ||
| Performs division (equivalent to “/”); LCD shows current input (eg: “Input: 3/”). | ||
| विशेष कळा | Used to input negative numbers; press this key before the number (eg: “-5”). | |
| Acts as a decimal point; used to enter decimals (eg: press “3 — 100+ —> 5” for “3.5”). | ||
| Confirms calculation and outputs result, rounded to two decimal places (eg: “Result: 8.00”). | ||
| Clears current input and result; returns to initial state (LCD shows “Input:”). |
- Basic Calculation Process
Press numeric keys to enter values.The LCD displays: “Input: [entered value]”.For example, after entering “153”, the LCD shows: “Input: 153”.。
Press an operator key (+, –, VOL+ (×), or VOL– (/)) to continue the input.For instance, after entering “153” and then pressing “+”, the LCD shows: “Input: 153+”.
Press more numeric keys to input another value.For example, entering “526” shows: “Input: 153+526”.You can continue entering a full expression like: “Input: 153+526–987*104/356”.
Press the equals key (=) to evaluate the expression.The result will be displayed on the LCD with two decimal places.For example, the LCD will show: “Result: 390.66”.
- Operations Starting with a Negative Sign
First, press the minus key “-”, then input the number. For example, inputting “-136” will display on the LCD as “Input: -136”.
Press an operator key such as “+”, and the LCD will display “Input: -136+”.
Enter another number, for example “598”, and the LCD will update to “Input:
-136+598”. Continue entering the full expression, such as “Input: -136+598*407/386”.
Press the confirm key to calculate and display the result. In this example, the result is shown as “Result: 494.53”.
- Decimal Calculation Process
To enter a decimal number, use the “100+” key as the decimal point.For example, to input “123.45”: first press “123”, then “100+”, and finally “45”.The LCD will show: “Input: 123.45”.
Press an operator key, such as “+”.The LCD updates to show: “Input: 123.45+”.
Enter another decimal or integer.For example, entering “567.89” will result in: “Input:
123.45+567.89”.You may continue inputting a more complex expression, such as:“Input: 123.45+567.89–99.3×23/56.12”.
Press the equals key (=) to evaluate the expression.
The result will be displayed with two decimal places, eg: “Result: 650.64”.
- Division by Zero Handling Process
After entering a number and the “/” operator, then inputting “0” (eg: “236/0”),the LCD will display: “Input: 236/0”.
When the equals key is pressed, the LCD shows: “Result: Error” to indicate an error.
When a division operation is detected, the system checks if the divisor is zero: if (b == 0) return NAN; If the divisor is 0, the function immediately returns a NAN (Not-a-Number) value to prevent invalid calculation. This NAN value is passed up to the main loop, where is nan (result) is evaluated. If true, the system displays “Error” on the screen to inform the user. This mechanism provides immediate interception and consistent handling of division-by-zero errors, ensuring calculator stability and a user-friendly experience.
- Using the EQ Clear Key
During the input process or after completing an expression, if an input error is detected or the user wants to start a new calculation, they can press the EQ Clear Key.
The LCD will clear the current “Input: [entered content]” along with any previous result, returning to the initial state and waiting for new input.
प्रमुख स्पष्टीकरणे
- Infrared Receiver Initialization
IrReceiver.begin(11, DISABLE_LED_FEEDBACK);
Ir Receiver. begin(pin, option) is a method from the IR remote library used to initialize the infrared receiver.
The parameter 11 indicates that the IR receiver’s data output pin (OUT) is connected to GPIO11.
DISABLE_LED_FEEDBACK disables the default onboard LED blinking feedback used by the library, which would otherwise toggle the built-in LED (eg: pin 13) to indicate signal reception.
This line ensures that the IR receiver module works properly and can respond to remote control key presses. Without correctly setting this pin, the system will not be able to receive IR commands. - बॅकलाइट नियंत्रण
पिनमोड(१३, आउटपुट);
डिजिटलराइट(0, उच्च);
Set GPIO0 as an output pin to control the LCD backlight power.
digitalWrite(0, HIGH) sets the backlight control pin to high, which turns on the screen backlight.
If this line is missing, the display may remain black (no visible content) due to the backlight being off, even though the screen is properly rendering the content. - Expression Input Processing (IR Handling in loop())
switch (code) {
case 0x16: input += “0”; break;
case 0x0C: input += “1”; break;
….
case 0x15: input += “+”; break;
case 0x07: input += “-“; break;
case 0x44: input += “/”; break;
case 0x40: input += “*”; break;
case 0x09: input = “”; break;
case 0x43: {
float result = evaluateExpression(input);
}
case 0x19: {
if (!(input.length() == 0 || input.endsWith(“.”) || isOperator(input.back()))) {
input += “.”;
}
खंडित;
}
}
This part uses a switch-case structure to handle IR remote key codes (code) and update the calculator’s input string input accordingly.
case 0x16: input += “0”; break;: Each case corresponds to a remote control button. The ellipsis in the code represents other numeric keys (0-9) corresponding to the cases. When a numeric key is pressed (for example, 0x16 corresponds to 0, 0x0C corresponds to 1, and so on), the number is directly appended to the end of the input string. For the complete code, please check the link to the full code below..
case 0x15: input += “+”; break;: When an operator key (such as +, -, *, /, etc.) is pressed, the corresponding symbol is appended to the input string.
case 0x09: input = “”; break;: When the clear key (eg: 0x09) is pressed, the input string is directly cleared.
OK key (0x43): When the user presses the “=” or “OK” key (corresponding to the infrared code 0x43), a calculation operation is triggered.
float result = evaluate Expression (input);: The evaluate Expression(input) function is called to compute the current input expression string (eg: “3+5*2”), and the result is stored in the result variable.
case 0x19: This corresponds to the decimal point key on the infrared remote control (assuming 0x19 is the infrared code for “.”).
if (!(input.length() == 0 || input.endsWith(“.”) || isOperator(input.back()))): Checks if the decimal point can be entered at this time. If allowed, “.” is appended to the input string. input.length() == 0: The input is empty, preventing a direct leading “.” (eg: “.5”).
input.endsWith(“.”): The last character is “.”, preventing consecutive decimal points (eg: “5..2”).
is Operator (input. back()): The last character is an operator (+, -, *, /), preventing a direct “.” after an operator (eg: “5+.3”). - Computation Logic
• 4.1 Infix to Postfix Conversion:infix To Postfix()
1. infix To Postfix(): This function converts an infix expression (eg: 3 + 4 * 2) into a postfix expression (eg: 3 4 2 * +).It handles operator precedence and parentheses to ensure correct order of operations.
The infix To Postfix function is responsible for converting infix expressions into postfix notation.
Input (infix) → infixToPostfix() → Output (postfix)
2. Infix Expression::This is the standard format we normally use, where operators are placed between operands.
Exampलेस:
• 3 + 4 (addition)
• 10 * (5 – 2) (multiplication with parentheses)
• (2 + 3) / 5 (division with parentheses)
In the code, the input variable holds the user-entered infix expression via IR remote (eg: “3+4*2″). The evaluate Expression() function first converts this infix input to postfix using infix To Postfix() before evaluating it.”
2. Postfix Expression (also known as Reverse Polish Notation):
• In this notation, the operator comes after the operands. This format eliminates the need for parentheses and is easier to process using a stack. Exampलेस:
• Infix: 3 + 4 → Postfix: 3 4 +
• Infix: 10 * (5 – 2) → Postfix: 10 5 2 – *
• Infix: (2 + 3) / 5 → Postfix: 2 3 + 5 /\
- 1. Initialization Section
bool infixToPostfix(const String &infix, String &postfix) {
std::stack<char> stack;
String num = “”;
}
The Infix To Postfix function converts infix expressions into postfix notation (also known as Reverse Polish Notation).
std::stack<char> stack: Creates a stack to temporarily hold operators.
Initialize the string ‘num’ to temporarily store numbers, including multi-digit and decimal numbers. - 2. Handling the Negative Sign (Unary Operator)
if (c == ‘-‘ && (num.isEmpty() || is Operator (infix[i-1]))) {
num += c;
सुरू ठेवा;
}
Key conditions:
• The current character is a “-”
• And there is no preceding number (i.e., ‘num’ is empty) or the previous character is an operator
Exampले:
• In the expression “-5 + 3”, the “-” is recognized as a negative sign
• In the expression “3 – 5”, the “-” is treated as a subtraction operator (so it doesn’t enter this case) - 3. Core Logic
if (isdigit(c) || c == ‘.’) {
num += c;
} else if (isOperator(c)) {
if (num.length() > 0) {
postfix += num + ” “;
num = “”;
}
while (!stack.empty() && precedence(stack.top()) >= precedence(c)) {
postfix += stack.top();
postfix += ” “;
stack.pop();
}
stack.push(c);
} इतर {
खोटे परत करा;
}
Part 1: Handling Numbers and Decimal Points
if (isdigit(c) || c == ‘.’) {
num += c;
}
if (isdigit(c) || c == ‘.’) checks whether the current character c is a digit (using isdigit(c)) or a decimal point (‘.’). If yes, it gets added to the temporary number string ‘num’.
num += c; appends the character to ‘num’, which temporarily holds continuous digits until an operator or the end of the expression is encountered. - 4. Operator Handling
else if (isOperator(c)) {
if (!num.isEmpty()) {
postfix += num + ” “;
num = “”;
}
while (!stack.empty() && precedence(stack.top()) >= precedence(c)) {
postfix += stack.top() + ” “;
stack.pop();
}
stack.push(c);
}
Suppose the infix expression being processed is 3+4*2, and the current operator scanned is “+”:
- else if (isOperator(c)) { … }
• Purpose: This branch runs when an operator (such as +, -, *, /) is encountered.
• उदाample: When the “+” is scanned, this branch is triggered. - if (num.length() > 0) { … }
• Purpose: Checks if a complete number has been accumulated (eg: 3 or 3.14).
• Logic:
• If ‘num’ is not empty (meaning a number was scanned before), add it to the postfix expression and clear ‘num’ to prepare for the next number.
• If ‘num’ is empty (such as when operators appear consecutively like the second “-” in 3+-4), this step is skipped.
• उदाampले:
• When “+” is scanned and ‘num’ is “3” (length > 0), execute postfix += “3 “, so the postfix expression becomes “3 “, and ‘num’ is cleared. - postfix += num + ” ”
• Purpose:
• Adds the accumulated number (like 3 or 3.14) to the postfix expression, followed by a space for separation.
• उदाampले:
• After adding 3, the postfix expression becomes “3 “.
• As 4 and 2 are scanned later, the postfix expression updates to “3 4 ” and then “3 4 2 “. - num = “”
• Purpose: Clears the temporary variable ‘num’ to get ready for the next number.
• उदाampले:
• After adding 3, ‘num’ resets from “3” to an empty string to prepare for collecting the next number, 4. - Operator Precedence Handling (details omitted)
• Purpose: Manage stack operations based on operator precedence.
• उदाampले:
• When scanning “+”, the stack is empty, so “+” is pushed onto the stack directly.
• When scanning “”, since “” has higher precedence than the “+” on top of the stack, “*” is pushed onto the stack.
• The final postfix expression becomes 3 4 2 * +.
Handling Operator Precedence:
while (!stack.empty() && precedence(stack.top()) >= precedence(c)) {
postfix += stack.top() + ” “;
stack.pop();
}
Loop conditions:
• !stack.empty(): Process the top operator only when the stack is not empty.
• precedence(stack.top()) >= precedence(c): The precedence of the operator at the top of the stack is greater than or equal to that of the current operator c.
• stack.pop(): Pop the top operator from the stack and append it to the postfix expression (eg: +, *).
▪ 5. Finalizing the Expression: Add the Last Number and Remaining Operators from the Stack to the Postfix Expression.
if (!num.isEmpty()) postfix += num + ” “;
while (!stack.empty()) {
postfix += stack.top() + ” “;
stack.pop();
}
if (!num.isEmpty()) postfix += num + ” “: Handles the last number in the expression. When reaching the end of the infix expression, the temporary variable ‘num’ may still hold the last number (eg: 3.14), which needs to be added to the postfix expression. If ‘num’ is not empty, add it to the postfix expression followed by a space (numbers and operators in postfix are separated by spaces).
while (!stack.empty()) { … }: Pops all remaining operators from the stack and appends them to the postfix expression. After scanning the infix expression, the stack may still contain operators (such as +, *), which should be popped in order and added to the postfix expression. Due to the stack’s Last-In-First-Out nature, the popping order naturally respects operator precedence rules.
• 4.2 Evaluating Postfix Expressions: evaluatePostfix()
evaluatePostfix() is a function that calculates the value of a postfix expression (Reverse
Polish Notation, RPN). It takes a space-separated postfix expression string (eg: “3 4 2 * +”) and returns its computed result (eg: 11).
Postfix Expression → evaluatePostfix() → Final Result.
float evaluatePostfix(const String &postfix) {
std::stack<float> stack;
String token = “”;
for (int i = 0; i <= postfix.length(); ++i) {
char c = postfix[i];
if (c == ‘ ‘ || c == ‘\0’) {
if (token.length() > 0) {
if (isOperator(token[0]) && token.length() == 1) {
if (stack.size() < 2) return NAN;
float b = stack.top(); stack.pop();
float a = stack.top(); stack.pop();
switch (token[0]) {
case ‘+’: stack.push(a + b); break;
case ‘-‘: stack.push(a – b); break;
case ‘*’: stack.push(a * b); break;
case ‘/’:
if (b == 0) return NAN;
stack.push(a / b);
खंडित;
}
} इतर {
stack.push(token.toFloat());
}
token = “”;
}
} इतर {
token += c;
}
}
return (stack.size() == 1) ? stack.top() : NAN;
}
- Variable Initialization
std::stack<float> stack;
String token = “”;
std::stack<float> stack; This line defines a stack container named ‘stack’ specifically for storing operands of type float. Its main role is to temporarily hold numbers during the evaluation of the postfix expression.
• std:: indicates that the stack belongs to the C++ Standard Library.
• Stack: The stack data structure is chosen because its Last-In-First-Out (LIFO) behavior perfectly matches the evaluation logic of postfix expressions (when an operator is encountered, the most recently pushed numbers are processed first).
• Float: Specifies that the elements in the stack are floating-point numbers, allowing correct handling of integers, decimals, and negative numbers.
• stack(variable name): The name clearly reflects its purpose—to store operands for calculation, which are dynamically managed using push() and pop() operations. String token = “”: This line initializes an empty string variable named ‘token’, which is used to build up numbers or operators character by character during postfix expression parsing, until a space or string end triggers processing.
• String: Indicates this variable is a string type (likely Arduino’s String class or similar), capable of flexibly storing multi-character numbers (eg: “3.14”) or single-character operators (eg: “+”).
• token (variable name): Named after the compiler concept “token,” representing an independent unit extracted from the expression (a complete number or operator).
• = “”: Initialized as an empty string to ensure no leftover data before processing each new token. - Main Loop
for (int i = 0; i <= postfix.length(); ++i) {
char c = postfix[i];
if (c == ‘ ‘ || c == ‘\0’) {
} इतर {
token += c;
}
}
for (int i = 0; i <= postfix.length(); ++i): The loop condition includes the equal sign (<=) to ensure the iteration reaches the string termination character \0, allowing correct termination even if there’s no trailing space.
char c = postfix[i]; Retrieves the character at position i, which could be a digit, operator, space, or the string terminator \0.
if (c == ‘ ‘ || c == ‘\0’): When the current character is a space or the string terminator \0, it indicates a complete token has been formed (eg: “5” or “*”).
Separator branch (if): Triggered when the token holds a complete unit (like “3.14” or “+”), then
enters processing logic.
Non-separator branch (else): Concatenates digits, decimal points, or operator characters to build
a complete token.
• माजी साठीample, input “3.14” appends ‘3’, ‘.’, ‘1’, ‘4’ sequentially, resulting in token = “3.14”.
• Input “” directly sets token = “” (a single-character operator).
▪ 3. Processing the Token
1. If it is an operator:
if (token.length() == 1 && isOperator(token[0])) {
if (stack.size() < 2) return NAN;
float b = stack.top(); stack.pop();
float a = stack.top(); stack.pop();
switch (token[0]) {
case ‘+’: stack.push(a + b); break;
case ‘-‘: stack.push(a – b); break;
case ‘*’: stack.push(a * b); break;
case ‘/’: if (b == 0) return NAN; stack.push(a / b); break;
}
}
Operator check: If the token is one of +, -, *, or /:
• 1. if (stack.size() < 2) return NAN; — Verify operand count: At least two numbers must be on the stack to perform the operation; otherwise, return NAN indicating an invalid expression.
• 2. float b = stack.top(); stack.pop(); float a = stack.top(); stack.pop(); — Pop operands: The first popped value is the right operand b, and the second is the left operand a, ensuring the correct order for evaluation.
• 3. Perform operation: Compute a op b according to the operator and push the result back onto the stack.
• 4. case ‘/’: if (b == 0) return NAN; stack.push(a / b); break; — Division by zero check: If the divisor b is zero, return NAN to prevent division errors.
2. If it is a number:
इतर {
stack.push(token.toFloat());}
stack.push(token.toFloat());: Converts the token to a float and pushes it onto the stack, preparing it for future operations. - Reset token:
token = “”;
token = “”;: Resets the string variable token to an empty string, clearing the processed token (whether a number or operator) and preparing to parse the next expression unit. - Return the final result
return (stack.size() == 1) ? stack.top() : NAN;
Using a conditional (ternary) operator with the following logic:
• stack.size() == 1: Checks if there is exactly one element left in the stack.
• stack.top(): If there is exactly one element, returns it as the final result.
• NAN: If the stack size is not one (empty or multiple leftover elements), returns NAN indicating invalid or erroneous calculation.
• 4.3 Helper Function
bool isOperator(char c) {
return c == ‘+’ || c == ‘-‘ || c == ‘*’ || c == ‘/’;
}
bool isOperator(char c)
Parameter: c — the character to check
Return value: boolean; returns true if c is an operator, otherwise false
return c == ‘+’ || c == ‘-‘ || c == ‘*’ || c == ‘/’;
Uses the logical OR operator (||) to check if the character c matches any of the four basic
arithmetic operators:
• +(addition)
• -(subtraction)
• *(multiplication)
• / (division) - दशांश बिंदू हाताळणी
case 0x19: {
if (input.length() == 0 || input.endsWith(“.”) || isOperator(input[input.length() – 1])) {
खंडित;
}
int i = input.length() – 1;
while (i >= 0 && (isdigit(input[i]) || input[i] == ‘.’)) {
if (input[i] == ‘.’) break;
–i;
}
if (i >= 0 && input[i] == ‘.’) break;
input += “.”;
खंडित;
}
- 1. Invalid Input Validation:
if (input.length() == 0 || input.endsWith(“.”) || isOperator(input[input.length() – 1]))
• input.length() == 0: Prevents entering a decimal point when there’s no prior input.
• input.endsWith(“.”): Prevents entering multiple decimal points in a row.
• isOperator(input[input.length() – 1]): Ensures a decimal point doesn’t follow directly after an operator. - 2. Current Number Check:
int i = input.length() – 1;
while (i >= 0 && (isdigit(input[i]) || input[i] == ‘.’)) {
if (input[i] == ‘.’) break;
–i;
}
int i = input.length() – 1;: A variable i is defined and initialized to point to the last character in the input string, so the scan can go from right to left.
while (i >= 0 && (isdigit(input[i]) || input[i] == ‘.’)): The loop continues scanning left as long as the index is valid (i >= 0) and the character is either a digit or a decimal point. This helps isolate the current number being typed (like “12.34” in a longer expression).
if (input[i] == ‘.’) break;: If a decimal point is found, the loop stops right away, indicating that the current number already includes a decimal point—so no more can be added.
–i;: The index i is decremented to continue checking the characters to the left. - 3. Final Decision:
if (i >= 0 && input[i] == ‘.’) break;
input += “.”;
1. if (i >= 0 && input[i] == ‘.’) break;
• i >= 0: Ensures that the index is within valid bounds and prevents out-of-range errors.
• input[i] == ‘.’: Checks if the current character is a decimal point.
• break;:If a decimal has already been found in the number, exit the loop.
2. input += “.”;
If no decimal point was found during the scan (meaning the loop wasn’t broken), then a decimal point is safely appended to the input string.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the above code, you will have built a simple calculator controlled by an infrared remote. It allows users to input numbers and operators using the remote, displays the expression in real time on the screen, and performs calculations including decimal support and basic arithmetic operations. Additional features include backlight control, input denounce handling, and validation for decimal point usage. The entire calculation process and result are clearly presented through a graphical user interface.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use two additional library (IRremote and LovyanGFX-develop), so it’s
important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries directory and download the IR remote and LovyanGFX-develop folder.
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा २० – हॉल काउंटर
परिचय
In this chapter, you’ll learn the basic application of a Hall effect sensor. A magnet is used to trigger the sensor, enabling a counting function with the results displayed in real time on a TFT screen. This system is useful for detecting magnetic field changes and can be applied in scenarios such as access control counters and object detection.
या धड्यात वापरलेले हार्डवेअर:

Working Principle of Hall Sensor
A Hall sensor detects magnetic fields via the Hall effect. When current flows perpendicular to a magnetic field in a semiconductor plate, carriers deflect due to Lorentz force, generating a transverse potential difference (Hall voltage). This voltage, proportional to field strength, is amplified into analog/digital outputs. It measures field intensity, position, speed, etc., featuring non-contact operation and high reliability for motor control and position sensing.
एलईडीचे कार्य तत्व
LED (प्रकाश उत्सर्जक डायोड) च्या केंद्रस्थानी एक अर्धसंवाहक PN जंक्शन असते. जेव्हा फॉरवर्ड बायस व्हॉल्यूमtage is applied, electrons from the N-type region recombine with holes from the P-type region near the junction. During this recombination, electrons drop from a higher energy level to a lower one, releasing the excess energy in the form of photons—producing light. The color (or wavelength) of the emitted light is determined by the energy band gap of the semiconductor material. This process is a direct application of electroluminescence.
ऑपरेशन इफेक्ट डायग्राम
- प्रारंभिक स्थिती:
After powering on, the TFT screen displays “Counter: 0,” and the system enters standby mode.
- Count Trigger:
a. When a magnet is brought near the Hall sensor, it detects the change in magnetic
field and outputs a high signal.
b. Upon receiving the signal, the microcontroller flashes a red LED once (turns it on and off), and the counter increments by 1.
c. The TFT screen updates in real time to display “Counter: X,” where X is the current
- Repeating the Count Operation:
Each time the magnet is brought close to and then removed from the sensor, the counter increments following the same process (e.g., 1 → 2 → 3…), with the LED flashing and the display updating for every count.count.
प्रमुख स्पष्टीकरणे
- Display Initialization and Interface Update Function
void updateCounterDisplay(int count) {
gfx.fillScreen(TFT_BLACK);
gfx.setCursor(60, 100, 4);
gfx.setTextSize(1);
gfx.setTextColor(TFT_WHITE);
gfx.printf(“counter: %d”, count);
}
gfx.fillScreen(TFT_BLACK); This command fills the entire screen with black using the fillScreen() method. TFT_BLACK is a predefined color constant in the LovyanGFX library. This ensures that each screen update starts with a clean background.
setCursor(x, y, font): This method sets the starting position and font for text display.
• 60 is the X coordinate (horizontal offset from the left edge),
• 100 is the Y coordinate (vertical offset from the top),
• 4 is the font index (an optional parameter that likely specifies a particular font style).
gfx.setTextSize(1); Sets the text scaling factor. A value of 1 keeps the text at its original size.
Larger values scale the text proportionally.
gfx.setTextColor(TFT_WHITE); Sets the text color to white. TFT_WHITE is a predefined white color constant in the LovyanGFX library.
gfx.printf(“counter: %d”, count); Uses the printf() function to format and print the text on screen.
It displays “counter: ” followed by the value of count. The %d is a placeholder that inserts the integer value of count in decimal format. - Hall Sensor Detection Logic
if (digitalRead(hall) == LOW) {
विलंब(50);
if (digitalRead(hall) == LOW) {
while (digitalRead(hall) == LOW);
मोजा++;
updateCounterDisplay(count);
digitalWrite(redLed, HIGH);
विलंब(200);
digitalWrite(redLed, LOW);
}
}
Use a two-step digitalRead() check combined with a 50ms delay to implement debounce handling.
while (digitalRead(hall) == LOW); Wait until the magnet moves away to prevent counting a single trigger multiple times.
When a magnet is successfully detected:
• Increment the count (count++).
• Call updateCounterDisplay() to refresh the screen.
• Briefly flash the red LED to indicate a successful trigger.
This process is crucial to ensure the Hall sensor triggers accurately, resists interference, and avoids duplicate counts. - Backlight Control and Display Initialization
gfx.init();
पिनमोड(१३, आउटपुट);
डिजिटलराइट(0, उच्च);
gfx.init(): This is the core call to initialize the LovyanGFX display system. It performs several key steps: first, it establishes SPI communication with the ST7789 display controller at an 80MHz clock speed, configures the display parameters for a 240×320 resolution, initializes the FT5x06 touch controller via I2C (address 0x38), and finally allocates memory for the display buffer.
Notably, this function automatically sets up the hardware interfaces based on the SPI pin configuration defined earlier in the LGFX class (SCLK=6, MOSI=7, DC=16, etc.), and sends the factory default initialization command sequence to the screen to ensure proper color mode (RGB565) and scan direction.
pinMode(0, OUTPUT): sets GPIO0 as a digital output to control the display backlight circuit. In the hardware design, this pin is usually connected to the gate of an N-MOSFET (such as AO3400). By controlling the MOSFET’s conduction, it switches the power supply to the backlight LED. Setting the pin to OUTPUT mode configures the GPIO as a push-pull output, capable of driving up to 12mA according to the RP2040 chip specs, sufficient to directly drive a small MOSFET. It’s important to note that pin 0 here refers to RP2040’s GPIO0, not the physical pin number on the board.
digitalWrite(0, HIGH): outputs a 3.3V high signal to GPIO0, activating the backlight circuit. When set high, the connected MOSFET fully conducts, allowing the backlight LED’s anode to receive power (typically 5V supply). This action triggers two key effects: first, it enables the backlight boost circuit (if the screen uses a constant-current driver), and second, it sets the PWM duty cycle to 100%, achieving maximum brightness.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the code above, you have implemented a Hall effect sensor counting system that updates the count in real time on the TFT screen using the format “counter: X”. When a magnet approaches the Hall sensor, the system triggers a count, while the red LED flashes for 200ms as visual feedback. The design employs dual detection and delayed debounce mechanisms to ensure counting is both accurate and reliable.
प्रोग्रामिंग स्टेप्स
टीप: For detailed programming steps, you can refer to the programming process in the first lesson.
In this lesson, we use an additional library (LovyanGFX-develop), so it’s important to include it before running the code to avoid compilation errors.
- Download the Library
• Click the link below:
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2
• Navigate to the /example/libraries directory and download the LovyanGFX-develop folder
- Add the Library to the Arduino Environment
• In the Arduino IDE, click on the File मेनूवर जा आणि प्राधान्ये निवडा.
• Open the corresponding folder on your computer. Inside, you’ll find a folder named libraries – this is where Arduino stores third-party libraries.
• Copy or move the downloaded library folder directly into the libraries directory. Once done, the Arduino IDE will automatically recognize and be able to use this library.
- Upload and Run the Code(You can refer to the flashing steps from Lesson 1 (page 10-15) as a guide.)
After placing the library correctly, follow the upload steps from Lesson 1 to compile and upload the code to your board. Make sure the compilation completes without errors before running the program.
धडा २१ – धुराचा अलार्म
परिचय
In this chapter, you’ll learn the principles and implementation of an alarm system based on the MQ2 smoke sensor. The system triggers a buzzer when it detects a certain level of smoke in the environment. This lesson focuses on the basics of sensor signal acquisition and alarm logic.
या धड्यात वापरलेले हार्डवेअर:
Working Principle of Gas Sensor
A gas sensor detects target gases via reactions that alter the electrical properties (eg: resistance/capacitance/current) of sensing materials. MOS types rely on resistance changes from gas adsorption; electrochemical sensors generate current via redox reactions; infrared models measure light absorption at specific wavelengths. Signal processing converts variations into concentration readings, offering high selectivity and rapid response.
बजर ऑपरेशनचे कार्य तत्व
The buzzer generates sound by vibrating a diaphragm driven by an electrical signal.
When an alternating current is applied, the diaphragm vibrates rapidly due to magnetic or piezoelectric effects, producing sound. The pitch and frequency are determined by the current frequency, and it is commonly used for alerts or alarms.
ऑपरेशन इफेक्ट डायग्राम
- Prepare a safe smoke source (take extreme caution to avoid any fire hazard during the process).
(In this demonstration, I used a lighter and extinguished the flame, allowing it to emit only carbon monoxide.) - Slowly move the smoke source closer to the sensing head of the MQ-2 sensor.

- Observe the system’s response: when the smoke concentration exceeds the preset threshold, the buzzer should sound continuously as an alarm.

प्रमुख स्पष्टीकरणे
- Analog Pin Reading and Voltage रूपांतरण
float sensorValue = analogRead(gas_pin);
float sensor_volt = sensorValue / 1023.0 * 5.0;
The analogRead() function returns an integer between 0 and 1023, corresponding to an input voltagई श्रेणी 0 ते 5 व्होल्ट्स पर्यंत आहे.
To determine the actual voltage, the raw value is converted using the formula: sensorValue / 1023.0 * 5.0. This voltage is then used to estimate the gas concentration.
When detecting gases such as smoke, methane, or propane, the MQ-2 sensor’s analog output voltage increases proportionally with the concentration of gas.
Significance: This is the core data-processing step for smoke detection—it determines whether the system should trigger an alarm. - Smoke Voltage Threshold Detection and Buzzer Alarm
if (sensor_volt > 1.0) {
tone(buzzerPin, 1300);
} इतर {
noTone(buzzerPin);
}
When the MQ-2 sensor’s output voltage exceeds 1.0V, it indicates the presence of a certain concentration of smoke or gas in the air.
tone(pin, freq) sends a square wave of the specified frequency—1300Hz in this case—to the buzzerPin, producing an audible alarm.
noTone(pin) stops the sound output from the buzzer.
Significance: This forms the core logic of the alarm response—using a simple voltage threshold to deliver real-time audio warnings. - Serial Output for Monitoring and Debugging
Serial.print(“Voltagई: “);
Serial.print(sensor_volt);
Serial.println(” V”);
वर्तमान खंडtage reading is sent to the serial port, making it easy to debug or observe real-time data using a serial monitor tool.
Based on the test results, the alarm threshold can be fine-tuned dynamically for better accuracy.
Significance: This feature is essential for debugging and calibrating the sensor, especially useful during the development and testing phase.
पूर्ण कोड
कृपया खालील लिंकवर क्लिक करा view संपूर्ण कोड अंमलबजावणी.
https://github.com/Elecrow-RD/All-in-one-Starter-Kit-for-Pico-2/tree/master/example/pico_arduino_code
After studying the above code, you’ve built a basic alarm system using an MQ2 smoke sensor. It reads the analog voltage from the sensor and compares it to a 1.0V threshold. If the voltage exceeds this value—indicating the presence of smoke—the system triggers a 1300Hz alarm sound through the buzzer. If not, the buzzer remains silent. Meanwhile, the current voltage is continuously output via the serial port for monitoring and debugging purposes.
प्रोग्रामिंग स्टेप्स
तुम्ही मार्गदर्शक म्हणून धडा १ (पृष्ठ १०-१५) मधील फ्लॅशिंग स्टेप्सचा संदर्भ घेऊ शकता.

www.elecrow.com
MAKE YOUR MAKING EASIER
कागदपत्रे / संसाधने
![]() |
एलक्रो पिको २ ऑल इन वन स्टार्टर किट [pdf] वापरकर्ता मॅन्युअल PICO 2, PICO 2 ऑल इन वन स्टार्टर किट, ऑल इन वन स्टार्टर किट, स्टार्टर किट |
