This code is an Arduino sketch for a temperature control system using a thermistor. It reads the temperature from two thermistors, calculates the average temperature, and adjusts a PWM (Pulse Width Modulation) output based on the desired temperature.
To run this code, you will need:
- Arduino board
- Two thermistors
- Resistors
- Jumper wires
- A PWM output device (e.g., fan, heater, LED)
The thermistors should be connected to analog input pins A0
and A1
on the Arduino board. The PWM output pin should be connected to pin 9
. Additionally, ensure that the required resistors are correctly connected.
The following constants are used for temperature calculation:
thermistorNominal
: Nominal resistance of the thermistor at 25°C.temperatureNominal
: Nominal temperature for the thermistor.betaValue
: Beta value of the thermistor.desiredTemperature
: The desired temperature in Celsius.
The code contains the following functions:
setup()
: Initializes the PWM pin and the Serial Monitor for debugging.loop()
: Continuously reads the temperature from both thermistors, calculates the average temperature, calculates the PWM ratio, sets the PWM output, and prints the temperature and PWM values to the Serial Monitor. It then waits for one second before taking the next reading.readTemperature(int pin)
: Reads the analog value from the specified thermistor pin, converts it to resistance, and calculates the temperature in Celsius using the Steinhart-Hart equation.
graph TD
A[Start] --> B[Setup]
B --> C[Loop]
C --> D[Read temperature from thermistors]
D --> E[Calculate average temperature]
E --> F[Calculate PWM ratio]
F --> G[Calculate PWM value]
G --> H[Set PWM output]
H --> I[Print temperature and PWM values]
I --> J[Delay]
J --> C
C --> K[End]
subgraph Functions
D --> readTemperature
end
- Connect the thermistors, resistors, and PWM output device according to the circuit connections mentioned above.
- Upload the code to your Arduino board.
- Open the Serial Monitor in the Arduino IDE (set the baud rate to
9600
) to view the temperature and PWM values.
- The code uses the Steinhart-Hart equation to calculate the temperature from the thermistor resistance. Make sure the equation is appropriate for your specific thermistor.
- Adjust the
thermistorNominal
,temperatureNominal
, andbetaValue
constants according to the specifications of your thermistor. - Modify the
desiredTemperature
to set your desired temperature. - The PWM output pin should be connected to a compatible device capable of adjusting its output based on the PWM value (e.g., a fan, heater, or LED).
- If you encounter any issues, ensure that the circuit connections are correct and the components are properly functioning.
- Double-check the thermistor specifications and adjust the constants accordingly.
Contributions to this repository are welcome. If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.
This code was developed based on the requirements of the temperature control system using thermistors.
Please note that this code is provided as-is and without any warranty. Use it at your own risk.