For the first in-put device project, I chosen the photoresistor component.
I create the schematic on Eagle software.

Photoresistor schematic project.

Photoresistor board design project.



I made the png file and milled it.

Engraving board's file.

Cut board's file.



Milling photoresistor board.



After that, I wired all components on the board.


Welding components.



I check all components, welds and connection. About this, I saw an error in the wiring diagram, I didn’t connect the photoresistor to microcontroller! Because I connected isp pin and serial port pin, so I finished all pin available.

Anyway, I cut one track (the Rx connection to PB4 pin) on my board and soldering one photoresistor pin with PB4 pin.

Manual modification.

Zoom of manual modification.



Also I inverted the Serial pin, because I didn’t connect the Tx board with Rx FTDI board.

New connection between FTDI and photoresistor board.

I wrote the code on Arduino IDE. I tried many times, after some attempt, I understood that I couldn’t use the Arduino Serial Port.

Serial port error on Arduino IDE.

So I use the Software Serial library, which allows to choose the Rx and Tx pins. But nevertheless it not worked well, because this library has 2 component Rx and Tx, instead I have only Tx component. Therefore I research online and I found one library modified that has only one component. But when I opened the Serial port I saw strange character, like this “€€€€€€€€€€€€€€”. I tried to increase the baud rate, but it was not chance.

Baud rate error.



I tried to decrease the baud rate, but I didn’t have any good reaction. This because I didn’t to change the fuse, so the microcontroller worked to 1mhz, and I change the baud rate in 1200.

I had to change the photoresistor pin from 4 to A2, because I must use the analogic pin, not digital one, this because the serial port wrote the values only between 1 to 3.

Here you can see my code.

/* This is the program of my photoresistor input device board.
I used one library modified "SendOnlySoftwareSerial.h", that don't use the Rx port.
*/

#include 

// Definitions
// #define rxPin -1   // I don't have Rx pin on my board
#define txPin 3   // My Tx pin is on PB3 port

SendOnlySoftwareSerial mySerial(txPin); // Configure Serial Port

  int sensorPin = A2; // Phototransistor pin
  int sensorVal; // Store value from photoresistor (0-1023)


// the setup routine runs once when you press reset:
void setup() {   
 mySerial.begin(9600);             
 pinMode(sensorPin, INPUT);
}

// the loop routine runs over and over asensorpingain forever:
void loop() {

  sensorVal = analogRead(sensorPin); 
  
  mySerial.print("Input Val: ");
  mySerial.print(sensorVal);

  mySerial.println();

  delay(100);
}


Finally, I have decided to change the position of photoresistor, because I saw that it worked, but have some interference, maybe for its positioning.

I soldered it behind the board, in this way it not have some interference with the other components, and now it works well!

Here you can see the photoresistor test video.

Photoresitor board test from Mario Fullone on Vimeo.



Ultrasonic sensor board

I use a different ultrasonic sensor compared to ultrasonic used by Neil. I used un Ping sensor of Parallax, PING))) 28015 rev b.

This one has only one pin signal, doesn’t have one pin for trigger and another one for echo, but only one for both signal.

In the first time, when I made the circuit diagram, I change the connection between to Tx and Rx. I connected the Tx of my board to Rx of FTDI.

New FTDI connection scheme.



Furthermore, considering that there isn’t the ultrasonic element on Eagle, I added 3 free pin on my board. But I choose to add 2+1 pin, because I needed of space between 2 pin for to get us through a track.

Ultrasonic schematic project.

Particular pad board design project.



This is the schematic of my little board.

Board design project.



I created the usual 2 png files.

Engraving board's file.

Cut board's file.



I milled the board and soldered all component. I choose to solder the pin of ultrasonic sensor behind to board, so that any component would has disturbed the ultrasonic sensor.

Milling ultrasonic board.

Welding components.

Ultrasonic, my new board and FTDI connected.



Then I took the original Neil code, but I had to change it, for my different sensor. I used for the trigger and echo pins the same pin, that is PB4 pin. But I had to change the direction of pin after the trigger function, and after to read the signal. You can see the changes and additions that I have made on my code because I highlighted them with comments like (ADDED BY ME) or (MODIFIED).

//
// hello.HC-SR04.c
//
// HC-SR04 sonar hello-world
//    9600 baud FTDI interface
//
// Neil Gershenfeld 11/15/15
// (c) Massachusetts Institute of Technology 2015
//
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose. Copyright is
// retained and must be preserved. The work is provided
// as is; no warranty is provided, and users accept all 
// liability.
//

