Commonly used sensors with Arduino Uno

by Apr 5, 2020Arduino Uno, Sensors

The sensor converts a physical parameter into a signal, generally in terms of voltage or current. Sensors are the sensory organs of the Embedded system.

Some commonly used sensors are as follows:

  1. Soil Humidity Sensor
  2. IR Sensor
  3. Smoke sensor
  4. Ultrasonic Sensor
  5. Rain Sensor
  6. Temperature Sensor
  7. Pressure Sensor
  8. Touch Sensor
  9. Photoresist Sensor
  10. Accelerometer Sensor

1.Soil Humidity Sensor:

The Moisture Sensor is used to measure the water content(moisture) of soil. When the soil is having water shortage, the module output is at high voltage (5 Volt), else the output is at a low level (0 Volt).

credit
//Digital read from the analog sensor
int led_pin =13;

int sensor_pin =8;

void setup() 
{

  pinMode(led_pin, OUTPUT);

  pinMode(sensor_pin, INPUT);

}

void loop()
{

  if(digitalRead(sensor_pin) == HIGH)
  {

    digitalWrite(led_pin, HIGH);//Turn on LED if soil is Dry

  } 
  
  else
  
  {

    digitalWrite(led_pin, LOW);//Turn off LED if soil is Dry

    delay(1000);

  }

}
//Analog read

int sensor_pin = A0;

int output_value ;

void setup() {

   Serial.begin(9600);

   Serial.println("Reading From the Sensor ...");

   delay(2000);

   }

void loop() {

   output_value= analogRead(sensor_pin);

   output_value = map(output_value,550,0,0,100);// we will map the output values to 0-100, 
                                                //   because the moisture is measured in 
                                                //    percentage
   //For wet soil it was 550 for dry soil it is 100.

   Serial.print("Mositure : ");

   Serial.print(output_value);

   Serial.println("%");

   delay(1000);

   }

2.IR Sensor:

IR sensors work on the basic principle of reflection and absorption of light. One of the sensors emits infrared light. if the surface is blackish it absorbs light and the IR sensor reads no reading. but if it is whitish then light gets reflected and we get a reading on the IR sensor.

credit
int IRSensor = 2; // connect ir sensor to arduino pin 2
int LED = 13; // conect Led to arduino pin 13



void setup() 
{



  pinMode (IRSensor, INPUT); // sensor pin INPUT
  pinMode (LED, OUTPUT); // Led pin OUTPUT
}

void loop()
{
  int statusSensor = digitalRead (IRSensor);
  
  if (statusSensor == 1)
    digitalWrite(LED, LOW); // LED LOW
  }
  
  else
  {
    digitalWrite(LED, HIGH); // LED High
  }
  
}

3.Smoke sensor:

A smoke sensor is a device that senses smoke, typically as an indicator of fire. Commercial security devices issue a signal to a fire alarm control panel as part of a fire alarm system. While household smoke detectors, also known as smoke alarms. Generally issue a local audible or visual alarm from the detector itself or several detectors if there are multiple smoke detectors interlinked.

credit
int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
int sensorThres = 400;


//MQ-2 Gas sensor


void setup() {
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(smokeA0, INPUT);
  Serial.begin(9600);
}

void loop() 
{
  int analogSensor = analogRead(smokeA0);

  Serial.print("Pin A0: ");
  Serial.println(analogSensor);
  if (analogSensor > sensorThres)
  {
    digitalWrite(redLed, HIGH);
    digitalWrite(greenLed, LOW);
    tone(buzzer, 1000, 200);
  }
  else
  {
    digitalWrite(redLed, LOW);
    digitalWrite(greenLed, HIGH);
    noTone(buzzer);
  }
  delay(100);
}

4.Ultrasonic Sensor:

As the name indicates, ultrasonic/level sensors measure distance by using ultrasonic waves. The sensor head emits an ultrasonic wave and receives the wave reflected back from the target. ultrasonic/level sensors measure the distance to the target by measuring the time between the emission and reception.

// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;

// defines variables
long duration;
int distance;

void setup() 
{
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}

