11. Input devices

Highlights of the Week:

Measured Soil moisture sensor’s analog and digital signals on serial monitor and plotter.

Measured temperature and humdity using “thermocouple K” and showed data on serial monitor and plotter.

Group Assignment:

Jaydip and I chose soil moisture sensor to measure analog and digital signals. The soil moisture sensor consists of two probes that are used to measure the volumetric content of water. The two probes allow the current to pass through the soil, which gives the resistance value to measure the moisture value.

Specifications of soil moisture sensor
1. Input Voltage: 3.3–5V
2. Output Voltage: 0–4.2V
3. Output Signal: both analog and digital

Pin-out of sensor
1. VCC: Power
2. A0: Analog Output
3. D0: Digital Output
4. GND: Ground

This sensor can be connected in analog and digital modes. First, we connected it in analog mode, and then digital.

1.Analog Read:

When there is water, the soil conducted more electricity, which means that there will be less resistance. Dry soil conducts electricity poorly, so when there is less water, then the soil will conduct less electricity, which means that there will be more resistance.

A.Circuit Diagram:

  1. VCC to 5V of the Arduino
  2. GND of the sensor to GND of the Arduino
  3. A0 of the sensor to A0 of the Arduino

B.Code:

/*
  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.

  Modified by Tushar Kukreja
  Date:2nd October 

  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
}

C. Code Explaination:

Soil sensor input is at pin A0. In the setup function “Serial.begin(9600)” command will help in communcating between serial monitor and arduino. And in the loop function Serial.print() will show value on serial monitor.

D. Setup and Operation:

Three samples of different soil moisture were taken and their values were sensed by soil moisture.

E.Serial Plotter:

Values of different soil moisture were observed on the graph. After changing the sand sample the sensor took a few seconds to show the constant value.

F. Serial Monitor:

Numerical values of soil moisture approx. 185 for sample 1,340 for sample 2 and 642 for sample 3 of sand were displayed on the monitor.

2. Digital Read:

The module also contains a potentiometer, which sets the threshold value. The output LED lights up and down according to this threshold value.

A.Circuit Diagram:

  1. VCC to 5V of the Arduino
  2. GND of the sensor to GND of the Arduino
  3. D0 of the sensor to 2nd Pin of the Arduino

B. Code:

/*
  DigitalReadSerial

  Reads a digital input on pin 2, prints the result to the Serial Monitor

  This example code is in the public domain.
 Modified by Tushar Kukreja
 Date: 2nd OCtober
  http://www.arduino.cc/en/Tutorial/DigitalReadSerial
*/

// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState = digitalRead(pushButton);
  // print out the state of the button:
  Serial.println(buttonState);
  delay(1);        // delay in between reads for stability
}

C. Code Explaination:

Pin 2 of arduino has been defined as pushbutton. 1 millisecond of delay is in between reads for stability.

D. Setup and Operation:

The 3rd sample in this case has been replaced by water to give maximum conductivity. The first and second sample as same as above experiment. In the 3rd sample Blue Led lights up showing it has reached maximum vale.

E. Serial Plotter:

Digital Read gives output value only in 0 or 1. There is no inbetween value which is clearly visible on the graph.

F. Serial Monitor:

The 3rd sample of water gave value 1. First and second sample even though had certail soil moisture the output is shown 0.

Analog and Digital Code files available here.

Individual Assignment:

1. Design

A. Atmega 328p Datasheet

For selecting the microcontroller for the board I read and understood the datasheet of microcntrollers and decided to use Atmega 328p.ATmega328 microcontrollers are from the 8-bit AVR microcontroller family.

a. Pin Out diagram of Atmega 328p:
i. VCC: Digital Supply Voltage
ii. GND: Connected to Ground
iii. PC6/Reset:Pin by default is used as RESET pin. PC6 can only be used as I/O pin when RSTDISBL Fuse is programmed.
iv. AVcc:Power for Internal ADC Converter.
v.AREF:Analog reference pin for the A/D Converter
vi. Port B(PB7:0):Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability.
vii. Port C(PC5:0):Port C is a 7-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The PC5 to 0 output buffers have symmetrical drive characteristics with both high sink and source capability.
viii. Port D(PD7:0):Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port D output buffers have symmetrical drive characteristics with both high sink and source capability.