#include 
#include 


#define input(directions,pin) (directions &= (~pin)) // set port direction for input (ADDED BY ME)

#define output(directions,pin) (directions |= pin) // set port direction for output
#define set(port,pin) (port |= pin) // set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define bit_delay_time 102 // bit delay for 9600 with overhead
#define bit_delay() _delay_us(bit_delay_time) // RS232 bit delay
#define half_bit_delay() _delay_us(bit_delay_time/2) // RS232 half bit delay
#define char_delay() _delay_ms(10) // char delay

#define serial_port PORTB
#define serial_direction DDRB
#define serial_pin_out (1 << PB3) // MODIFIED
#define trigger_port PORTB
#define trigger_direction DDRB
#define trigger_pin (1 << PB4) // MODIFIED
#define echo_port PORTB // (ADDED BY ME)
#define echo_pins PINB
#define echo_direction DDRB
#define echo_pin (1 << PB4)

#define timeout 255

void put_char(volatile unsigned char *port, unsigned char pin, char txchar) {
   //
   // send character in txchar on port pin
   //    assumes line driver (inverts bits)
   //
   // start bit
   //
   clear(*port,pin);
   bit_delay();
   //
   // unrolled loop to write data bits
   //
   if bit_test(txchar,0)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,1)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,2)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,3)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,4)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,5)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,6)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   if bit_test(txchar,7)
      set(*port,pin);
   else
      clear(*port,pin);
   bit_delay();
   //
   // stop bit
   //
   set(*port,pin);
   bit_delay();
   //
   // char delay
   //
   bit_delay();
   }

int main(void) {
   //
   // main
   //
   static unsigned char high,low;
   //
   // set clock divider to /1
   //
   CLKPR = (1 << CLKPCE);
   CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
   //
   // initialize output pins
   //
   set(serial_port,serial_pin_out);
   output(serial_direction,serial_pin_out);
   clear(trigger_port,trigger_pin);
   output(trigger_direction,trigger_pin);
   //
   // start counter
   //
   TCCR0B |= (1 << CS00); // prescale /1
   //
   // main loop
   //
   while (1) {
      //
      // trigger pulse
      //

   output(trigger_direction,trigger_pin); // Set output pin after echo loop (ADDED BY ME)

      set(trigger_port,trigger_pin);
      _delay_us(10);
      clear(trigger_port,trigger_pin);  
      //
      // wait for echo rising edge
      //
       

   clear(echo_port,echo_pin);  // clear echo pins (ADDED BY ME)
   input(echo_direction,echo_pin);  // set input echo pins (ADDED BY ME)

      high = 0;
      TCNT0 = 0;
      TIFR |= (1 << TOV0);
      while (1) {
         if ((echo_pins & echo_pin) != 0) // check for rising edge
            break;
         if ((TIFR & (1 << TOV0)) != 0) { // check for counter overflow
            high += 1;
            if (high == timeout)
               break;
            TIFR |= (1 << TOV0);
            }
         }
      //
      // rising edge found, wait for falling edge
      //
      high = 0;
      TCNT0 = 0;
      TIFR |= (1 << TOV0);
      while (1) {
         if ((echo_pins & echo_pin) == 0) { // check for falling edge
            low = TCNT0;
            break;
            }
         if ((TIFR & (1 << TOV0)) != 0) { // check for counter overflow
            high += 1;
            if (high == timeout)
               break;
            TIFR |= (1 << TOV0);
            }
         }
      //
      // send count with framing
      //
      put_char(&serial_port,serial_pin_out,1);
      put_char(&serial_port,serial_pin_out,2);
      put_char(&serial_port,serial_pin_out,3);
      put_char(&serial_port,serial_pin_out,4);
      put_char(&serial_port,serial_pin_out,low);
      put_char(&serial_port,serial_pin_out,high);
      //
      // delay before next cycle
      //
      _delay_ms(10);
      }
   }

Finally I could to send my code on my board with Linux Terminal through the make’s commands.

sudo make -f hello.ping_sensor.make program-usbtiny 
Loading make file.



After that, I used the same python program of Neil, for to read the signal. I launched it with terminal command.

python hello.HC-SR04.py /dev/ttyUSB0

In this video you can see that the In-put device worked well, measuring the right distance.

Ultrasonic from Mario Fullone on Vimeo.

Sketch Design Logo