DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. IoT
  4. The Three-Step Process to Building With Arduino Sensors

The Three-Step Process to Building With Arduino Sensors

You can easily incorporate sensors and alerts into your projects. In this case, an Arduino, some sensors, and an alert tool will keep your home safe from gas leaks.

Francesco Azzola user avatar by
Francesco Azzola
CORE ·
Feb. 07, 17 · Tutorial
Like (1)
Save
Tweet
Share
8.10K Views

Join the DZone community and get the full member experience.

Join For Free
this post describes how to create an iot project using arduino sensors. you will learn how easy is to create an iot app that monitors gas in a room using arduino sensors and sends a notification when the gas is over a threshold. we can build a simple gas monitoring system in a few steps. first of all, we assume you are already familiar with iot projects and what iot means and how it will impact our future .

what do we need to create an iot arduino sensor project?

  • mq-4 sensor
  • arduino uno + internet shield
  • jump wirings

step 1: arduino sensor circuit

as our gas sensor, we will use an mq-4 sensor. it is a fast and reliable sensor that's very sensitive to natural gas and ch4 (methane). it has a long life and is commonly used in gas leakage detecting. what we want to do is create a simple project that shows gas concentration using two leds:

  • green led: the gas concentration is under the threshold.
  • red led: alert! the gas concentration is above the threshold.

the mq-4 arduino sensor has four pins:

  • vcc (+5v)
  • ground
  • digital output
  • analog output

we will use the analog output to check the gas concentration. the schematic is shown below:

image title

please notice that the connections to the gas sensor in the schematic above are not real, while the arduino pin used to get data from the sensor is the real one (a5).

when you turn on the gas sensor at the beginning, it could smell a bit. this is normal — do not worry. in the schematic, there are two resistors that connect the arduino digital pin and the leds. these limit the current flowing through the leds. they are 220 ohm. that’s all. you are ready now to develop the sketch to monitor the arduino sensor.

step 2: develop the arduino sketch

the sketch below describes how to implement the gas monitoring system:

int pinredled = 11;
int pingreenled = 8;
int pinsensor = a5;
int threshold = 250;
void setup() {
    pinmode(pinredled, output);
    pinmode(pingreenled, output);
    pinmode(pinsensor, input);
    serial.begin(9600);
}

void loop() {
    int analogvalue = analogread(pinsensor);
    serial.println("val: " + analogvalue);
    digitalwrite(pingreenled, high);
    if (analogvalue >= threshold) {
        digitalwrite(pingreenled, low);
        digitalwrite(pinredled, high);
    }
    else {
        digitalwrite(pinredled, low);
    }
    delay(5000);
}

the code is very simple. at the beginning, it declares the pins we will use to connect to the sensor and leds. the green led is always on while the red led turns on only when the gas concentration is over the threshold.

step 3: implement the notification

in this last step, we will implement a notification system so that when the gas concentration is over the threshold, we will get an email. to do it, this arduino sensor sketch uses ifttt . ifttt stands for if this then that . it's a powerful system that helps us connect to countless services, like social services. the first step is creating an account — if this is the first time you've used this service.

once you have your account, click on search at the top and look for the maker service. this service is made for makers that want to integrate external services with arduino or similar boards:

image title

now go to applet and create a new applet. click on the plus sign and add the service. in this case, you should add a maker service to the one we created before. click on receive a web request and configure your trigger. this is the event that triggers the notification process, in other words, as soon as ifttt receive a web request, it sends an email:

image title

create the trigger. now we have to configure the other step: the service that should be executed when the trigger is fired. click on the plus sign again (in the then part) and add the email service. you can add other services, too:

image title

add email details and confirm. at the end you, have your service configured in ifttt:

that’s all. now to trigger this event, we have to call the url as shown in the service configuration. we have to modify the arduino sketch to call the url when the analog value goes above the threshold.

conclusion

in the end, you have implemented a simple iot project in just three steps. integrating online services and arduino, you can expand your arduino and create interesting and useful iot project with a few lines of code. in this tutorial, you learned how to create an iot project that monitors an arduino sensor.


arduino Web Service LEd IoT

Published at DZone with permission of Francesco Azzola, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Quest for REST
  • API Design Patterns Review
  • A Brief Overview of the Spring Cloud Framework
  • How Observability Is Redefining Developer Roles

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: