11. Input devices

Goal(s):

  • Group assignment:
  • Probe an input device’s analog levels and digital signals

  • Individual assignment:

  • Measure something: add a sensor to a microcontroller board that you have designed and read it

Introduction

This weeks assignment is to interface a microcontroller with input devices like switches, keyboards,PIR sensors,temp & humidity sensors etc. After going through the details of the project, I was able to finalize that I wanted to use a simple temperature sensor and for the Microcontroller, I decided to use the Satshakit by Danielle Ingrassia

Signal testing

For this assignment, I initially used an Arduino Uno to test the input device analong and digital signals to a Temperature Sensor which I will be using in my Final project. I had connected both the input an output devices to the same board and measured the signals.

For measuring the signals, I was using a TekTronix Oscilloscope to understand how to analyze input and output signals.

- Temperature Sensor input at room temperature

- Varying analog signals

Microcontroller Board

Due to my limited knowledge in Electronics, I decided to use the SatshaKit by Danielle Ingrassia, mainly for the following reasons

  • It replaces the need to use Arduino board
  • It is an improvement over the FabDuino project
  • We can use the board directly with the Arduino IDE
  • We can connect both input and output to the same board for getting the results

Making the Board

As I was using Satshakit with only a single device for input and single device for output, I decided to use the Satshakit Micro and reduce the pins so that I would be able to use it purely for my project.

The input device being used was a DS18B20 Digital Temperature Sensor with only 3 wires: VCC, GND and Data, I only needed a single data pin for the temperature sensor to work correctly

The Output device being used was an i2C LCD Sensor which had only 4 output wires: VCC, GND and 2 Analog pins which needed only 2 analog outputs on the Satshakit.

As I covered in the previous Electronics design assignment, the Satshakit was made using Laser engraving and chemical etching protocol.

Final Board

The Satsahkit Micro was more than sufficient for the 2 sensors and was able to read the program and display serial output.

Done Bootloading

Done uploading Ice code to the Satshakit

Since we had to design the board over using the existing Satshakit board, I made note of the input / output pins for the sensors and remodelkled the Satshakit to include only the required pins

Codes used

Code used

#include <OneWire.h>                             //The One wire Library used
#include <DallasTemperature.h>                   //Temperature library used
OneWire  ds(2);

void setup() {
 Serial.print("Temperature....."); 

 delay(3000);

Serial.print("Starting.....");
delay(3000);
}
void loop() {
  byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
ds.reset_search();
delay(250);
return;
}
for ( i = 0; i < 8; i++) {
}
if (OneWire::crc8(addr, 7) != addr[7]) {
return;
}
                                                      // the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
type_s = 1;
break;
case 0x28:
type_s = 0;
break;
case 0x22:
type_s = 0;
break;
default:
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1);                                    // start conversion, with parasite power on at the end
delay(1000);                                          // maybe 750ms is enough, maybe not
                                                      // we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE);                                       // Read Scratchpad
for ( i = 0; i < 9; i++) {                            // we need 9 bytes
data[i] = ds.read();
}
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
                                                      // "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
                                                      // at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7;                      // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3;                 // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1;                 // 11 bit res, 375 ms
                                                      // default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
  delay(300);
  Serial.print("ICEICE BABY TEMP");
  Serial.print(celsius);
  Serial.print("C:");
  Serial.print(fahrenheit);
  Serial.print("F:");
  }                                                  // Printing the temperature to the serial monitor or LCD

Output

The Output was initially sent to serial monitor to display on screen to ensure that the module was working.

Download