We are the MAKERS

Fab Academy 2017






Input Devices




Tasks:





During the Output Devices week I designed a board which will be the basis of my Final Project board. But after using it for a while, I realized that there is a big room for improvement!

There are many things missing, many features I would still like to add, and of course the goal is to practise more on making PCB Boards

This week I want to integrate Input Devices together with the Output Devices


To design the board, I took as a reference the satshakit from Daniele Ingrassia.

satshakit is a 100% Arduino IDE and libraries compatible, fabbable and open source board, and also an improved version of Fabkit.


Main improvements and features over Fabkit are:


The same as last week, my #1 Guide for making the PCB was the ATmega328p pinout


The software which I will be using for the board design is

EAGLE (Easily Applicable Graphical Layout Editor) is a flexible and expandable EDA schematic capture, PCB layout, autorouter and CAM program. EAGLE is popular among hobbyists because of its freeware license and rich availability of component libraries on the web.

Eagle has two windows that are used simultaneously to design a board:


After I installed EAGLE, the first thing which I want to do is Create a New Schematic. A schematic in electronics is a drawing representing a circuit. It uses symbols to represent real-world electronic components. The most basic symbol is a simple conductor (traces), shown simply as a line. If wires connect in a diagram, they are shown with a dot at the intersection.

In order to place my components on the schematics, I have to download and use special Libraries. Eagle has a lot of built in libraries of components that we can use. The fab network also maintains a library which is constantly updated:


fab.lbr


In order to install the library, in the EAGLE environment, go to the top toolbar and select the Library menu. Then select use and open the .lbr file that I just downloaded.

Now I can go to Add component and selecting the library, I choose the component which I want to place.


Here is the list of components that I used:


This is how the final schematics looks:



Some of the new improvements which I added are the direct connection for the FTDI cable, the AVRISP, I also added the connection for the two input devices that I am going to use (DHT11 - Humidity & Temperature Sensor and DS18B20 - One Wire Digital Temperature Sensor)




I also added the LDR Photocell and mounted it directly on the board. Maybe this is not the best idea to place it on the board, but I decided to give it a try!)




To control the output devices, I added the N-Channel MOSFET circuit. I made one input connector for the external power supply, which will power the 3 output sources.




The board layout after I routed all the connections:




I am using the trick of making a polygon around the circuit and name it as GND. One important thing here is the isolation. I have to make sure that the isolation is going inside everywhere and leaves no "islands"



When I double check everything, I can Export my file as a .png picture.

In the appearing window, I increase the resolution to 1500 dpi, click on monochrome, and select window mode.



To edit the .png image, I will be using I open my image in GIMP, and using the rectangular select tool, I select the image leaving some space from all the sides. After I press File and Copy the selected area. To continue working with the selected picture, I click again on File, and Create from the Clipboard


More detailed procedures can be found in my previous documentation Electronics Design week!


At the output I have two .png files which I called inside_cut.png and the outside_cut.png.


       


Now I can proceed to the CNC milling machine. So, again I used FabModules to convert the .PNG files into Gcodes for the Roland machine.

Let’s start to work with the Fab Modules. When I introduce the ip adress into the browser window, the first interface that will appear is:



After I press on th gray button input format, a new menu should appear with the option to load the .PNG image. Here I upload the first image, which is the inside engraving. After doing that, the preview of the image will appear in the Fab Modules and also other fields and other parameters will show up

On the right side of the window, we have many input parameters. In order to be able to move the machine, we have to input the following parameters:




    mod_lp.py /dev/usb/lp0     into the send command field


    hostname_of_your_machine     into the server field (just the address without http or /)



In order to move the machine I just enter in the respective fields the x, y and z position coordinates. Before moving the machine I have to make sure that the zjog parameter is always set to 0, even if it will change automatically. To move the machine I have to press the move to xyz0 button.

* A small life hack while adjusting the z0 axis, is to use the multimeter and check if there is connection between the tool and the surface.