void loop() 
{
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// Calculating the distance in centi meter speed=d/t speed of sound is 340 m/s
distance= duration*0.034/2;

// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}

5.Rain sensor:

A rain sensor is one kind of switching device which is used to detect the rainfall. It works like a switch and the working principle of this sensor is, whenever there is rain, the switch will be normally closed.

cedit
const int capteur_D = 4;
const int capteur_A = A0;//to take analog value

int val_analogique;//To take the digital Value from sensor module

void setup()
{
  pinMode(capteur_D, INPUT);
  pinMode(capteur_A, INPUT);
  Serial.begin(9600);
}

void loop()
{
if(digitalRead(capteur_D) == LOW) 
  {
    Serial.println("Digital value : wet"); 
    delay(10); 
  }
else
  {
    Serial.println("Digital value : dry");
    delay(10); 
  }
val_analogique=analogRead(capteur_A); 
 Serial.print("Analog value : ");
 Serial.println(val_analogique); 
 Serial.println("");
  delay(1000);
}

6. Temperature Sensor

The temperature sensor is a device, usually an RTD (resistance temperature detector) or a thermocouple, that collects the data about temperature from a particular source and converts the data into an understandable form for a device or an observer.

#include <OneWire.h> 
#include <DallasTemperature.h>

// Data wire is plugged into pin 2 on the Arduino 
#define ONE_WIRE_BUS 2 

OneWire oneWire(ONE_WIRE_BUS); 

DallasTemperature sensors(&oneWire);
 
void setup(void) 
{ 
 
 Serial.begin(9600); 
 
 Serial.println("Dallas Temperature IC Control Library Demo"); 
 // Start up the library 
 
 sensors.begin(); 
} 

void loop(void) 
{ 

 Serial.print(" Requesting temperatures..."); 
 sensors.requestTemperatures(); // Send the command to get temperature readings 
 Serial.println("DONE"); 

 Serial.print("Temperature is: "); 
 Serial.print(sensors.getTempCByIndex(0));
 
 // Why "byIndex"?  
 // You can have more than one DS18B20 on the same bus.  
 // 0 refers to the first IC on the wire 
 
 
 delay(1000); 
} 

7.Pressure sensor:

Pressure pads are designed to detect when pressure is applied to an area, and they come in a variety of quality and accuracy. The simplest pressure pads are often the equivalent of big switches. Inside a pressure, the pad is two layers of foil separated by a layer of foam with holes in it. When the foam is squashed, the metal contacts touch through the foam and complete the circuit.

credit
const int FSR_PIN = A0; // Pin connected to FSR/resistor divider
const int LED_PIN1 = 7;
const int LED_PIN2 = 6;
const int LED_PIN3 = 4;
const float VCC = 4.98; // Measured voltage of Ardunio 5V line
const float R_DIV = 3230.0; // Measured resistance of 3.3k resistor

void setup() 
{
  Serial.begin(9600);
  pinMode(FSR_PIN, INPUT);
  pinMode(LED_PIN1, OUTPUT);
  pinMode(LED_PIN2, OUTPUT);
  pinMode(LED_PIN3, OUTPUT);
}

void loop() 
{
  int fsrADC = analogRead(FSR_PIN);
  // If the FSR has no pressure, the resistance will be
  // near infinite. So the voltage should be near 0.
  if (fsrADC != 0) // If the analog reading is non-zero
  {
    // Use ADC reading to calculate voltage:
    float fsrV = fsrADC * VCC / 1023.0;
    // Use voltage and static resistor value to 
    // calculate FSR resistance:
    float fsrR = R_DIV * (VCC / fsrV - 1.0);
    Serial.println("Resistance: " + String(fsrR) + " ohms");
    // Guesstimate force based on slopes in figure 3 of
    // FSR datasheet:
    float force;
    float fsrG = 1.0 / fsrR; // Calculate conductance
    // Break parabolic curve down into two linear slopes:
    if (fsrR <= 600) 
      force = (fsrG - 0.00075) / 0.00000032639;
    else
      force =  fsrG / 0.000000642857;
    Serial.println("Force: " + String(force) + " g");
    Serial.println();
    if(force<10)
    {
       digitalWrite(LED_PIN1,LOW);
      digitalWrite(LED_PIN2,LOW);
      digitalWrite(LED_PIN3,LOW);}
    if(force>20)
    {
      digitalWrite(LED_PIN1,HIGH);
      digitalWrite(LED_PIN2,LOW);
      digitalWrite(LED_PIN3,LOW);
     
    }
    if(force>60)
    {
      digitalWrite(LED_PIN2,HIGH);
      digitalWrite(LED_PIN1,LOW);
      digitalWrite(LED_PIN3,LOW);
    }
    if(force>100)
    {
       digitalWrite(LED_PIN3,HIGH);
      digitalWrite(LED_PIN2,LOW);
      digitalWrite(LED_PIN1,LOW);
    }
  
    delay(500);
    
  }
  else
  {
    // No pressure detected
  }
}

8.Touchsensor:

It is a simple sensor which detects the touch of the human beings.

credit
#define sensorPin 1 // capactitive touch sensor - Arduino Digital pin D1
 
int ledPin = 13; // Output display LED (on board LED) - Arduino Digital pin D13
 
void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);  
  pinMode(sensorPin, INPUT);
}
 
