#Logging Arduino sensor data into MySQL table using Python.
Follow the steps below to complete your project.
- Connect your sensor to Arduino as shown in circuit. (Here I'm using TMP36, a temperature sensor and reading only voltage from it)
- Next, from the downloaded code, copy code from
ArduinoMySQL.ino
file and then paste it in your Arduino IDE. - To check if the code is working or not, open serial monitor and get confirmed.
- Now, create a database in your localhost and then a table in it using phpMyAdmin.
- If you're not using phpMyAdmin using the following script to create tables.
CREATE TABLE IF NOT EXISTS `tempdata` (
`ID` int(11) NOT NULL,
`Date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`voltage` varchar(4) NOT NULL
)
- Then, get
ArduinoMySQL.py
from the downloaded code and paste it any one of your prefered code editor. - Change the Database credentials in the line 5. The credetials include your Database username, password and Database name.
- Finally, save the code and run the Python script. Then, go and check you table, you'll find that data.
Possible Errors
You might see an error such as the error shown in the image below.
Then, you need to upgrage you python MySQLdb library. Use pip install --upgrade MySQL-python==1.2.4
command to upgrade the library.