Hello all people in forums,
I am doing this project:
I have 3 lines with each line with switch sensor, the sensor has duty to detect how many "stuff" has passed through.
This project uses 1 Arduino UNO and 3 switch sensor (IR sensors).
void loop()
{
if (digitalRead(switchPin0))// START BUTTON LINE 1
{
detect(0);
}
if (digitalRead(switchPin1))// START BUTTON LINE 2
{
detect(1);
}
if (digitalRead(switchPin2))// START BUTTON LINE 3
{
detect(2);
}
}
void detect(int line)
{
if (line == 0)
{
int state0 = digitalRead(IRdetectPin0);
if (laststate0 == HIGH && state0 == LOW) // only count on a HIGH-> LOW transition
{
increment (0);
Serial.println(no1);
}
laststate0 = state0;// remember last state
}
if (line == 1)
{
int state1 = digitalRead(IRdetectPin1);
if (laststate1 == HIGH && state1 == LOW) // only count on a HIGH-> LOW transition
{
increment (1);
Serial.println(no2);
}
laststate1 = state1; // remember last state
}
if (line == 2)
{
int state2 = digitalRead(IRdetectPin2);
if (laststate2 == HIGH && state2 == LOW) // only count on a HIGH-> LOW transition
{
increment (2);
Serial.println(no2);
}
laststate2 = state2; // remember last state
}
}
void increment(int line)
{
if(line==0)
{
g_numberToDisplay = no1;
no1++;
}
else if(line==1)
{
g_numberToDisplay = no2;
no2++;
}
else if(line==2)
{
g_numberToDisplay = no3;
no3++;
}
}
And I would like to put the data: no1, no2, no3 to the database in host computer (computer that connect to the Arduino using USB cable).
I want the database update the data each time they count up, then which database can I use:
a. Microsoft Office Access?, or
b. SQL database?
c. Visual Basic?
I prefer to use Visual Basic, if I can use it, then how to connect it to my Arduino UNO?
Is there any example how to make the database?
Here is the image showing the data from the database for common user:
I want the database update the data each time they count up, then which database can I use:
a. Microsoft Office Access?, or
b. SQL database?
c. Visual Basic?
Visual Basic is not a relational database. It is a programming language. Neither Access nor SQL Server have mechanisms to read from a serial port, so you will need to create an application that can read from the serial port and store the data in the database.
I prefer to use Visual Basic, if I can use it, then how to connect it to my Arduino UNO?
See above.
Is there any example how to make the database?
There are plenty of books - online and dead tree versions - that delve into creating databases. There is nothing Arduino-specific about your database.
Your Arduino program needs to "Serial.print" to PC.
You write a VB (or even VBscript) app on PC that reads from serial port and outputs to a CSV file.
Take a look at this for some inspiration:
Why output to a CSV? The OP wants to write to a database.
If the project is not for commercial use, I'd get a copy of SQL Server Express Edition (get the one with management tools), and use VB to write to it. If it is for commercial use, get them to stump up for a Standard Edition license, or get mySQL instead. It works just as well, but is (arguably) harder to manage.
To me, the image appears to be showing an extract of the data, in table form. That is a perfectly reasonable way to visualise it. I am a Database Administrator though, and hardly ever use spreadsheets.
MS Access can be used for serial communication. It isn't the easiest task but it can be done. Serial communication can be done with the mscomm32.ocx control. In addition I recall some code floating around out there for doing serial communication directly from VBA using the Windows API. The primary issue using a ocx control is the control must be registered on any computer you want to use. MS Access is an incredibly versatile tool, but it does have its limitations.
You can also use visual basic to perform serial communication. However you will need to record the data to either a database such as MS Access or SQL Sever. The easiest thing for you to do would be to handle the serial comunnication in visual basic and store the data in an .mdb file.