Smart Scale

by yibai.wang.elaine in Workshop > Tools

562 Views, 3 Favorites, 0 Comments

Smart Scale

Arduino-UNO-R3-CH340G-02.jpg
download.jpg
45040-dscn0624-400x300.jpg
Electronic-Axial-Lead-Resistors-Array.jpg
50803_-_img_6116-2.jpg
41iQeLY0DTL._AC_SS350_.jpg

This model is designed to reflect the change of measurable thing both simultaneously and remotely. The idea is to break the traditional measure conducting only real-time monitoring by transporting digital information to person him/herself.

Supplies

Hardware

  • Arduino Controller board (Uno/Mega)
  • Breadboard Breadboard Jumper Wire with sorted colors
  • Resistor
  • Round force sensitive resistor/Square force sensitive resistor

Software

  • Arduino IDE
  • Processing IDE

Preparation

images.png
images.jpg

Install two apps on the laptop

A). Arduino IDE

  • Arduino IDE is written in the programming language Java. It originated from the IDE for the languages Processing and Wiring. Compared with other computer languages, it has a more flexible language environment, allowing cutting and pasting, searching and replacing text, automatic indenting, brace matching, and syntax highlighting. It also provides simple one-click mechanisms to compile and upload the program into the Arduino board.

B). Processing IDE

  • Processing is written in the programming language Java. It is a language for learning how to code and link together the visual art and visual literacy. It is also a flexible language environment for all general public. The Processing IDE can communicate with the Arduino IDE through serial communication.
  • Processing software download: https://processing.org/download/

Know the Arduino and Force Sensitive Resistor(FSR)

  • The output voltage of the sensor will be between 0 V (no pressure applied) and roughly 5 V (maximum pressure applied).
  • Arduino board contains a multichannel, 10-bit analog to digital converter, which means it'll map the input voltage between 0 and 5 V into integer values between 0 and 1023, which will display in the code.

Electronic Connection

force___flex_fsrpulldowndia.png
WeChat Image_20201101142321.jpg

Connect the force sensitive resistor

Carefully note thay, a FSR is non-polarized. So it is just a normal resistor with pins that have no positive or negative side, but make sure to connect them with the detectable face upward.

The exact connection can be referred to the graphs above.

  • Use different jumper wires to differentiate their use
  • One pin of the FSR is connected to the 5v
  • Another pin is connected to both GND (ground) and the input pin

Firmware for Auduino

int potPin = A2; //Potentiometerconnected to A0
int potValue = 20; //initial of the pot value is 20
int forceValue;
int oldForceValue; 


void setup() {
  Serial.begin(9600); //Set the serial communication at 9600 bps
}

void loop() {
  readPotValue();
}


void readPotValue(){ 
  potValue = analogRead(potPin);
  forceValue = map(potValue, 0, 1023, 5, 255); //convert the potentiometer value to 5-255
  if (forceValue != oldForceValue){
    oldForceValue = forceValue;
    Serial.write(forceValue);
    }
//  Serial.print("forceValue =  ");//debugging
//  Serial.println(forceValue);
}


Graphic User Interface

import processing.serial.*;

Serial comPort;
//int buttonStatus;
int forceValue = 250;
int serialPortValue;
int serialThreshold = 5;

void setup(){
  size(500,1000);
  background(#8CBCE6);
  frameRate(500);
  initialize();
  String portName = Serial.list()[0];
  comPort = new Serial(this, portName, 9600);
}

void draw(){
  getComPortData();
  drawColorBar();
}

void initialize(){
  fill(0);
  rect(width/4, height/4, width/2, height/2);
  //buttonStatus = 0;
}

void getComPortData(){
  if (comPort.available() > 0){  //If data is available
    serialPortValue = comPort.read();
    if (serialPortValue >=serialThreshold){
      forceValue = int(map(serialPortValue, serialThreshold, 255, 0, height/2));
    }  
  }
//  print("portValue = ", serialPortValue);
//  print("forceValue = ", forceValue);
}
  
void drawColorBar() {
  fill(0);
  rect(width/4, height/4, width/2, height/2-forceValue);
  if (forceValue >= height/8) {
    fill(0, 255,0);
  } else if (forceValue <= height/16) {
    fill(255,0,0);
  } else {
    fill(255,255,0);
  }
  rect(width/4, height*3/4-forceValue, width/2, forceValue); 
  stroke(255);
  strokeWeight(3);
  line(width/4,height*3/8, width*3/4, height*3/8);
  line(width/4,height/2, width*3/4, height/2);
  line(width/4,height*5/8, width*3/4, height*5/8);
}

Finalization and Important Notice

After setting up all the hardware and pasting all the codes, we are almost DONE!

Before starting the force detection, we have to adjust the parameter on the Arduino software

  • Tool>development board>[choose] Arduino Uno/Arduino Mega or Mega 2560
  • Tool>Port>[choose] Com [No.]

Also, make sure to run the Processing code after the Arduino code and not to open the serial monitor, or else it will report port busy :(.

Result

Instructable-Smart Scale-Result Video
屏幕截图 2020-11-22 212730.png
屏幕截图 2020-11-22 212915.png

The changing of forces can be detected and displayed on the graphic bar by linking together the Arduino and Processing IDE and hardware.

Besides, slightly changing the Arduino code allows us to determine the changes in force with exact data in the serial monitor.