Skip to content

12. Input devices

Weekly Summary

  • Connect with Ammonia sensor
  • Connect Processing and Arduino IDE

Assignments

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

Kamakura Group Assignment Week12

Individual assignment

I start to research about this sensor from here

I connect with Arduino first and my PCB board from week 10.

And used the code as follow:

analogRead(A0)// for Arduino

pinMode(A0, INPUT);
#define RL 47  //The value of resistor RL is 47K
void setup() 
{
  Serial.begin(9600);
}

void loop() {
  float analog_value;
  float VRL;
  float Rs;
  float Ro;
  for(int test_cycle = 1 ; test_cycle <= 500 ; test_cycle++) //Read the analog output of the sensor for 200 times
  {
    analog_value = analog_value + analogRead(7); //add the values for 200
  }
  analog_value = analog_value/500.0; //Take average
  VRL = analog_value*(5.0/1023.0); //Convert analog value to voltage
  //RS = ((Vc/VRL)-1)*RL is the formulae we obtained from datasheet
  Rs = ((5.0/VRL)-1) * RL;
  //RS/RO is 3.6 as we obtained from graph of datasheet
  Ro = Rs/3.6;
  pinMode(7, INPUT);
  Serial.println(Ro);
  delay(100);
}

It answered the serial monitor with Arduino, But with my board....

I tried to connect the LED tape at the same pins, and worked.

Tried different code…but didn’t work…

And Instructor suggested me “Where is the FTDI pins”…!!

I avoided FTDI pins for this board because I thought I don’t need it.

So I tried my first design board from week 8

And It worked to connect with serial monitor.

But It doesn’t have VCC pin for UPDI. So I’m not able to connect with ammonia sensor.

I added the jumper wirers of TX and RX to second board.

And I can connect with ammonia sensor too.

Next I tried to create the graphics mater on Processing.

So I downloaded Processing for my windows PC.

I followed how to download Processing from here

Open the download folder.

And right click on the processing zip file > select Extract All… >Press Extract

And open processing.exe

And They might ask you to download Java, then download.

Press “Agree and Start Free Download”

Press “Install” and done

Now you can open processing.

Create heart shape on Processing

int HeartSize=5;
void setup()
{
  size(700,700,P2D);
  frameRate(60);
  background(150,10,0);
}

void draw()
  {
    translate(350,350);//position od  heart
    stroke(100, 250, 200);
    strokeWeight(15); 
    for (float t=0; t<=2*PI; t+=.01)
      point((-16*HeartSize*pow(sin(t), 3)), (-(13*HeartSize*cos(t)-10*HeartSize*cos(2*t)
      -2*HeartSize*cos(3*t)-cos(4*t))));
  }

or

{
  size(700,700);
  background(150,10,0);
}

void draw()
  {
 translate(350,350);//position od  heart

  smooth();
  noStroke();
  fill(255,0,0);
  beginShape();
  vertex(50, 15); 
  bezierVertex(50, -5, 90, 5, 50, 40); 
  vertex(50, 15); 
  bezierVertex(50, -5, 10, 5, 50, 40); 
  endShape();
}

Random circle moving

int size;

void setup(){
 size(700,700);
}

void draw() {
  background(150,10,0); 

  size = round(random(200)); //'round' turns float into integer

  stroke(0,200,200);
  strokeWeight(8);

  circle(width/2, height/2, size); 
}

Connect with Arduino and Processing

import processing.serial.*;

Serial mySerial;
String myString = null;
int nl = 10;
float myVal;

void setup(){
  size(200,400);

  String myPort = Serial.list()[0];
  mySerial = new Serial(this, myPort, 9600);
}

void draw()
  {

 while (mySerial.available()>0){
   myString = mySerial.readStringUntil(nl);

   if (myString != null){
   background(150,10,0); 
   myVal = float(myString);

   myVal = myVal/500*height;

  rectMode(CENTER);
  rect(width/2, height*(myVal/2), 500, myVal);
}
 }
  }

I got 9.5~10.5w/v% ammonia from drugstore.

Now I’m ready to see the ammonia number…

But It didn’t show the right number.

It didn’t change the number…

I think what I need to add around 47K resistor.

I need to make a new board for communication, so I will add the resistor for ammonia sensor pin this week.

4.30.2022

I create third nose board. Detail from week 13 assignment.

Now I can try networking easier. There are UART, I2C and SPI pads.

And tried to connect with Photoresistor as follows;

I use this sensor at group assignment.

This is the code

int val=0; 
void setup() {
Serial.begin(9600); 
}
void loop() {
val=analogRead(0); //analog pin 0
Serial.println(val/4); 
delay(100);
}

I need more time for ammonia sensor.

Because I found out my mistake was I didn’t try second code.

I only tried to find out the number of “Ro”.

But the guy made a mistake pretty much in the formula. So I need to find a correct number.

It is for my final project, so I’ll figure out in the final project week.

  • Programing on Arduino IDE [.ino]
  • Programing on Processing [.pde]

What I learned

I need to communication pin to see the serial monitor. In this time FTDI.

It is really basic knowledge, but pretty important I think><

Appendix


Last update: June 25, 2022