You are a beginner with Croduino. 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 e-radionica 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 Croduino and the basic code. Everything else is left to your imagination.


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 LM 393 breakout are:
• Hall effect sensor
• Fire detector
• Light sensor
• Vibration sensor
• Humidity sensor
• Soil humidity sensor


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 Croduino, 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.

Hall effect sensor
Hall Effect Sensor is a sensor that measures the magnetic field using the Hall Effect. The stronger the magnetic field, the smaller the voltage on the analog output from the module. The sensor is as big as the transistor and it is also located in the plastic housing. This sensor is used to measure the speed of a bicycle and in similar applications where it is necessary to measure the speed of rotation (e.g. measuring engine rotating speed or determining engine rotor position). This sensor is most often used as a digital sensor because for measuring speed, it is enough to know when a magnet passes the sensor, and then we count how many times the magnet has passed in a period of one second, and we get the speed.

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.

Vibration sensor
The vibration sensor works as a switch because, within, it has a small spring, and in the middle of the spring there is a wire. When the spring trembles, it touches the middle wire and makes contact. Using this sensor we can detect when there are, and when there are no vibrations. If we look at the sensor’s picture, its working principle is clear and it is visible that it is a switch that reacts to vibrations.

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.


The sensors are connected either from the A0 output to the analog pin of the Croduino 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 Croduino 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.


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.

int ocitanje;//variable to which we save values from the sensor
int analogPin=A0; //pin to which the analog output from the sensor is connected
void setup() {
 pinMode(analogPin,INPUT); //setting the analog pin as input
Serial.begin(9600); //Serial communication initialization (speed 9600 baud)
void loop() {
ocitanje=analogRead(analogPin);//saving the value from the analog pin to the variable reading (očitanje)
Serial.println(ocitanje);//displaying the variable on the Serial monitor
delay(1000);//1 second pause

When it comes to the second example, we have taken a light sensor, connected one LED to it and gradually turned it on as the darkness came as well as turned it off when our sensor was illuminated. We can use another sensor to control something else, but here we have shown how we can use the analog value from the sensor to get more states.

int ocitanje;//variable to which we save values from the sensor
int analogPin=A0; //pin to which the sensor's analog output is connected
int ledPin=9;
void setup() {
 pinMode(analogPin,INPUT); //setting the analog pin as input
Serial.begin(9600); //Serial communication initialization (speed 9600 baud)
void loop() {
ocitanje=analogRead(analogPin);//saving the value from the analog pin to the ocitanje variable
Serial.println(ocitanje);//displaying the ocitanje variable on the Serial monitor
  //depending on the reading from the sensor, we turn the LED on on the pin 9
  //(if the value is more than 900, the LED is the brightest
  //if the reading is less than 200, the LED is off)
  else if(ocitanje>=680){
  else if(ocitanje>=500){
  else if(ocitanje>=350){
  else if(ocitanje>=200){
  else if(ocitanje<200){
delay(1000);//1 second pause