The tool for engraving the PCB is suggested to use diameter from 0.2 mm and below, while for cutting we can use a 1 mm tool.



These are the settings which I used in the fabmodules for the inside cut:



And the outside cut:



And the result was really great! This is my final PCB Board:


       




To program my board I used Arduino IDE. I connect the arduino board to the USB hub, in the tools menu select the right board (Arduino Uno/Genuino) and the port, after go to File--> examplesand open the Arduino as ISP sketch. Upload the code.



After I see done uploading, which means that the code is uploaded to the board, I disconnect the arduino from the PC. The next step is to connect my PCB board to Arduino using some wires. The connection scheme is this one:



I connect the arduino board to the USB hub. Under Tools select the right board, select Arduino as ISP programmer, double check the parameters, and press the Burn Bootloader button.



And I see Done Uploading! Good sign)

To test the board, I decided to upload a sketch code for the LDR, to see if the FTDI is uploading the code, the check if the LDR is functioning, and also make sure that the Serial Communication takes place! A nice test, isn't it?)



/* Photocell simple testing sketch. */

int photocellPin = 0;     // the cell and 10K pulldown are connected to A0
int photocellReading;     // the analog reading from the analog resistor divider

void setup(void) {
  
  Serial.begin(9600);   // We'll send debugging information via the Serial monitor
}
 
void loop(void) {
  photocellReading = analogRead(photocellPin);  
 
  Serial.print("Analog reading = ");
  Serial.print(photocellReading);     // the raw analog reading
  
    delay(1000);
}



And Voilaaa! It's working

Now I would like to test the output connections. To the power supply, I will attach a 9V battery, and for the output device I will use a DC Motor. I want to control the speed of the motor using the serial monitor. This is the sketch that I use:


        
int motorPin = 10;
 
void setup() 
{ 
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
  while (! Serial);
  Serial.println("Speed 0 to 255");
} 
 
 
void loop() 
{ 
  if (Serial.available())
  {
    int speed = Serial.parseInt();
    if (speed >= 0 && speed <= 255)
    {
      analogWrite(motorPin, speed);
    }
  }
} 




When I am sure that the board is working properly, I can attach and program some sensors to it.


First sensor that I want to use is DHT11 - Temperature & Humidity Sensor



These sensors are very basic and slow, but are great for hobbyists who want to do some basic data logging. The DHT sensors are made of two parts, a capacitive humidity sensor and a thermistor. There is also a very basic chip inside that does some analog to digital conversion and spits out a digital signal with the temperature and humidity. The digital signal is fairly easy to read using any microcontroller.


Some characteristics:


The wiring is pretty easy, just VCC, GND, and any Digital Pin! In my case, I designed in advance the connection for this sensor.

To test it, I will upload a simple sketch. The sketch includes the library DHT.h

So here is the code:

        
// DHT11 Temperature and Humidity Sensors Example

#include "DHT.h"         //include DHT library

#define DHTPIN 3         //define as DHTPIN the Pin 3 used to connect the Sensor
#define DHTTYPE DHT11    //define the sensor used(DHT11)

DHT dht(DHTPIN, DHTTYPE); //create an instance of DHT

void setup() {
  Serial.begin(9600);    //initialize the Serial communication

  dht.begin();           //initialize the Serial communication
}

void loop() {
 
  float h = dht.readHumidity();    // reading Humidity 
  float t = dht.readTemperature(); // read Temperature as Celsius (the default)
  
  Serial.print(t, 2);    //print the temperature
  Serial.print("\t");
  Serial.println(h, 2);  //print the humidity
  delay(2000);           //wait 2 seconds
}



Another sensor which I want to use is DS18B20 - One Wire Digital Temperature Sensor



DS18B20 is 1-Wire digital temperature sensor from Maxim IC. Reports degrees in Celsius with 9 to 12-bit precision, from -55 to 125 (+/-0.5). Each sensor has a unique 64-Bit Serial number etched into it - allows for a huge number of sensors to be used on one data bus.

