Sensing

From Interaction Station Wiki
Revision as of 01:23, 13 May 2019 by Oyo (Talk | contribs) (Temperature and humidity)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

what is the Arduino

Hello everyone hello hello hello,

now what is an Arduino ...well...find a detailed introduction here [[1]]
Computer and processor are generic terms for the anything that can run a program, basically.
Controller or microcontroller usually refers to a simple processor that does only one task, like listening to sensors. In explaining microcontrollers, we’ll distinguish them from computers, which contain more powerful processors that can run an operating system.
Arduino is an open source physical computing platform based on a simple input/output (I/O) board and a development environment that implements the Processing language. Arduino can be used to develop standalone interactive objects or can be connected to software on your computer.
The Arduino contains a microcontroller.
Most electronic devices today have a microcontroller at their core. Microcontrollers are optimized for control of general input and output. What Is Physical Computing? Physical Computing uses electronics to prototype new materials for ( in our case ) designers and artists.
Arduino is composed of two major parts: the Arduino board, which is the piece of hardware you work on when you build your objects; and the Arduino IDE, the piece of software you run on your computer. You use the IDE to create a sketch (a little computer program) that you upload to the Arduino board. The sketch tells the board what to do.

In the meantime, HERE you can find ANYTHING about Arduino, including download the software

NOW,
The pins on your Arduino are the places where you connect wires to construct a circuit (probably in conjunction with a breadboard and some wire. They usually have black plastic ‘headers’ that allow you to just plug a wire right into the board. The Arduino has several different kinds of pins, each of which is labeled on the board and used for different functions.
Arduino-uno.png



First things first

we start by figuring put if our Arduino is all good or it is somehow damaged ...it is a basic test to check and run a simple script at the same time.

Go to File ---> Examples ---> Basics --->Blink

so we have something like this

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://www.arduino.cc
 
  This example code is in the public domain.
 
  modified 8 May 2014
  by Scott Fitzgerald
 */
 
 
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}
 
// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

GOOOD! lets dissect this

  • commenting / one line and multiple lines
  • setup
  • loop

Choose board

Board.png

Choose port

Port.png


Lets compile this

--- Press/ Click upper most left button, looks like a Tick. Observe the messages appearing in the bottom of the Arduino software window ( there must be a sentence Done Compiling
Compile.png


Lets upload this

Upload.png

And we should have a Blinking aka Flashing on board LED


Arduino-LED-Overview.jpg

Inputs and Outputs

Like mentioned earlier - μControllers are optimized for control of general input and output. What are those two exactly.


Analog ( we have six of them in the Uno): The area of pins under the ‘Analog In’ label (A0 through A5 on the UNO) are Analog In pins. These pins can read the signal from an analog sensor (like a temperature sensor) and convert it into a digital value that we can read.
Digital (seven on the Uno): Across from the analog pins are the digital pins (0 through 13 on the UNO). These pins can be used for both digital input (like telling if a button is pushed) and digital output (like powering an LED).


Sensors

Analog-or-digital-signal.png

Digital Sensors


Digital sensors are the sensors that gives 2 state (on/off, 5V/0V). You will connect them to digital Pins and set them as INPUT.
Digital data consists exclusively of 0s and 1s .
For example, consider a push button switch. This is one of the simplest forms of sensors. It has two discrete values. It is on, or it is off. Other 'discrete' sensors might provide you with a binary value.
Another example of a digital sensor is an accelerometer, which sends a series of data points (speed, direction, and so on) to the Arduino. Usually digital sensors need a chip in the sensor to interpret the physical data.

Analog Sensors


Analog sensors on the other hand, gives range. You connect this types of Analog sensors to Analog Input pins which is measuring the incoming voltage between 0V-5V*. Arduino converts this incoming voltage into the number between 0-1023.
Analog data is transmitted as a continuous signal, almost like a wave. In other words, an analog sensor doesn’t send a burst of 1s and 0s like digital sensors do; instead, the sensor modulates a continuous signal to transmit data.
Microcontrollers are capable of detecting binary signals: is the button pressed or not? These are digital signals. When a microcontroller is powered from five volts, it understands zero volts (0V) as a binary 0 and a five volts (5V) as a binary 1. The world however is not so simple and likes to use shades of gray. What if the signal is 2.72V? Is that a zero or a one? We often need to measure signals that vary; these are called analog signals. A 5V analog sensor may output 0.01V or 4.99V or anything inbetween. Luckily, nearly all microcontrollers have a device built into them that allows us to convert these voltages into values that we can use in a program to make a decision.
An Analog to Digital Converter (ADC) is a very useful feature that converts an analog voltage on a pin to a digital number. By converting from the analog world to the digital world, we can begin to use electronics to interface to the analog world around us.
Not every pin on a microcontroller has the ability to do analog to digital conversions. On the Arduino board, these pins have an ‘A’ in front of their label (A0 through A5) to indicate these pins can read analog voltages.
ADCs can vary greatly between microcontroller. The ADC on the Arduino is a 10-bit ADC meaning it has the ability to detect 1,024 (210) discrete analog levels. Some microcontrollers have 8-bit ADCs (28 = 256 discrete levels) and some have 16-bit ADCs (216 = 65,536 discrete levels).

The knob example (hello world)

Analogreadserial.png

Good read to go in detail about voltage dividers HERE

 
/*
  AnalogReadSerial
 
  Reads an analog input on pin 0, prints the result to the Serial Monitor.
  Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 
  This example code is in the public domain.
 
  http://www.arduino.cc/en/Tutorial/AnalogReadSerial
*/
 
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}
 
// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}

Portable Sensing boxes

First things...the breadboard

A new thing......Breadboarding

OK, first, what's with the name....bread board? Bread, like in food? Well yes, kind of.
Breadboard.jpg

This terminology goes way back in the days. Generally, you would mount electronic components to a piece of wood (the actual "breadboard"), and do all the wiring with point-point wire and the components just hanging between the various devices.

Breadboardreal.jpg

The story goes that an engineer had an idea for a vacuum tube device late one night. Looking around the house, the only base for his prototype that he found was indeed his wife's breadboard, from the breadbox.

A video by the Make magazine people

Ok, but why do we need to breadboard?
Well, they are useful for making temporary circuits and prototyping, and they require absolutely no soldering.
Prototyping is the process of testing out an idea by creating a preliminary model from which other forms are developed or copied, and it is one of the most common uses for breadboards.
The best way to explain how a breadboard works is to take it apart and see what’s inside. Breadboard02.jpg

connections lines are connected like this
Breadboard03.jpg



Oled display


Grove - OLED Display 0.96" module is an OLED monochrome 128×64dot matrix display module with Grove 4pin I2C Interface.Comparing to LCD, OLED screens are more competitive, which has a number of advantages such as high brightness, self-emission, high contrast ratio, slim / thin outline, wide viewing angle, wide temperature range, and low power consumption.


Seeeduino Grove - OLED Display 0.96 inch
5V --> Red
GND --> Black
SDA --> White
SCL --> Yellow


OledWiring.PNG


Next step we will install the Oled Grove library.
Go to the menu Sketch---> Include library----> Library manager
In the newly appeared window, there is a search bar. In it type Oled grove and install the appearing library.


Now, we will see how the oled display works, buy opening the Hello World example


#include <Wire.h>
#include <SeeedOLED.h>
 
 
void setup()
{
  Wire.begin();
  SeeedOled.init();  //initialze SEEED OLED display
 
  SeeedOled.clearDisplay();          //clear the screen and set start position to top left corner
  SeeedOled.setNormalDisplay();      //Set display to normal mode (i.e non-inverse mode)
  SeeedOled.setPageMode();           //Set addressing mode to Page Mode
  SeeedOled.setTextXY(0,0);          //Set the cursor to Xth Page, Yth Column  
  SeeedOled.putString("Hello World!"); //Print the String
 
}
 
void loop()
{
 
}

Moisture sensor


Moisturesensor.jpg


This Moisture Senor can be used for detecting the moisture of soil or judge if there is water around the sensor. It is a soil moisture sensor based on soil resistance measurement.

It is an analog sensor and we will connect the YELLOW wire to pin A0 of the Arduino uno.
The BLACK goes to GND
and the RED goest to 5V


Moitsturewiring.PNG

#include <Wire.h>
#include <SeeedOLED.h>
 
void setup(){
 
  Serial.begin(9600);
  Wire.begin();                 //initialize I2C in master mode
  SeeedOled.init();             //initialize the OLED
  SeeedOled.clearDisplay();     //clear the screen and set start position to top left corner
  SeeedOled.setNormalDisplay(); //Set display to normal mode (i.e non-inverse mode)
  SeeedOled.setPageMode();      //Set addressing mode to Page Mode
}
 
void loop(){  
 
  float sensorValue;  
  sensorValue = analogRead(0);                        //connect the Moisture sensor to Analog 0   
 
 
  Serial.println(sensorValue); //here we will be able to see the sensor value in the Serial monitor
  SeeedOled.setTextXY(1, 0); 
  SeeedOled.putString("Sensing");
  SeeedOled.setTextXY(3, 0);
  SeeedOled.putString("Soil Moisture:");
  SeeedOled.setTextXY(5, 0);
  SeeedOled.putFloat(sensorValue);  
 
}

Light Intensisty sensor

The light intensity sensor is very similar to the moisture sensor, only it changes ists resistance according to the amount of light that falls onto the LDR.
We basically are doing this, but instead on the breadboard we have it wired to a connector.
Arduinolrd.jpg


