Arduino i MySQL
upload data to DB(MySQL)
ShenzenAV - HC-SR501 PIR motion detector
x 1
In this project,author show to upload the read data to DB and then display it in a website.
He used PIR motion sensor(HC-SR501)
- Arduino monitors the state of the pin to which the motion sensor is connected, the sensor works digitally, so it sends the status 0 or 1.
- If motion is detected, pin 6 displays high or "1". This is a prerequisite for establishing connection with the server.
- If the status on pin 6 is low - we do not connect to the server. Thanks to this, we limit the bandwidth and the amount of data sent.
- Arduino, after establishing a connection with the server, runs the PHP script and passes a variable informing about the detection of motion.
- The script takes a variable and saves it to the database. In addition, the CURRENT_TIMESTAMP function was used in the MySQL database , which automatically adds the date and time of the measurement.
- wait a few seconds not to enter the same detection into the database.
Arduino code
System diagram:
LED is just check motion sensor work well.
and he created DB and table to store measurements.
this is PHP script to server.
write the address, username, and password according to the DB information
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php function Connection(){ $server="localhost"; $user="xxxxxxxxxxx"; $pass="xxxxxxxxxxx"; $db="xxxxxxxxxxxxx"; $connection = mysql_connect($server, $user, $pass); if (!$connection) { die('MySQL ERROR: ' . mysql_error()); } mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() ); return $connection; } ?> |
user can entering servername / index.php path and check motion detected time.
This UCC used DB and can show data in web.
So I thought this UCC was a special, interesting UCC.