b. Memory Size: Atmega328P has “Flash” 32K type memory.
c.EEPROM:It supports a real Read-While-Write Self-Programming mechanism and 1Kbytes of electrically erasable programmable read-only memory.
d.Internal SRAM 2Kbytes Internal Static Random Access Memory (SRAM).

B.Schematic:

I chose components and connected them using “NET” and lablelled them. Parts with the same name got connected. There were no errors after ERC check and proceeded ahead.

a. Schematic of the main board:


b. Schematic of the sensor board:

C.Board:

After the DRC check saved the board files in png format.

a. Board design of the main PCB:


b. Board design of the sensor PCB:

D. rml file:

Using Fab modules converted the .png format files to .rml giving values of speed, x,y,z coordinates,name of machine, end mill size etc.

2.Fabrication

A. Took the single side FR1 board.
B. Cleaned the bed of sacrifical layer properly with Acetone. Made sure there is no dirt at all. C. Sticked double side tape on the bottom of the FR1 board and I sticked it on the sacrifical layer. D.Using the end mill 1/64 for tracing and 1/32 for cutting milled the PCB. I used the software VPanel to instruct the machine. E. Using filler, flux and the soldering rod placed and soldered all the components on the board.

3.Programming

Programmed the board to read temperature data and calculate humidity. The readings were shown on serial monitor and graph on serial plotter.

A.Code:

/********************************************************************/
// First we include the libraries
// Created by Tushar Kukreja
// Date: 16th August 
#include <OneWire.h> 
#include <DallasTemperature.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(0,1); // RX, TX
/********************************************************************/
// Data wire is plugged into pin 5 on the Arduino 
#define ONE_WIRE_BUS 5
/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices  
// (not just Maxim/Dallas temperature ICs) 
OneWire oneWire(ONE_WIRE_BUS); 
/********************************************************************/
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
/********************************************************************/ 



void setup() 
{ 

 // start serial port 
  mySerial.begin(9600);

  delay (100);

 // Start up the library 
 sensors.begin();


}

void loop() 
{ 

 // call sensors.requestTemperatures() to issue a global temperature 
 // request to all devices on the bus 
/********************************************************************/ 
sensors.requestTemperatures(); // Send the command to get temperature readings  
  float t = sensors.getTempCByIndex(0);
  mySerial.print("Temperature is: ");
  mySerial.println(t); // Why "byIndex"?
// Serial.println(sensors.getTempCByIndex(0));
   // You can have more than one DS18B20 on the same bus.  
   // 0 refers to the first IC on the wire 
  //delay(4000); 
/********************************************************************/
  float u = sensors.getTempCByIndex(1);// 
  float d = ((17.502*t)/(240.97+t)); // Equation for Humidity
  float e = 2.7183;
  float g = 6.112*(pow(e,d));
  float j = ((17.502*u)/(240.97+u));
  float k = 2.7183;
  float m = 6.112*(pow(k,j));
  float n = (m-(0.6687*(1+0.00115*u)*(t-u)))/g*100; //Humidity upto 2 digit

mySerial.print("Humidity is: ");
 mySerial.println(n); // Why "byIndex"?
 mySerial.println("Hello, world?");

}

B. Code Explaination:

a.To compile the programme there are 3 libraries to be included-One wire, Dallas Temperature and Software serial.
b.For serial monitor to show tmperature and humidity data connected with Recieve(RX) and Transimt(TX) serial data.
c.One_wire_bus is the connection for the data pin in 5 of arduino.
d.The communication will be at baud rate 9600.
e.MySerial.print() will print the data on serial monitor.
f.Float t is the dry bulb temperature.
g.Float n is the calculated relative humidity using

C. Uploading Programme: Connected the sensors thermocouple K to the sensor board. Further attached the sensor board to the main board and programmed it using Fab ISP.

D. Serial Monitor: The video shows the entire setup where temperature and humidity readings are shown on serial monitor every second.

Input device Code files available here.
Design files of sensor board available here.
Design files of main board available here.