It is an analog sensor and we will connect the YELLOW wire to pin A0 of the Arduino uno.
The BLACK goes to GND
and the RED goest to 5V


#include <Wire.h>
#include <SeeedOLED.h>
 
void setup(){
 
  Serial.begin(9600);
  Wire.begin();                 //initialize I2C in master mode
  SeeedOled.init();             //initialize the OLED
  SeeedOled.clearDisplay();     //clear the screen and set start position to top left corner
  SeeedOled.setNormalDisplay(); //Set display to normal mode (i.e non-inverse mode)
  SeeedOled.setPageMode();      //Set addressing mode to Page Mode
}
 
void loop(){  
 
 
  float sensorValue; 
  sensorValue = analogRead(0);                        //connect light sensor sensor to Analog 0   
 
  Serial.println(sensorValue);
  SeeedOled.setTextXY(1, 0);
  SeeedOled.putString("Sensing");
  SeeedOled.setTextXY(3, 0);
  SeeedOled.putString("Light Intensity:");
  SeeedOled.setTextXY(5, 0);
  SeeedOled.putFloat(sensorValue);  
 
 
}

UV sensor


UvSensor.jpg

The Grove – UV Sensor is used for detecting the intensity of incident ultraviolet(UV) radiation. This form of electromagnetic radiation has shorter wavelengths than visible radiation. The Grove - UV Sensor is based on the sensor GUVA-S12D which has a wide spectral range of 200nm-400nm.

It is an analog sensor and we will connect the YELLOW wire to pin A0 of the Arduino uno.
The BLACK goes to GND
and the RED goest to 5V