This is by far one of the most simple digital sensors to hookup. Aside from power and ground, it has a single digital signal pin that I will be connecting to digital pin which I designed in advance. It also requires a 4.7k pull-up resistor between the signal and power pin, which unfortunately I forgot to place on my PCB. That is why, I will solder it manually directly to the sensor cables.

Before I start, I have to download the libraries: OneWire.h and DallasTemperature.h


Upload the following sketch:


// First we include the libraries
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2 

// 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(void) 
{ 
 // start serial port 
 Serial.begin(9600); 
 sensors.begin(); 
} 


void loop(void) 
{ 
 // call sensors.requestTemperatures() to issue a global temperature (request to all devices on the bus)
sensors.requestTemperatures(); // Send the command to get temperature readings 

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



Last but not least, LDR = Light Dependent Resistor



LDR is a passive electronic component, basically a resistor which has a resistance that varies depending of the light intensity. The resistance is very high in darkness, almost high as 1MΩ but when there is light that falls on the LDR, the resistance is falling down to a few KΩ (10-20kΩ @ 10 lux, 2-4kOmega; @ 100 lux) depending on the model.

The LDR gives out an analog voltage when connected to Vcc (5V), which varies in magnitude in direct proportion to the input light intensity on it. That is, the greater the intensity of light, the greater the corresponding voltage from the LDR will be. Since the LDR gives out an analog voltage, it is connected to the analog input pin on the Arduino. The Arduino, with its built-in ADC (Analog to Digital Converter), then converts the analog voltage (from 0-5V) into a digital value in the range of (0-1023). When there is sufficient light in its environment or on its surface, the converted digital values read from the LDR through the Arduino will be in the range of 800-1023.


Because I already tested the LDR before, I would like to integrate all the sensors together, and come up with a final piece of code.

This is how it looks:


/*-----( Import needed libraries )-----*/
#include <DallasTemperature.h>
#include <OneWire.h>
#include <dht.h>

/*-----( Declare Constants )-----*/
#define DHT11_PIN 2
#define ONE_WIRE_BUS 3

int sensorPin = A0; /*  select the input pin for LDR */
int sensorValue = 0; /*  variable to store the value coming from the sensor */

OneWire ourWire(ONE_WIRE_BUS);   /* Set up a oneWire instance to communicate with any OneWire device*/
DallasTemperature sensors(&ourWire);   /* Tell Dallas Temperature Library to use oneWire Library */

dht DHT;

void setup(){
  Serial.begin(9600);   /*-(start serial port to see results )-*/

  sensors.begin();   /*-( Start up the DallasTemperature library )-*/
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);

sensorValue = analogRead(sensorPin); // read the value from the sensor

sensors.requestTemperatures(); // Send the command to get temperatures
  
 
  Serial.print("Air Temperature = ");
  Serial.print(DHT.temperature);
  Serial.print("C");
  Serial.print("\t");
  Serial.print("Air Humidity = ");
  Serial.print(DHT.humidity);
  Serial.print("%");
  Serial.print("\t\t");


  Serial.print("Water Temperature = ");
  Serial.print(sensors.getTempCByIndex(0));
  Serial.print("C");
  Serial.print("\t");



 // We'll have a few threshholds, qualitatively determined
  Serial.print("LDR Value = ");
  Serial.print(sensorValue);
  if (sensorValue < 100) {
    Serial.println(" (Dark)");
  } else if (sensorValue < 200) {
    Serial.println(" (Dim)");
  } else if (sensorValue < 500) {
    Serial.println(" (Light)");
  } else if (sensorValue < 800) {
    Serial.println(" (Bright)");
  } else {
    Serial.println(" (Very bright)");
  }

   delay(3000);
}







Download Files:


Inside Cut (.png)

Outside Cut (.png)

Eagle schematics (.sch)

Eagle board layout (.brd)

Arduino Code (final sketch)











© 2017 Albot Dima . All rights reserved | Albot.Dumitru@hsrw.org

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.