HUM: LM393 BREAKOUTS

You are a beginner with Dasduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by soldered where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect the module with Dasduino and the basic code. Everything else is left to your imagination.
INTRODUCTION
In this tutorial, we will get acquainted with numerous sensors working on a similar principle. All sensors are connected to the same breadboard that has an analog and digital output, and the sensor itself is located on it. How is it possible that we use the same breadboard for more sensors, and how they work will be explained below, and for starters, we are going to see which sensors we have.
Sensors that work with the LM393 breakout are:
• Fire detector
• Light sensor
• Humidity sensor
• Soil humidity sensor
HOW DOES IT WORK?
The LM 393 is a voltage comparator that compares two voltages and depending on their relation, the output is connected to GND or VCC(power supply voltage comparator), and, since in our case, the power supply voltage is 5V, then at the comparator output we have either a logical 0 or logical 1. Each of these sensors is analog, i.e. as an output it provides an analog value that can be read on Dasduino, but with the comparator, using the potentiometer we can adjust the precise value at which the output turns from the logical 0 to logical 1 or vice versa. Find out more about the comparator working principle in our LM393 comparator tutorial. On the sensor board, we have adequate resistors and capacitors which are necessary for the work of the comparator and sensor that are connected to the breadboard.
Fire detector (phototransistor)
The fire detector is a phototransistor which, because of its dark lense, detects infrared light. Infrared light is emitted by the sun, but also the fire, and that is why this sensor is suitable for fire detecting. The sensor is activated when it is near the source that emits infrared radiation and the stronger the radiation, the smaller the value on the analog output. The digital output has 5V (logical 1) when there is no radiation, and when the radiation increases at the adjusted value (the value at which the output state changes is adjusted by the potentiometer) the digital output turns from logical 1 to logical 0.
Light sensor
The light sensor is a photoresistor that changes the resistance value depending on the intensity of light. When a photoresistor is connected to our breakout, we get a sensor to measure the amount of light, and at the output, we get a voltage that is proportional to the intensity of light. On this sensor, we can use the digital output to turn on the light by adjusting the light level at which the digital output is activated. The sensor provides a higher voltage on the analog output when it is dark, and lower when it is illuminated.
Humidity sensor
The humidity sensor provides analog values depending on humidity, so that voltage analog values change with the increase of humidity. The sensor is a resistant tile that changes resistance with the change of humidity. The digital output is 5V when humidity is lower, which is adjusted using the potentiometer and it turns off when humidity is higher than the adjusted value.
Soil humidity sensor
This sensor is similar to the humidity sensor because it has the same working principle, only this one is used in the soil, i.e. we plant the sensor into the soil in order to measure soil humidity.
HOW TO CONNECT?
The sensors are connected either from the A0 output to the analog pin of the Dasduino if we want to read analog values or we can connect the digital output (D0) from the sensor to any other digital pin on the Dasduino and read only when the pin turns from logical 0 to logical 1 and vice versa, and the value at which it happens must be adjusted using the potentiometer on the board. Sometimes it is enough to read the transition between two states in the project, and sometimes we need the analog value to be able to, depending on that value, do some things (we can have more than 2 states) and according to that we must choose which output will be used, or we can use both outputs. To the board, we still must connect +5V and the GND and we can finally read the values from the sensor.
ARDUINO CODE
The code is the same for all of these sensors and in the example, we have used the analog input and we have read values only from that input, saved them to the variable and displayed that variable on the Serial monitor.