About the assignment: input devices

Measure something: add a sensor to a microcontroller board that you've designed and read it.

For this assignment I worked with a light sensor and a motion sensor.

light sensor: redesign the board

For this assignment I re-designed the board I created for the electronic design assignment. For my final project, I would like to have my chair movement based on light and motion. I decided to start from the hello.light board and add the light sensor sensor to my button board.

After the first attempt to reorganize the components I decided to change pin 11 to button and connect pin 10 to the photo sensor.

Now the path is not crossing anymore.

Finally, (after some photoshop adjustments) the pgp file is ready to mill.

light sensor: milling and soldering the board

light sensor: read the board with arduino

I used a common Analog Read Serial code for arduino IDE setting the analog input on pin 3 on trhe Attiny 44.

light sensor: read the board with pyserial

To measure the light sensor with PySerial I need to install Python, Pyserial and Tkinter on my PC with Windows 7.

I followed Anna's tutorial but there are some differences:

You need Python (use 2.7.3 - it works with the dependencies listed)
Add Python to your Path
  • Go to the "Start" menu
  • Open "Control Panel"
  • Click "System and Security"
  • Click "System"

On the left you will find the Control Panel Home

  • Click "Advanced System Settings"
  • Select "Environmental Variables"
    • Under "System Variables" / "Variables" select "Path" so it is highlighted in blue
    • Select the "Edit" button.
      • This text (or something like it) will already be in the box.: C:\Tcl\bin;%PATH%
      • Just add to whatever you have already.....
      • Add a semicolon directly after the text (NO SPACES).
      • Then add the following: C:\Python27

The final result should look like this (on 64 bit Windows anyway):

C:\Tcl\bin;%PATH%;C:\Python27
Restart your computer

If you did everything correctly, after you restart, you can open the Windows command line and type "python". You should get a python version number.

If you get an error, you can run python by navigating to the folder as described here: http://web.media.mit.edu/~liningy/sub_work/lining.yao/design%20about/Tutorial_2.html

You need PySerial
You need Tkinter

Motion sensor: Connect PIR to arduino board

I will need to work with a motion sensor for my final project.
To test it, I used a PIR (Pyroelectric "Passive" Infra Red) connected to an Arduino board.

I am using the Arduino uno because I am still soldering my own Hello Arduino.

I connected the PIR sensor as follow:

  • OUT to digital pin 2
  • VCC to 5V
  • GND to pin GND

Motion sensor: program and read arduino board

I programed the board with a simple code :

/* Davide Prete PIR sensor tester*/

int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status

void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input

Serial.begin(9600);
}

void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
}
else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}

 

I red the sensor with Arduino Serial Monitor to check it.

© 2014, Davide Prete, Washington DC