Skip to content

Commit 1f3d227

Browse files
Add 'Temp_LDR_Serial_Reader/' from commit '230c70e2f73accff61067a798dbf253bfc1ca10c'
git-subtree-dir: Temp_LDR_Serial_Reader git-subtree-mainline: 8e3d1e3 git-subtree-split: 230c70e
2 parents 8e3d1e3 + 230c70e commit 1f3d227

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

Temp_LDR_Serial_Reader/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Shahm Najeeb
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Temp_LDR_Serial_Reader/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
3+
# Arduino Sensor Serial Reader
4+
5+
A fun and simple project that allows you to use an Arduino to read sensor data from selected pins and send the results over the serial connection.
6+
7+
## Requirements
8+
9+
To get started, you’ll need the following hardware:
10+
11+
- **Arduino Nano**
12+
- **LDR** (Light Dependent Resistor, 2-pin model)
13+
- **Resistor** (10kΩ, preferred)
14+
- **Thermistor** (LM35 model for temperature)
15+
16+
## Setup
17+
18+
### Circuit Assembly
19+
20+
Here’s how to set up the circuitry:
21+
22+
- LM35 (Temperature Sensor)
23+
- **VCC**: Connect to **5V** on the Arduino Nano.
24+
- **GND**: Connect to **GND** on the Arduino Nano.
25+
- **Output (Analog Signal)**: Connect to **A0** on the Arduino Nano.
26+
- LDR (Light Dependent Resistor)
27+
- One leg of the LDR: Connect to **A1** on the Arduino Nano.
28+
- The other leg of the LDR: Connect to **5V** on the Arduino Nano through a **10kΩ pull-down resistor** to **GND**. This configuration ensures the LDR provides a readable voltage level at **A1**.
29+
30+
![Circuit diagram](https://github.com/user-attachments/assets/49237c92-5590-4c77-841c-89898fff56c5)
31+
32+
### Receiver Side
33+
34+
The Arduino code sends data over the serial connection every second (note: not the most precise, but functional). The communication uses a **BAUD RATE** of **115200**.
35+
36+
> [!Important]
37+
> Ensure you're familiar with uploading code to the Arduino Nano using the Arduino IDE. If you face issues during upload, please note:
38+
>
39+
> - When using a **CH341** chip for serial communication, you must upload the code with the **Old Bootloader**.
40+
> - The driver version must be **3.7.2022.1**. You can download the correct version from [this link](https://cdn.sparkfun.com/assets/learn_tutorials/8/4/4/CH341SER.EXE).
41+
42+
## Usage
43+
44+
Once uploaded, the Arduino Nano will send a string containing two float values over the serial connection. The first value represents the temperature from the LM35, and the second is the reading from the LDR. The data is in a **JSON-like** format, structured as follows:
45+
`[int, float]` where the `int` is temperature (In Celsius) and `float` is LDR
46+
47+
You can easily parse this string into an array for further use in your application.
48+
49+
------
50+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const int lm35Pin = A0; // LM35 temperature sensor on A0
2+
const int ldrPin = A1; // LDR sensor on A1
3+
4+
void setup() {
5+
Serial.begin(115200); // Start serial communication
6+
}
7+
8+
void loop() {
9+
// Read temperature from LM35 (in Celsius)
10+
int tempRaw = analogRead(lm35Pin);
11+
float temperature = (tempRaw * 5.0 / 1024.0) * 100.0;
12+
13+
// Read light intensity from LDR
14+
int ldrValue = analogRead(ldrPin);
15+
16+
// Send data as a JSON-like string
17+
Serial.print("[");
18+
Serial.print(temperature, 2);
19+
Serial.print(", ");
20+
Serial.print(ldrValue);
21+
Serial.println("]");
22+
23+
delay(1000); // Send data every second
24+
}

0 commit comments

Comments
 (0)