Thursday, November 21, 2019
Sunday, October 27, 2019
How to Instal a Load Cell in a Weighing Machine
Setup Code:
/*
This is the calibration sketch. Use it to determine the calibration_factor that the main example uses. It also
outputs the zero_factor useful for projects that have a permanent mass on the scale in between power cycles.
Setup your scale and start the sketch WITHOUT a weight on the scale
Once readings are displayed place the weight on the scale
Press +/- or a/z to adjust the calibration_factor until the output readings match the known weight
Use this calibration_factor on the example sketch
This example assumes pounds (lbs). If you prefer kilograms, change the Serial.print(" lbs"); line to kg. The
calibration factor will be significantly different but it will be linearly related to lbs (1 lbs = 0.453592 kg).
Your calibration factor may be very positive or very negative. It all depends on the setup of your scale system
and the direction the sensors deflect from zero state
Arduino pin 2 -> HX711 CLK
3 -> DOUT
5V -> VCC
GND -> GND
Most any pin on the Arduino Uno will be compatible with DOUT/CLK.
The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.
*/
#include "HX711.h"
#define DOUT 3
#define CLK 2
HX711 scale;
float calibration_factor = -7050; //-7050 worked for my 440lb max scale setup
void setup() {
Serial.begin(9600);
Serial.println("HX711 calibration sketch");
Serial.println("Remove all weight from scale");
Serial.println("After readings begin, place known weight on scale");
Serial.println("Press + or a to increase calibration factor");
Serial.println("Press - or z to decrease calibration factor");
scale.begin(DOUT, CLK);
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
Serial.println(zero_factor);
}
void loop() {
scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1);
Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
if(Serial.available())
{
char temp = Serial.read();
if(temp == '+' || temp == 'a')
calibration_factor += 10;
else if(temp == '-' || temp == 'z')
calibration_factor -= 10;
}
}
After Setup Code:
/*
The HX711 does one thing well: read load cells. The breakout board is compatible with any wheat-stone bridge
based load cell which should allow a user to measure everything from a few grams to tens of tons.
Arduino pin 2 -> HX711 CLK
3 -> DAT
5V -> VCC
GND -> GND
The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.
*/
#include "HX711.h"
#define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define DOUT 3
#define CLK 2
HX711 scale;
void setup() {
Serial.begin(9600);
Serial.println("HX711 scale demo");
scale.begin(DOUT, CLK);
scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
Serial.println("Readings:");
}
void loop() {
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.println();
}
Setup Code:
/*
This is the calibration sketch. Use it to determine the calibration_factor that the main example uses. It also
outputs the zero_factor useful for projects that have a permanent mass on the scale in between power cycles.
Setup your scale and start the sketch WITHOUT a weight on the scale
Once readings are displayed place the weight on the scale
Press +/- or a/z to adjust the calibration_factor until the output readings match the known weight
Use this calibration_factor on the example sketch
This example assumes pounds (lbs). If you prefer kilograms, change the Serial.print(" lbs"); line to kg. The
calibration factor will be significantly different but it will be linearly related to lbs (1 lbs = 0.453592 kg).
Your calibration factor may be very positive or very negative. It all depends on the setup of your scale system
and the direction the sensors deflect from zero state
Arduino pin 2 -> HX711 CLK
3 -> DOUT
5V -> VCC
GND -> GND
Most any pin on the Arduino Uno will be compatible with DOUT/CLK.
The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.
*/
#include "HX711.h"
#define DOUT 3
#define CLK 2
HX711 scale;
float calibration_factor = -7050; //-7050 worked for my 440lb max scale setup
void setup() {
Serial.begin(9600);
Serial.println("HX711 calibration sketch");
Serial.println("Remove all weight from scale");
Serial.println("After readings begin, place known weight on scale");
Serial.println("Press + or a to increase calibration factor");
Serial.println("Press - or z to decrease calibration factor");
scale.begin(DOUT, CLK);
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
Serial.println(zero_factor);
}
void loop() {
scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1);
Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
if(Serial.available())
{
char temp = Serial.read();
if(temp == '+' || temp == 'a')
calibration_factor += 10;
else if(temp == '-' || temp == 'z')
calibration_factor -= 10;
}
}
After Setup Code:
/*
The HX711 does one thing well: read load cells. The breakout board is compatible with any wheat-stone bridge
based load cell which should allow a user to measure everything from a few grams to tens of tons.
Arduino pin 2 -> HX711 CLK
3 -> DAT
5V -> VCC
GND -> GND
The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.
*/
#include "HX711.h"
#define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define DOUT 3
#define CLK 2
HX711 scale;
void setup() {
Serial.begin(9600);
Serial.println("HX711 scale demo");
scale.begin(DOUT, CLK);
scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
Serial.println("Readings:");
}
void loop() {
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.println();
}
Tuesday, June 18, 2019
Monday, March 18, 2019
Wednesday, February 27, 2019
DIGITAL CLOCK USING ARDUINO WITH RTC MODULE
Component List:
1 arduino uno
3 switches
1 Clock module RTC_DS1307 RTC
4 seven segment
2 red led
24 220 ohm resistor
1 vero board ....some jumper wire
Program That Is Required:
int digit1 = 11; //PWM Display pin 12 (digit1 is common anonds A1 from right side)
int digit2 = 10; //PWM Display pin 9 (digit2 is common A2)
int digit3 = 9; //PWM Display pin 8 (digit3 is common anods A3)
int digit4 = 6; //PWM Display pin 6 (digit4 is common anods, from left side)
//Pin mapping from Arduino to the ATmega DIP28 if you need it
//http://www.arduino.cc/en/Hacking/PinMapping
int segA = 2; //Display pin 11
int segB = 3; //Display pin 7
int segC = 4; //Display pin 4
int segD = 5; //Display pin 2
int segE = 12; //Display pin 1
int segF = 7; //Display pin 10
int segG = 8; //Display pin 5
int segDP = 13; // Display pin 3
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
// original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/
// add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/
// add part with manual adjust http://www.bristolwatch.com/arduino/arduino_ds1307.htm
byte SW0 = A0;
byte SW1 = A1;
byte SW2 = A2;
// use for hexa in zecimal conversion
int zh, uh, ore;
int zm, um, miniti;
void setup() {
// Serial.begin(57600);
Wire.begin();
RTC.begin();
// RTC.adjust(DateTime(__DATE__, __TIME__));
// if you need set clock... just remove // from line above this
// part code for flashing LED
Wire.beginTransmission(0x68);
Wire.write(0x07); // move pointer to SQW address
// Wire.write(0x00); // turns the SQW pin off
Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave at 1Hz
// Wire.write(0x13); // sends 0x13 (hex) 00010011 (binary) 32kHz
Wire.endTransmission();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
// dht.begin();
pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);
pinMode(segDP, OUTPUT);
pinMode(digit1, OUTPUT);
pinMode(digit2, OUTPUT);
pinMode(digit3, OUTPUT);
pinMode(digit4, OUTPUT);
// pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println("test for niq_ro");
pinMode(SW0, INPUT); // for this use a slide switch
pinMode(SW1, INPUT); // N.O. push button switch
pinMode(SW2, INPUT); // N.O. push button switch
digitalWrite(SW0, HIGH); // pull-ups on
digitalWrite(SW1, HIGH);
digitalWrite(SW2, HIGH);
}
void loop() {
digitalWrite(segDP, HIGH);
DateTime now = RTC.now();
int timp = now.hour()*100+now.minute();
// int timp = (now.minute(), DEC);
// displayNumber(12); // this is number to diplay
// int timp = 1234;
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(" -> ");
Serial.print(timp);
Serial.println(" !");
// display parts
for(int i = 250 ; i >0 ; i--) {
if (timp >= 1000) displayNumber01(timp);
else displayNumber02(timp);
}
for(int i = 250 ; i >0 ; i--) {
if (timp >= 1000) displayNumber03(timp);
else displayNumber04(timp);
}
if (!(digitalRead(SW0))) set_time(); // hold the switch to set time
}
void set_time() {
byte minutes1 = 0;
byte hours1 = 0;
byte minutes = 0;
byte hours = 0;
while (!digitalRead(SW0)) // set time switch must be released to exit
{
minutes1=minutes;
hours1=hours;
while (!digitalRead(SW1)) // set minutes
{
minutes++;
// converting hexa in zecimal:
zh = hours / 16;
uh = hours - 16 * zh ;
ore = 10 * zh + uh;
zm = minutes / 16;
um = minutes - 16 * zm ;
miniti = 10 * zm + um;
for(int i = 20 ; i >0 ; i--) {
displayNumber01(ore*100+miniti);
}
if ((minutes & 0x0f) > 9) minutes = minutes + 6;
if (minutes > 0x59) minutes = 0;
Serial.print("Minutes = ");
if (minutes >= 9) Serial.print("0");
Serial.println(minutes, HEX);
delay(150);
}
while (!digitalRead(SW2)) // set hours
{
hours++;
// converting hexa in zecimal:
zh = hours / 16;
uh = hours - 16 * zh ;
ore = 10 * zh + uh;
zm = minutes / 16;
um = minutes - 16 * zm ;
miniti = 10 * zm + um;
for(int i = 20 ; i >0 ; i--) {
displayNumber01(ore*100+miniti);
}
if ((hours & 0x0f) > 9) hours = hours + 6;
if (hours > 0x23) hours = 0;
Serial.print("Hours = ");
if (hours <= 9) Serial.print("0");
Serial.println(hours, HEX);
delay(150);
}
Wire.beginTransmission(0x68); // activate DS1307
Wire.write(0); // where to begin
Wire.write(0x00); //seconds
Wire.write(minutes); //minutes
Wire.write(0x80 | hours); //hours (24hr time)
Wire.write(0x06); // Day 01-07
Wire.write(0x01); // Date 0-31
Wire.write(0x05); // month 0-12
Wire.write(0x09); // Year 00-99
Wire.write(0x10); // Control 0x10 produces a 1 HZ square wave on pin 7.
Wire.endTransmission();
// converting hexa in zecimal:
zh = hours / 16;
uh = hours - 16 * zh ;
ore = 10 * zh + uh;
zm = minutes / 16;
um = minutes - 16 * zm ;
miniti = 10 * zm + um;
for(int i = 20 ; i >0 ; i--) {
displayNumber01(ore*100+miniti);
}
// delay(150);
}
}
void displayNumber01(int toDisplay) {
#define DISPLAY_BRIGHTNESS 500
#define DIGIT_ON HIGH
#define DIGIT_OFF LOW
for(int digit = 4 ; digit > 0 ; digit--) {
//Turn on a digit for a short amount of time
switch(digit) {
case 1:
digitalWrite(digit1, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
case 2:
digitalWrite(digit2, DIGIT_ON);
digitalWrite(segDP, LOW);
break;
case 3:
digitalWrite(digit3, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
case 4:
digitalWrite(digit4, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
}
lightNumber(toDisplay % 10);
toDisplay /= 10;
delayMicroseconds(DISPLAY_BRIGHTNESS);
//Turn off all segments
lightNumber(10);
//Turn off all digits
digitalWrite(digit1, DIGIT_OFF);
digitalWrite(digit2, DIGIT_OFF);
digitalWrite(digit3, DIGIT_OFF);
digitalWrite(digit4, DIGIT_OFF);
}
}
void displayNumber02(int toDisplay) {
#define DISPLAY_BRIGHTNESS 500
#define DIGIT_ON HIGH
#define DIGIT_OFF LOW
for(int digit = 4 ; digit > 0 ; digit--) {
//Turn on a digit for a short amount of time
switch(digit) {
case 1:
lightNumber(10);
digitalWrite(segDP, HIGH);
break;
case 2:
digitalWrite(digit2, DIGIT_ON);
digitalWrite(segDP, LOW);
break;
case 3:
digitalWrite(digit3, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
case 4:
digitalWrite(digit4, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
}
lightNumber(toDisplay % 10);
toDisplay /= 10;
delayMicroseconds(DISPLAY_BRIGHTNESS);
//Turn off all segments
lightNumber(10);
//Turn off all digits
digitalWrite(digit1, DIGIT_OFF);
digitalWrite(digit2, DIGIT_OFF);
digitalWrite(digit3, DIGIT_OFF);
digitalWrite(digit4, DIGIT_OFF);
}
}
void displayNumber03(int toDisplay) {
#define DISPLAY_BRIGHTNESS 500
#define DIGIT_ON HIGH
#define DIGIT_OFF LOW
for(int digit = 4 ; digit > 0 ; digit--) {
//Turn on a digit for a short amount of time
switch(digit) {
case 1:
digitalWrite(digit1, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
case 2:
digitalWrite(digit2, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
case 3:
digitalWrite(digit3, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
case 4:
digitalWrite(digit4, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
}
lightNumber(toDisplay % 10);
toDisplay /= 10;
delayMicroseconds(DISPLAY_BRIGHTNESS);
//Turn off all segments
lightNumber(10);
//Turn off all digits
digitalWrite(digit1, DIGIT_OFF);
digitalWrite(digit2, DIGIT_OFF);
digitalWrite(digit3, DIGIT_OFF);
digitalWrite(digit4, DIGIT_OFF);
}
}
void displayNumber04(int toDisplay) {
#define DISPLAY_BRIGHTNESS 500
#define DIGIT_ON HIGH
#define DIGIT_OFF LOW
for(int digit = 4 ; digit > 0 ; digit--) {
//Turn on a digit for a short amount of time
switch(digit) {
case 1:
lightNumber(10);
digitalWrite(segDP, HIGH);
break;
case 2:
digitalWrite(digit2, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
case 3:
digitalWrite(digit3, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
case 4:
digitalWrite(digit4, DIGIT_ON);
digitalWrite(segDP, HIGH);
break;
}
lightNumber(toDisplay % 10);
toDisplay /= 10;
delayMicroseconds(DISPLAY_BRIGHTNESS);
//Turn off all segments
lightNumber(10);
//Turn off all digits
digitalWrite(digit1, DIGIT_OFF);
digitalWrite(digit2, DIGIT_OFF);
digitalWrite(digit3, DIGIT_OFF);
digitalWrite(digit4, DIGIT_OFF);
}
}
//Given a number, turns on those segments
//If number == 10, then turn off number
void lightNumber(int numberToDisplay) {
#define SEGMENT_ON LOW
#define SEGMENT_OFF HIGH
switch (numberToDisplay){
case 0:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_OFF);
break;
case 1:
digitalWrite(segA, SEGMENT_OFF);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_OFF);
break;
case 2:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_OFF);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_ON);
break;
case 3:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_ON);
break;
case 4:
digitalWrite(segA, SEGMENT_OFF);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;
case 5:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_OFF);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;
case 6:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_OFF);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;
case 7:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_OFF);
break;
case 8:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_ON);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;
case 9:
digitalWrite(segA, SEGMENT_ON);
digitalWrite(segB, SEGMENT_ON);
digitalWrite(segC, SEGMENT_ON);
digitalWrite(segD, SEGMENT_ON);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_ON);
digitalWrite(segG, SEGMENT_ON);
break;
// all segment are ON
case 10:
digitalWrite(segA, SEGMENT_OFF);
digitalWrite(segB, SEGMENT_OFF);
digitalWrite(segC, SEGMENT_OFF);
digitalWrite(segD, SEGMENT_OFF);
digitalWrite(segE, SEGMENT_OFF);
digitalWrite(segF, SEGMENT_OFF);
digitalWrite(segG, SEGMENT_OFF);
break;
}
}
Sunday, January 6, 2019
Subscribe to:
Posts
(
Atom
)