void loop() 
{
  int senseValue = digitalRead(sensorPin);
  if (senseValue == HIGH){
    digitalWrite(ledPin, HIGH);
    Serial.println("TOUCHED");
  }
  else{
    digitalWrite(ledPin,LOW);
    Serial.println("not touched");
  } 
  delay(500);
  
}

9.Photo resist sensor:

When the value read from the photoresistor sensor module goes below the threshold value. It becomes dark, the Arduino on-board LED is switched on. The LED is switched off when the analog value from the sensor goes above the threshold value.

int sensorPin = A0;   // select the analog input pin for the photoresistor
int threshold = 300;  // analog input trigger level from photoresistor
int sensorValue = 0;  // photoresistor value read from analog input pin

void setup() {
  pinMode(LED_BUILTIN, OUTPUT); // built-in LED, usually on pin 13
}

void loop() {
  if (analogRead(sensorPin) < threshold) {
    // low light, so switch the light (LED) on
    digitalWrite(LED_BUILTIN, HIGH);
  }
  else {
    // light level high enough, so switch the light (LED) off
    digitalWrite(LED_BUILTIN, LOW);
  }
  // wait for ADC to settle before next reading
  delay(20);
}

Creating a multiplication Skill in Alexa using python

Written By Vishal Naik

Electronics Engineering student. Interested in Python and embedded systems development . I love research and share knowledge on current technology.

RELATED POSTS

How to use simulators to build Arduino Projects

How to use simulators to build Arduino Projects

Introduction In this tutorial, let's learn how to use simulators for building Arduino projects for beginners. In addition to it, We shall learn how to configure it and how to get started with simulation tools. Here, We shall take an example of blinking an led using...

Basics of Wireless Sensor Networks, Topologies and Application

Basics of Wireless Sensor Networks, Topologies and Application

This article will learn about Wireless Sensor Networks, the need to develop WSN, Applications, and their Topologies. However, before getting into the topic, let us brush up on some basic information about the sensor. A sensor is an appliance that detects changes in...

Image Sensor and Its Types

Image Sensor and Its Types

In this post, we are going to discuss and explain the concept of Image Sensor. In the world of technology, images play an important role. We are identifying and classifying the objects with the help of Machine learning concepts. This all possible with the help of...

Sensor Technology in IoT and How it works

Sensor Technology in IoT and How it works

Senors Technology plays a key role when we use it in IoT. The sensor is a device which detects changes in an environment or measures physical property, record, indicates or respond to it. so, different types of applications require different types of sensors to data...

Arduino and its various development boards

Arduino and its various development boards

1. What is Arduino? Arduino is an open-source software and software company, project, and user community that designs and manufactures single-board microcontrollers and microcontroller kits for building digital devices....

MIT app inventor with Arduino

MIT app inventor with Arduino

MIT app inventor is a platform developed to help you expand your ideas into mobile applications that can be used throughout various devices. Arduino, as you most probably have heard of is mainly used to develop and implement many projects. When you put together the...

LiDAR: Light Detection and Ranging

LiDAR: Light Detection and Ranging

Light Detection and Ranging (LiDAR) measures distances. It uses light in the form of a pulsed laser to remotely generate measurement. In short it produces beams of laser light and measures how long it takes to return to the sensor in order to measure the distance....

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....