Standard-UV-Index-vs-Sensor-Modules-Output-Voltage.jpg
(* World Health Organisation Classification / Standard UV Index vs Sensor Module’s Output Voltage
UVchart.jpg

#include <Wire.h>
#include <SeeedOLED.h>
 
void setup(){
 
  Serial.begin(9600);
  Wire.begin();                 //initialize I2C in master mode
  SeeedOled.init();             //initialize the OLED
  SeeedOled.clearDisplay();     //clear the screen and set start position to top left corner
  SeeedOled.setNormalDisplay(); //Set display to normal mode (i.e non-inverse mode)
  SeeedOled.setPageMode();      //Set addressing mode to Page Mode
}
 
void loop(){  
 
  // String UVIndex = "0";
  int sensorValue = 0;
  float UVIndex = 0.0;
  sensorValue = analogRead(0);                        //connect UV sensor to Analog 0   
  int voltage = (sensorValue * (5.0 / 1023.0))*1000;  //Voltage in miliVolts
 
  if(voltage<50)
  {
    UVIndex = 0.0;
  }
  else if (voltage>50 && voltage<=227)
  {
    UVIndex = 0.0;
  }
  else if (voltage>227 && voltage<=318)
  {
    UVIndex = 1.0;
  }
  else if (voltage>318 && voltage<=408)
  {
    UVIndex = 2.0;
  }
  else if (voltage>408 && voltage<=503)
  {
    UVIndex = 3.0;
  }
  else if (voltage>503 && voltage<=606)
  {
    UVIndex = 4.0;
  }
  else if (voltage>606 && voltage<=696)
  {
    UVIndex = 5.0;
  }
  else if (voltage>696 && voltage<=795)
  {
    UVIndex = 6.0;
  }
  else if (voltage>795 && voltage<=881)
  {
    UVIndex = 7.0;
  }
  else if (voltage>881 && voltage<=976)
  {
    UVIndex = 8.0;
  }
  else if (voltage>976 && voltage<=1079)
  {
    UVIndex = 9.0;
  }
  else if (voltage>1079 && voltage<=1170)
  {
    UVIndex = 10.0;
  }
  else if (voltage>1170)
  {
    UVIndex = 11.0;
  }
 
 
  Serial.println(voltage); //here we print the voltage the sensor ourputs in the Serial monitor
  SeeedOled.setTextXY(1, 0);
  SeeedOled.putString("Sensing");
  SeeedOled.setTextXY(3, 0);
  SeeedOled.putString("UV index:");
  SeeedOled.setTextXY(5, 0);
  SeeedOled.putFloat(UVIndex);  //print the UV index according to the voltage measured
 
 
}

Temperature and humidity


Grove-temperature-humidity-sensor.jpg
This Temperature&Humidity sensor provides a pre-calibrated digital output. A capacitive sensor element measures relative humidity and the temperature is measured by a negative temperature coefficient (NTC) thermistor. It has excellent reliability and long term stability. Please note that this sensor will not work for temperatures below 0 degree.
It is the only digital sensor we will be using


It is a digital sensor and we will connect the YELLOW wire to digital 2 pin of the Arduino uno.
The BLACK goes to GND
and the RED goest to 5V

We will have to install the Grove Temperature And Humidity Sensor library by Seeed studio and launch the DHT tester example.

And then, after we have tested the sensor, we will use the code for the sensor box


#include <DHT.h>
#include <Wire.h>
#include <SeeedOLED.h>
 
#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);
 
void setup() {
 
  Wire.begin();                 //initialize I2C in master mode
  SeeedOled.init();             //initialize the OLED
  SeeedOled.clearDisplay();     //clear the screen and set start position to top left corner
  SeeedOled.setNormalDisplay(); //Set display to normal mode (i.e non-inverse mode)
  SeeedOled.setPageMode();      //Set addressing mode to Page Mode
}
 
void loop() {
  float temp, hum;
 
  //Read temperature and humidity
  do {
    hum = dht.readHumidity();
    temp = dht.readTemperature();
  }
  while (isnan(temp) || isnan(hum));
 
  //Print temperature and humidity values on the OLED display
  SeeedOled.setTextXY(0, 0);
  SeeedOled.putString("Temperature:");
  SeeedOled.setTextXY(1, 0);
  SeeedOled.putString(String(temp).c_str());  //print temperature data converted to a c string
  SeeedOled.putString("C");
  SeeedOled.setTextXY(3, 0);
  SeeedOled.putString("Humidity:");
  SeeedOled.setTextXY(4, 0);
  SeeedOled.putString(String(hum).c_str());   //print humidity data converted to a c string
  SeeedOled.putString("%");
 
  delay(2000);
}

Air Quality


This sensor is designed for comprehensive monitor over indoor air condition. It's responsive to a wide scope of harmful gases, as carbon monoxide, alcohol, acetone, thinner, formaldehyde and so on. Due to the measuring mechanism, this sensor can't output specific data to describe target gases' concentrations quantitatively.

Grove-Air-Quality-Sensor.jpg


It is an analog sensor and we will connect the YELLOW wire to pin A0 of the Arduino uno.
The BLACK goes to GND
and the RED goest to 5V

/*
 * Grove_Air_Quality_Sensor.ino
 * Demo for Grove - Air Quality Sensor.
 *
 * Copyright (c) 2019 seeed technology inc.
 * Author    : Lets Blu
 * Created Time : Jan 2019
 * Modified Time:
 *
 * The MIT License (MIT)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#include "Air_Quality_Sensor.h"
#include <Wire.h>
#include <SeeedOLED.h>
 
AirQualitySensor sensor(A0);
 
void setup() {
 
  Serial.begin(9600);
  Wire.begin();                 //initialize I2C in master mode
  SeeedOled.init();             //initialize the OLED
  SeeedOled.clearDisplay();     //clear the screen and set start position to top left corner
  SeeedOled.setNormalDisplay(); //Set display to normal mode (i.e non-inverse mode)
  SeeedOled.setPageMode();      //Set addressing mode to Page Mode
 
  Serial.begin(9600);
  while (!Serial);
  SeeedOled.setTextXY(2, 0);
  SeeedOled.putString("Waiting sensor");
  SeeedOled.setTextXY(3, 0);
  SeeedOled.putString("to init...");
  delay(20000);
 
  if (sensor.init()) {
 
    SeeedOled.clearDisplay();     //clear the screen and set start position to top left corner
    Serial.println("Sensor ready.");
    SeeedOled.setTextXY(2, 0);
    SeeedOled.putString("Sensor ready.");
    delay(1000);
    SeeedOled.clearDisplay();     //clear the screen and set start position to top left corner
 
  }
  else {
    Serial.println("Sensor ERROR!");
  }
}
 
void loop(void) {
  int quality = sensor.slope();
  SeeedOled.setTextXY(1, 0);
  SeeedOled.putString("Sensing");
  SeeedOled.setTextXY(2, 0);
  SeeedOled.putString("Air Quality:");
  Serial.print("Sensor value: ");
  Serial.println(sensor.getValue());
 
  if (quality == AirQualitySensor::FORCE_SIGNAL) {
    SeeedOled.setTextXY(4, 0);
    SeeedOled.putString("High pollution! Force signal active.");
  }
  else if (quality == AirQualitySensor::HIGH_POLLUTION) {
    SeeedOled.setTextXY(4, 0);
    SeeedOled.putString("High pollution!");
  }
  else if (quality == AirQualitySensor::LOW_POLLUTION) {
    SeeedOled.setTextXY(4, 0);
    SeeedOled.putString("Low pollution!");
  }
  else if (quality == AirQualitySensor::FRESH_AIR) {
    SeeedOled.setTextXY(4, 0);
    SeeedOled.putString("Fresh air.");
  }
 
  delay(500);
}